Computers and Technology

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;
}

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 18:30, lizz1228
Kto rozmawia z clamentain przez krótkofalówke w the walking dead w 4 epizodzie
Answers: 1
image
Computers and Technology, 22.06.2019 21:30, aesthetickait
How do you take a green screen out of the video while editing?
Answers: 2
image
Computers and Technology, 23.06.2019 18:00, fordkenae
Which is a possible benefit of having a good credit history? having a checking account low interest rate on a car loan high interest rate on a credit card offer bankruptcy
Answers: 1
image
Computers and Technology, 24.06.2019 01:00, Timeisjesus
Answer these and get 40 points and brainliest
Answers: 1
Do you know the correct answer?
Open the attached .cpp file. Fill in the two missing functions where it says insert code here. Every...

Questions in other subjects:

Konu
Mathematics, 19.02.2020 03:23
Konu
Mathematics, 19.02.2020 03:23