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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 01:50, divine134
A.) generate scaffolding to create database for your application. develop all the entities identified in assignment #2. add any additional that may be identified later. b.) add data validation rules to the models that are appropriate for your application and data. c.) create links for each scaffold in the header section. part 2: application updates [30 points] a.) add two additional views to the "home" controller you created in assignment #1. b.) the two views should be named as “privacy" and "". c.) link the two newly created views in the footer section. hint: you would need to modify the “home" controller definition and create “privacy. html. erb" and “.html. erb" files in appropriate locations.
Answers: 3
image
Computers and Technology, 23.06.2019 16:30, rileysndr1782
Monica and her team have implemented is successfully in an organization. what factor leads to successful is implementation? good between different departments in an organization leads to successful is implementation.
Answers: 1
image
Computers and Technology, 23.06.2019 19:00, brittneyrenae7338
This question involves a class named textfile that represents a text file. public class textfile { private string filename; private string filename; private arraylist words; // constructors not shown // postcondition: returns the number of bytes in this file public int filesize() { } // precondition: 0 < = index < words. size() // postcondition: removes numwords words from the words arraylist beginning at // index. public void deletewords(int index, int numwords) { } // precondition: 0 < = index < = words. size() // postcondition: adds elements from newwords array to words arraylist beginning // at index. pub lic voidaddwords(int index, string[] newwords) { } // other methods not shown } complete the filesize() method. the filesize() is computed in bytes. in a text file, each character in each word counts as one byte. in addition, there is a space in between each word in the words arraylist, and each of those spaces also counts as one byte. for example, suppose the words arraylist stores the following words: { mary had a little lamb; its fleece was white as snow. } the filesize() method would compute 4 + 3 + 1 + 6 + 5 + 4 + 6 + 3 + 5 + 2 + 5 as the sum of the lengths of each string in the arraylist. the value returned would be this sum plus 10, because there would also be 10 spaces in between the 11 words. complete the filesize() method below: // postcondition: returns the number of bytes in this file public int filesize() { }
Answers: 1
image
Computers and Technology, 24.06.2019 00:00, Amrinderkhattra
Visualizing a game of “tag” to remember the meaning of contagious
Answers: 3
You know the right answer?
Open the attached .cpp file. Fill in the two missing functions where it says insert code here. Every...

Questions in other subjects:

Konu
Social Studies, 30.09.2019 18:30