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, 23.06.2019 15:20
What does a bonus object do? a. subtracts lives b. keeps track of a player's health c. gives a player an advantage d. makes text appear
Answers: 1
question
Computers and Technology, 24.06.2019 01:30
Could you find out how im still getting an 83 percent on this in edhesive a = input("enter an animal: ") s = input ("enter a sound: ") e = "e-i-e-i-o" print ("old macdonald had a farm, " + e) print ("and on his farm he had a " + a + "," + e) print ("with a " + s + "-" + s + " here and a " + s + "-" + s + " there") print ("here a " + s+ " there a " + s) print ("everywhere a " + s + "-" + s ) print ("old macdonald had a farm, " + e)
Answers: 2
question
Computers and Technology, 24.06.2019 12:30
Do you think media is stereotype ? and why?
Answers: 1
question
Computers and Technology, 24.06.2019 12:30
Select all that apply. what two keys listed below should you use to enter data in an excel worksheet? tab backspace enter right arrow
Answers: 2
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
Business, 06.05.2020 03:08
question
English, 06.05.2020 03:08
question
Mathematics, 06.05.2020 03:08
question
History, 06.05.2020 03:08
question
History, 06.05.2020 03:08