Created
March 13, 2014 20:45
-
-
Save anonymous/9536644 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Program: Classify Numbers | |
//This program counts the number of zeros, odd, and even numbers *?*/ | |
#include <iostream> | |
#include <iomanip> | |
#include <fstream> | |
using namespace std; | |
//Function prototypes | |
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, int evenCount); | |
bool getNumber(ifstream& numberFile, int& zeros, int& odds, int& evens); | |
void writeNumber(ofstream& resultsFile, int zeros, int odds, int evens, | |
int sum, int avg); | |
int calcSum( int zeros, int evens, int odds); | |
int main () | |
{ | |
ifstream inFile; | |
ofstream outFile; | |
int N; | |
int sum; | |
int avg; | |
//Variable declaration | |
int counter; //loop control variable | |
int number; //variable to store the new number | |
int zeros; //variable to store the number of zeros | |
int odds; //variable to store the number of odd integers s | |
int evens; //variable to store the number of even integers | |
//int sum; // sum of the numbers | |
//int avg; //average of the number | |
initialize(zeros, odds, evens); //Step 1 | |
//cout << "Please enter " << N << " integers." | |
// << endl; //Step 2 | |
//cout << "The numbers you entered are: " | |
// << endl; | |
//numberfile.open ("f:number.dat"); | |
// if(inFile) | |
//cout<< "Open \ 'f:numberfile.dat\' " << endl; | |
//else | |
//cout << "File not opened \ 'f:number.txt\' << endl; | |
inFile.open ("problem01Data.txt"); | |
if(inFile) | |
{ //failure of opening number file | |
cout << "Error in opening number file .\n" << endl; | |
system ("pause"); | |
return 0; | |
} | |
outFile.open("f:results.dat"); | |
if(!outFile) | |
{ //failure of opeinging results file | |
cout << "Error in opening results file .\n" << endl; | |
system("pause"); | |
return 0; | |
} | |
while ( getNumber (inFile, zeros, odds, evens)) | |
{ | |
for (counter = 1; counter <= N; counter++) //Step 3 | |
{ | |
getNumber(number); //Step 3a | |
cout << number << " "; //Step 3b | |
classifyNumber(number, zeros, odds, evens); //Step 3c | |
}// end for loop | |
// calcSum (zeroCount, evenCount, oddCount); | |
writeNumber(outFile, zeros, odds, evens, sum, avg); | |
} | |
cout << endl; | |
printResults(zeros, odds, evens); //Step 4 | |
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++; | |
} //end switch | |
} | |
int calcSum( int zeroCount, int oddCount, int evenCount) | |
{ | |
return zeroCount + oddCount + evenCount; | |
} | |
void printResults(int zeroCount, int oddCount, int evenCount) | |
{ | |
cout << "There are " << evenCount << " evens, " | |
<< "which includes " << zeroCount << " zeros" | |
<< endl; | |
cout << "The number of odd numbers is: " << oddCount | |
<< endl; | |
// calcuSum | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In line
67
changeopeinging
byopening
, lol