What i\'m trying to do is change the program to read the numberfrom an infile an
ID: 3618105 • Letter: W
Question
What i'm trying to do is change the program to read the numberfrom an infile and print it out in a outfile and.(mainly bymodifying getNumber function.)Have the program find the sum and average.
#include <iostream> #include <iomanip>
using namespace std;
const int N=20;
void initialize(int& zeroCount, int& oddCount,int& evenCount); void getNumber(int& num); void classifyNumber(int num, int& zeroCount, int&oddCount, int& evenCount); void printResults(int zeroCount, int oddCount, intevenCount);
int main() { int counter; int number; int zeros; int odds; int evens; initialize(zeros, odds,evens); cout<<"Please enter"<<N<<" integers."<<endl; cout<<" The numbers you enteredare: "<<endl; for (counter=1; counter<=N;counter++) { getNumber(number); cout<<number<<" "; classifyNumber(number,zeros,odds,evens); } cout<<endl; printResults(zeros, odds,evens); system("pause"); return 0; } void initialize(int& zeroCount,int& oddCount, int& evenCount) { zeroCount=0; oddCount=0; evenCount=0; } void getNumber(int& num) { cin >>num; } void classifyNumber(int num, int&zeroCount, int& oddCount, int& evenCount) { switch(num%2) { case 0: evenCount++; if (num == 0) zeroCount++; break; case 1: case -1: oddCount++; } } void printResults(int zeroCount, intoddCount, int evenCount) { cout<<"There are"<<evenCount<<" evens,"<<"which includes"<<zeroCount<<" zeros"<<endl; cout<<"The numberof odd numbers is: "<<oddCount<<endl; }
What i'm trying to do is change the program to read the numberfrom an infile and print it out in a outfile and.(mainly bymodifying getNumber function.)
Have the program find the sum and average.
#include <iostream> #include <iomanip>
using namespace std;
const int N=20;
void initialize(int& zeroCount, int& oddCount,int& evenCount); void getNumber(int& num); void classifyNumber(int num, int& zeroCount, int&oddCount, int& evenCount); void printResults(int zeroCount, int oddCount, intevenCount);
int main() { int counter; int number; int zeros; int odds; int evens; initialize(zeros, odds,evens); cout<<"Please enter"<<N<<" integers."<<endl; cout<<" The numbers you enteredare: "<<endl; for (counter=1; counter<=N;counter++) { getNumber(number); cout<<number<<" "; classifyNumber(number,zeros,odds,evens); } cout<<endl; printResults(zeros, odds,evens); system("pause"); return 0; } void initialize(int& zeroCount,int& oddCount, int& evenCount) { zeroCount=0; oddCount=0; evenCount=0; } void getNumber(int& num) { cin >>num; } void classifyNumber(int num, int&zeroCount, int& oddCount, int& evenCount) { switch(num%2) { case 0: evenCount++; if (num == 0) zeroCount++; break; case 1: case -1: oddCount++; } } void printResults(int zeroCount, intoddCount, int evenCount) { cout<<"There are"<<evenCount<<" evens,"<<"which includes"<<zeroCount<<" zeros"<<endl; cout<<"The numberof odd numbers is: "<<oddCount<<endl; }
Explanation / Answer
please rate - thanks #include #include #include using namespace std; const int N=20; void initialize(int& zeroCount, int& oddCount, int&evenCount); void getNumber(int& num,ifstream&); void classifyNumber(int num, int& zeroCount, int& oddCount,int& evenCount); void printResults(int zeroCount, int oddCount, intevenCount,ofstream&); int main() { int counter; int number; int zeros; int odds; int evens; ifstream inFile; ofstream out; inFile.open("classifyNumbers.txt"); out.open("Printclassified.txt"); outRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.