Skip to content

Instantly share code, notes, and snippets.

@pope
Created April 14, 2011 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pope/919595 to your computer and use it in GitHub Desktop.
Save pope/919595 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
void headerfn();
string getstringinput(string);
void scoresfn(int, int, int, int, int, int);
int errorfn(int);
void avgfn(int, int, int, int, int, int, int, int, int,
float, float, float, float);
char gradefn(float);
void outputfn(string, string, int, float, float, float, char);
ofstream fout;
int main(){
string fname, lname;
int prog1, prog2, prog3, test1, test2, test3, total, progtotal, testtotal;
float progavg, testavg, totalavg, cavg;
char lgrade, flag;
fout.open("Studentsoutput.txt");
if(!fout){
cout<<"output failure"<<endl;
system("pause");
return 1;
}//end of error check
headerfn();
do{
fname = getstringinput("Please enter student's first name: ");
lname = getstringinput("Please enter student's last name: ");
scoresfn(prog1, prog2, prog3, test1, test2, test3);
avgfn(prog1, prog2, prog3, test1, test2, test3, total, progtotal, testtotal,
progavg, testavg, totalavg, cavg);
lgrade = gradefn(cavg);
outputfn(fname, lname, total, progavg, testavg, cavg, lgrade);
cout<<"please enter y to calculate another student's grades or n to exit: ";
cin>>flag;
}while(flag == 'y'|| flag == 'Y');
fout.close();
system ("pause");
return 0;
}//end of main
void headerfn(){
cout<<"012345678901234567890123456789012345678901234567890123456789"<<endl;
cout<<setw(60)<<setfill('*')<<"*"<<endl;
cout<<setw(10)<<left<<setfill(' ')<<"*";
cout<<setw(40)<<left<<setfill(' ')<<" ";
cout<<setw(10)<<right<<setfill(' ')<<"*"<<endl;
cout<<setw(10)<<left<<setfill(' ')<<"*";
cout<<setw(40)<<left<<setfill(' ')<<"IT 210 Business Applications with C++";
cout<<setw(10)<<right<<setfill(' ')<<"*"<<endl;
cout<<setw(10)<<left<<setfill(' ')<<"*";
cout<<setw(40)<<left<<setfill(' ')<<"Programmer: Molly Morneault";
cout<<setw(10)<<right<<setfill(' ')<<"*"<<endl;
cout<<setw(10)<<left<<setfill(' ')<<"*";
cout<<setw(40)<<left<<setfill(' ')<<"Date: March 31, 2011";
cout<<setw(10)<<right<<setfill(' ')<<"*"<<endl;
cout<<setw(10)<<left<<setfill(' ')<<"*";
cout<<setw(40)<<left<<setfill(' ')<<" ";
cout<<setw(10)<<right<<setfill(' ')<<"*"<<endl;
cout<<setw(10)<<left<<setfill(' ')<<"*";
cout<<setw(40)<<left<<setfill(' ')<<"Program Assignment 3: Students' Grades";
cout<<setw(10)<<right<<setfill(' ')<<"*"<<endl;
cout<<setw(10)<<left<<setfill(' ')<<"*";
cout<<setw(40)<<left<<setfill(' ')<<" ";
cout<<setw(10)<<right<<setfill(' ')<<"*"<<endl;
cout<<setw(60)<<setfill('*')<<"*"<<endl;
}//end of headerfn
string getstringinput(string msg){
string result;
cout<<msg;
cin>>result;
return result;
}//end of getstringinput
void scoresfn(int prog1, int prog2, int prog3, int test1, int test2, int test3){
cout<<"Please enter the first program score: ";
cin>>prog1;
prog1 = errorfn(prog1);
cout<<"Please enter the second program score: ";
cin>>prog2;
prog2 = errorfn(prog2);
cout<<"Please enter the third program score: ";
cin>>prog3;
prog3 = errorfn(prog3);
cout<<"Please enter the first test score: ";
cin>>test1;
test1 = errorfn(test1);
cout<<"Please enter the second test score: ";
cin>>test2;
test2 = errorfn(test2);
cout<<"Please enter the third test score: ";
cin>>test3;
test3 = errorfn(test3);
return;
}//end of scoresfn
int errorfn(int score){
while(score>100||score<0){
cout<<"Oops! That's an invalid entry. Please enter a score between"
<<" zero and 100: ";
cin>>score;
}
return score;
}//end of errorfn
void avgfn(int prog1, int prog2, int prog3, int test1, int test2, int test3,
int total, int progtotal, int testtotal,
float progavg, float testavg, float totalavg, float cavg){
total = prog1+prog2+prog3+test1+test2+test3;
progtotal = prog1+prog2+prog3;
testtotal = test1+test2+test3;
progavg = progtotal/3;
testavg = testtotal/3;
totalavg = progavg+testavg;
cavg = totalavg/2;
return;
}//end of avgfn
char gradefn(float cavg){
char lgrade;
if(cavg>=90){
return 'A';
}
else if (cavg>=80){
return 'B';
}
else if(cavg>=70){
return 'C';
}
else{
return 'F';
}
}//end of gradefn
void outputfn(string fname, string lname, int total, float progavg,
float testavg, float cavg, char lgrade){
cout<<"0123456789012345678901234567890123456789012345678901234567890123456789"<<endl;
cout<<setw(70)<<setfill('=')<<"="<<endl;
cout<<setw(20)<<setfill(' ')<<left<<"Student Name";
cout<<setw(10)<<setfill(' ')<<left<<"Total";
cout<<setw(10)<<setfill(' ')<<left<<"Program";
cout<<setw(10)<<setfill(' ')<<left<<"Test";
cout<<setw(10)<<setfill(' ')<<left<<"Course";
cout<<setw(10)<<setfill(' ')<<left<<"Letter"<<endl;
cout<<setw(20)<<setfill(' ')<<left<<" ";
cout<<setw(10)<<setfill(' ')<<left<<"Points";
cout<<setw(10)<<setfill(' ')<<left<<"Average";
cout<<setw(10)<<setfill(' ')<<left<<"Average";
cout<<setw(10)<<setfill(' ')<<left<<"Average";
cout<<setw(10)<<setfill(' ')<<left<<"Grade"<<endl;
cout<<setw(70)<<setfill('-')<<"-"<<endl;
cout<<setw(20)<<setfill(' ')<<left<<fname+ " " +lname;
cout<<setw(10)<<setfill(' ')<<left<<total;
cout<<setw(10)<<setfill(' ')<<setprecision(2)<<showpoint<<fixed<<left<<progavg;
cout<<setw(10)<<setfill(' ')<<setprecision(2)<<showpoint<<fixed<<left<<testavg;
cout<<setw(10)<<setfill(' ')<<setprecision(2)<<showpoint<<fixed<<left<<cavg;
cout<<setw(10)<<left<<setfill(' ')<<lgrade<<endl;
cout<<setw(70)<<setfill('-')<<"-"<<endl;
fout<<"0123456789012345678901234567890123456789012345678901234567890123456789"<<endl;
fout<<setw(70)<<setfill('=')<<"="<<endl;
fout<<setw(20)<<setfill(' ')<<left<<"Student Name";
fout<<setw(10)<<setfill(' ')<<left<<"Total";
fout<<setw(10)<<setfill(' ')<<left<<"Program";
fout<<setw(10)<<setfill(' ')<<left<<"Test";
fout<<setw(10)<<setfill(' ')<<left<<"Course";
fout<<setw(10)<<setfill(' ')<<left<<"Letter"<<endl;
fout<<setw(20)<<setfill(' ')<<left<<" ";
fout<<setw(10)<<setfill(' ')<<left<<"Points";
fout<<setw(10)<<setfill(' ')<<left<<"Average";
fout<<setw(10)<<setfill(' ')<<left<<"Average";
fout<<setw(10)<<setfill(' ')<<left<<"Average";
fout<<setw(10)<<setfill(' ')<<left<<"Grade"<<endl;
fout<<setw(70)<<setfill('-')<<"-"<<endl;
fout<<setw(20)<<setfill(' ')<<left<<fname+ " " +lname;
fout<<setw(10)<<setfill(' ')<<left<<total;
fout<<setw(10)<<setfill(' ')<<setprecision(2)<<showpoint<<fixed<<left<<progavg;
fout<<setw(10)<<setfill(' ')<<setprecision(2)<<showpoint<<fixed<<left<<testavg;
fout<<setw(10)<<setfill(' ')<<setprecision(2)<<showpoint<<fixed<<left<<cavg;
fout<<setw(10)<<left<<setfill(' ')<<lgrade<<endl;
fout<<setw(70)<<setfill('-')<<"-"<<endl;
return;
}//end of outputfn
//I've rewritten this program 4 times and will include all versions on my USB disk,
//I could not get the output to come out correctly. I even tried calling the functions
//within the outputfn. At this point, I don't know how else to get the output to show
//up correctly. The student's name doesn't even show up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment