Created
July 19, 2009 05:24
-
-
Save allisons/149812 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
// This is the Sliter Survey Calculation Program (slitersurvey.cpp) | |
// Written by: Allison Sliter | |
// Date: 18 July 2009 | |
// Sources: Malik, D.S. C++ Programming: from Problem Analysis to Project Design, Colin Goble's filerewind.cpp, Ian Dees, | |
#include <iostream> | |
#include <iomanip> | |
#include <fstream> | |
#include <string> | |
using namespace std; | |
int main () | |
{ | |
string results; | |
string reply; | |
string seen; | |
string name; | |
string line; | |
int age; | |
double score; | |
double average, under18yavg, under18navg, over18yavg, over18navg; | |
double counter, under18y, under18n, over18y, over18n; | |
double youngycount, oldycount, youngncount, oldncount; | |
string inputFileName; | |
ifstream inputFile; | |
cout << "Input file name: "; | |
getline(cin, inputFileName); | |
inputFile.open(inputFileName.c_str()); | |
if ( ! inputFile.is_open()) | |
{ | |
cout << "Oops! Can't open that file! Make sure you give me the full file pathway. " << endl; | |
cout << "Press enter to continue..."; | |
getline(cin, reply); | |
exit(1); | |
} | |
counter = 0; | |
score= 0; | |
under18y= 0; | |
under18n = 0; | |
over18n = 0; | |
over18y = 0; | |
youngycount = 0; | |
oldycount = 0; | |
youngncount = 0; | |
oldncount = 0; | |
while (inputFile) { | |
inputFile >> name >> seen >> age >> score; | |
if (!inputFile) | |
break; | |
cout << left << setw(17) << name; | |
cout << setw(2) << seen; | |
cout << setw(3) << age; | |
cout << setw(3) << score << endl; | |
if (seen == "Y" && age < 18) | |
{under18y = under18y + score; | |
youngycount++; | |
} | |
else if (seen == "N" && age < 18) | |
{ | |
under18n += score; | |
youngncount++; | |
} | |
else if (seen == "Y" && age >= 18) | |
{ | |
over18y = over18y + score; | |
oldycount++; | |
} | |
else if (seen == "N" && age >= 18) | |
{ | |
over18n = over18n + score; | |
oldncount++; | |
} | |
} | |
under18navg = under18n / youngncount; | |
under18yavg = under18y / youngycount; | |
over18navg = over18n / oldncount; | |
over18yavg = over18y / oldycount; | |
average = (under18n + under18y + over18y + over18n) / (youngycount + youngncount + oldycount + oldncount); | |
cout << fixed << showpoint << setprecision(2); | |
cout << endl << endl; | |
cout << "The following is the results for the above data." << endl; | |
cout << "Average score given by subjects under 18 who have not seen the ad: "<< under18navg << endl; | |
cout << "Average score given by subjects under 18 who have seen the ad: "<< under18yavg << endl; | |
cout << "Average score given by subjects 18 and over who have not seen the ad: "<< over18navg << endl; | |
cout << "Average score given by subjects 18 and over who have seen the ad: "<< over18yavg << endl; | |
cout << "Average score for all subjects: " << average << endl; | |
// Close the input file stream | |
inputFile.close(); | |
cout << "Press enter to continue..."; | |
getline(cin, reply); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment