subject

Open the attached .cpp file. Fill in the two missing functions where it says insert code here. Everything else has been written for you to test your functions. You may not change anything in the file other than write the functions. Note: For testing purpose, I will have different data in file numbers. txt. Expected Output: Data in file: 10
9
1
10
25
5
4
6
7
3
92
1
3
8
Sum of all even numbers in list = 130
List after deleting even numbers: 9
1
25 5 7 3 1 3
HERE IS THE CPP:
/*This program is your final exam.
All you need to do is to fill both the functions.
1) Find the sum of the even numbers in the list.
Please insert code in the function called int sumEven(int[], int)
2) Delete/Remove all even numbers in the list.
Please insert code in the function called void delEven(int [], int &)
Note: Even if I change the content of the input file, your program should still produce the correct output.
*/
#include
#include
#include
using namespace std;
//constants
const int CAP = 100;
//function prototypes
bool openFile(ifstream &);
void readData(ifstream &, int[], int &);
void printData(const int[], int);
int sumEven(int[], int);
void delEven(int[], int &);
//main
int main()
{
ifstream inFile;
int list[CAP], size = 0;
int total = 0;
if (!openFile(inFile))
{
cout << "Program terminating!! File not found!" << endl;
return -1;
}
//read the data from the file
readData(inFile, list, size);
inFile. close();
cout << "Data in file:" << endl;
printData(list, size);
//find sum of even numbers
total = sumEven(list, size);
cout << "Sum of all even numbers in list = " << total << endl;
cout << endl;
//delete even numbers
delEven(list, size);
cout << "List after deleting even numbers:" << endl;
printData(list, size);
//end program
cin. ignore(100, '\n');
cout << "Press any key to continue...";
getchar();
return 0;
}
//function to open file
bool openFile(ifstream &inFile)
{
inFile. open("numbers. txt");
if (!inFile)
{
return false;
}
return true;
}
//reads the data from the file
void readData(ifstream &inFile, int list[], int &size)
{
while (!inFile. eof())
{
inFile >> list[size++];
}
}
//function to find the sum of even numbers in the list
int sumEven(int list[], int size)
{
//insert code here to find the sum of even numbers in the list
}
//function to delete all even numbers in the list.
void delEven(int list[], int &size) {
//insert code here to delete all even numbers in the list.
}
//print the contents of the array
void printData(const int list[], int size)
{
for (int i = 0; i < size; i++)
{
cout << list[i] << endl;
}
cout << endl;
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 17:40
Gabe wants to move text from one document to another document. he should copy the text, paste the text, and open the new document highlight the text, select the cut command, move to the new document, make sure the cursor is in the correct location, and select the paste command select the save as command, navigate to the new document, and click save highlight the text, open the new document, and press ctrl and v
Answers: 1
question
Computers and Technology, 23.06.2019 07:30
What part of the interface displays the external references contained in a selected cell? the status bar the review tab the scroll bar the formula bar
Answers: 1
question
Computers and Technology, 24.06.2019 10:30
This device directs network traffic. bridge hub nic repeater router switch
Answers: 3
question
Computers and Technology, 24.06.2019 12:30
Why does the pc send out a broadcast arp prior to sending the first ping request
Answers: 1
You know the right answer?
Open the attached .cpp file. Fill in the two missing functions where it says insert code here. Every...
Questions
question
Mathematics, 30.10.2020 21:50
question
Mathematics, 30.10.2020 21:50
question
Mathematics, 30.10.2020 21:50
question
Mathematics, 30.10.2020 21:50
question
Mathematics, 30.10.2020 21:50
Questions on the website: 13722363