- #1
essdb1
- 1
- 0
//******************************************************************
//Sherman Brown
//CIS 150-01 Programming in C/C++
//April 17, 2011
//Program #7
//Organizing data by age and gender, calculating average weight/height.
//*******************************************************************
//Preprocess Directives
#include <iostream>
#include <iomanip>
#include <fstream>
//Namespace used
using namespace std;
//global variables
int age;
int count1;
int count2;
int count3;
int count4;
int count5;
int count6;
int minoravgheightF;
int minoravgweightF;
int minoravgheightM;
int minoravgweightM;
int adultavgheightF;
int adultavgweightF;
int adultavgheightM;
int adultavgweightM;
int oldavgheightF;
int oldavgweightF;
int oldavgheightM;
int oldavgweightM;
char gender;
double height;
double weight;
void avgfunc(int minoravgheightF,int minoravgweightF,int adultavgheightF,int adultavgweightF,int oldavgheightF,int oldavgweightF,int minoravgheightM,int minoravgweightM,int adultavgheightM,int adultavgweightM,int oldavgheightM,int oldavgweightM);
void printavg();
//main function/value returning function
int main()
{
ifstream inputfile; //input stream variable
ofstream outputfile; //output stream variable
inputfile.open("Prog7Input.txt"); //opens file
if (!inputfile) //if...else ensures file opens correctly
{
cout << "File not found." << endl;
cout << "Ending now." << endl;
}
else
{
inputfile >> gender >> age >> height >> weight; //gets first line of input from file
}
while (!inputfile.eof()) //necessary .eof like stated in assignment
{
void avgfunc();
inputfile >> gender >> age >> height >> weight;
}
void printavg();
return 0;
}
//******************************************************************
void avgfunc() //void function that reads and processes
{
if ((gender == 'f') || (gender == 'F'))
{
if ((age >= 0) && (age <=18), count1++)
{
minoravgheightF = minoravgheightF + height;
minoravgweightF = minoravgweightF + weight;
}
else if ((age >= 19) && (age <=35), count2++)
{
adultavgheightF = adultavgheightF + height;
adultavgweightF = adultavgweightF + weight;
}
else if (age >=36, count3++)
{
oldavgheightF = oldavgheightF + height;
oldavgweightF = oldavgweightF + weight;
}
else
{
cout << "Unanalyzable data." << endl;
}
}
else if ((gender == 'm') || (gender == 'M'))
{
if ((age >= 0) && (age <=18), count4++)
{
minoravgheightM = minoravgheightM + height;
minoravgweightM = minoravgweightM + weight;
}
else if ((age >= 19) && (age <=35), count5++)
{
adultavgheightM = adultavgheightM + height;
adultavgweightM = adultavgweightM + weight;
}
else if (age >=36, count6++)
{
oldavgheightM = oldavgheightM + height;
oldavgweightM = oldavgweightM + weight;
}
else
{
cout << "Unanalyzable data." << endl;
}
}
//******************************************************************
void printavg() //void function that print to outfile
{
outputfile << "Age Range: Male Height: Male weight: Female Height: Female Weight:" << endl;
outputfile << fixed << showpoint << setprecision(1);
outputfile << setw(6) << "0-18" << setw(13)
<< minoravgheightM / count1 << setw(13)
<< minoravgweightM / count1 << setw(13)
<< minoravgheightF / count2 << setw(13)
<< minoravgweightF / count2 << endl;
outputfile << setw(6) << "19-35" << setw(13)
<< adultavgheightM / count3 << setw(13)
<< adultavgweightM / count3 << setw(13)
<< adultavgheightF / count4 << setw(13)
<< adultavgweightF / count4 << endl;
outputfile << setw(6) << "36+" << setw(13)
<< oldavgheightM / count5 << setw(13)
<< oldavgweightM / count5 << setw(13)
<< oldavgheightF / count6 << setw(13)
<< oldavgweightF / count6 << endl;
;
}
One, I have no clue how to fix this. Yes it is an assignment as I clearly left that viewable, I just need a little help.
And showing me how to make this code easily viewable on this site would be useful!
//Sherman Brown
//CIS 150-01 Programming in C/C++
//April 17, 2011
//Program #7
//Organizing data by age and gender, calculating average weight/height.
//*******************************************************************
//Preprocess Directives
#include <iostream>
#include <iomanip>
#include <fstream>
//Namespace used
using namespace std;
//global variables
int age;
int count1;
int count2;
int count3;
int count4;
int count5;
int count6;
int minoravgheightF;
int minoravgweightF;
int minoravgheightM;
int minoravgweightM;
int adultavgheightF;
int adultavgweightF;
int adultavgheightM;
int adultavgweightM;
int oldavgheightF;
int oldavgweightF;
int oldavgheightM;
int oldavgweightM;
char gender;
double height;
double weight;
void avgfunc(int minoravgheightF,int minoravgweightF,int adultavgheightF,int adultavgweightF,int oldavgheightF,int oldavgweightF,int minoravgheightM,int minoravgweightM,int adultavgheightM,int adultavgweightM,int oldavgheightM,int oldavgweightM);
void printavg();
//main function/value returning function
int main()
{
ifstream inputfile; //input stream variable
ofstream outputfile; //output stream variable
inputfile.open("Prog7Input.txt"); //opens file
if (!inputfile) //if...else ensures file opens correctly
{
cout << "File not found." << endl;
cout << "Ending now." << endl;
}
else
{
inputfile >> gender >> age >> height >> weight; //gets first line of input from file
}
while (!inputfile.eof()) //necessary .eof like stated in assignment
{
void avgfunc();
inputfile >> gender >> age >> height >> weight;
}
void printavg();
return 0;
}
//******************************************************************
void avgfunc() //void function that reads and processes
{
if ((gender == 'f') || (gender == 'F'))
{
if ((age >= 0) && (age <=18), count1++)
{
minoravgheightF = minoravgheightF + height;
minoravgweightF = minoravgweightF + weight;
}
else if ((age >= 19) && (age <=35), count2++)
{
adultavgheightF = adultavgheightF + height;
adultavgweightF = adultavgweightF + weight;
}
else if (age >=36, count3++)
{
oldavgheightF = oldavgheightF + height;
oldavgweightF = oldavgweightF + weight;
}
else
{
cout << "Unanalyzable data." << endl;
}
}
else if ((gender == 'm') || (gender == 'M'))
{
if ((age >= 0) && (age <=18), count4++)
{
minoravgheightM = minoravgheightM + height;
minoravgweightM = minoravgweightM + weight;
}
else if ((age >= 19) && (age <=35), count5++)
{
adultavgheightM = adultavgheightM + height;
adultavgweightM = adultavgweightM + weight;
}
else if (age >=36, count6++)
{
oldavgheightM = oldavgheightM + height;
oldavgweightM = oldavgweightM + weight;
}
else
{
cout << "Unanalyzable data." << endl;
}
}
//******************************************************************
void printavg() //void function that print to outfile
{
outputfile << "Age Range: Male Height: Male weight: Female Height: Female Weight:" << endl;
outputfile << fixed << showpoint << setprecision(1);
outputfile << setw(6) << "0-18" << setw(13)
<< minoravgheightM / count1 << setw(13)
<< minoravgweightM / count1 << setw(13)
<< minoravgheightF / count2 << setw(13)
<< minoravgweightF / count2 << endl;
outputfile << setw(6) << "19-35" << setw(13)
<< adultavgheightM / count3 << setw(13)
<< adultavgweightM / count3 << setw(13)
<< adultavgheightF / count4 << setw(13)
<< adultavgweightF / count4 << endl;
outputfile << setw(6) << "36+" << setw(13)
<< oldavgheightM / count5 << setw(13)
<< oldavgweightM / count5 << setw(13)
<< oldavgheightF / count6 << setw(13)
<< oldavgweightF / count6 << endl;
;
}
One, I have no clue how to fix this. Yes it is an assignment as I clearly left that viewable, I just need a little help.
And showing me how to make this code easily viewable on this site would be useful!