1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
//Global variables/constants, function prototypes
void headerfn();
void inputfn(string firstnames[40], string lastnames[40], float prog1[40], float prog2[40], float prog3[40], float test1[40], float test2[40], float test3[40], int&counter);
void outputfn(string firstnames[40], string lastnames[40], float prog1[40],
float prog2[40], float prog3[40], float test1[40],
float test2[40], float test3[40],int counter);
int totalfn(float prog1[40],
float prog2[40], float prog3[40], float test1[40],
float test2[40], float test3[40], float totalPts);
void outputfn2(string firstnames[10], string lastnames[10], float prog1[10],
float prog2[10], float prog3[10], float test1[10],
float test2[10], float test3[10],int counter);
ifstream fin;
ofstream fout;
//Function Definitions
int main(){
system("color f0");
headerfn();//void function call
//Declarations
string names[40][2];
int scores[40][6];
int total[40];
float averages[40][3];
char grades[40];
string filename;
ifstream datafile;
cout<<"Please enter the name/path of input file: ";
cin>>filename;
datafile.open(filename.c_str());
cout<<"Thank you! You entered: "<<filename<<endl;
fin.open("input4.txt");
fout.open("output4.txt");
if(!fin){cout<<"Input failure";
system("pause");
return 1;
}
if(!fout){cout<<"Output failure";
system("pause");
return 1;
}
int counter=0;
string firstnames[40];
string lastnames[40];
float prog1[40], prog2[40], prog3[40], test1[40], test2[40], test3[40];
inputfn(firstnames, lastnames, prog1, prog2, prog3, test1, test2, test3, counter);
outputfn(firstnames, lastnames, prog1, prog2, prog3, test1, test2, test3, counter);
for(int row=7; row<40;row++){
prog1[row]= prog2[row]= prog3[row]= test1[row]= test2[row]= test3[row]=0;}
float totalfn=0;
for(int col=0; col<7; col++){
totalfn=totalfn+prog1[col];
}
cout<<totalfn<<endl;
fout<<"*******************************************************\n";
fout<<"* IT 210 Business Applications with C++ *\n";
fout<<"* Programmer: *\n";
fout<<"* Program: Student Grades #4 *\n";
fout<<"* *\n";
fout<<"* This program uses functions to read student *\n";
fout<<"* information from an input text file into string *\n";
fout<<"* and integer arrays. It then calculates and outputs *\n";
fout<<"* averages and grades to the monitor as well as to *\n";
fout<<"* an output text file. *\n";
fout<<"*******************************************************\n";
fout<<endl<<setw(40)<<"STUDENT GRADES SHEET"<<endl;
fout<<endl<<"-----------------------------------------------------------------"<<endl;
fout<<"Student Name"<<setw(10)<<"Total"<<setw(11)<<"Program"<<setw(8)<<"Test"<<setw(11)<<"Course"<<setw(10)<<"Grade"<<endl;
fout<<setw(23)<<"Points"<<setw(10)<<"Average"<<setw(10)<<"Average"<<setw(10)<<"Average"<<endl;
fout<<endl<<"-----------------------------------------------------------------"<<endl;
for (int row=0;row<40;row++){
for(int col=0; col<2; col++)
fin>>names[row][col];
}
cout<<names;
fout.close();
system("pause");
return 0;
}//end of main
//***************************************************************
//Void Function Without Parameters
void headerfn(){
cout<<"*******************************************************\n";
cout<<"* IT 210 Business Applications with C++ *\n";
cout<<"* Programmer: *\n";
cout<<"* Program: Student Grades #4 *\n";
cout<<"* *\n";
cout<<"* This program uses functions to read student *\n";
cout<<"* information from an input text file into string *\n";
cout<<"* and integer arrays. It then calculates and outputs *\n";
cout<<"* averages and grades to the monitor as well as to *\n";
cout<<"* an output text file. *\n";
cout<<"*******************************************************\n";
}//end of headerfn
//**********************************************************
//Void Function with Parameters
void inputfn(string firstnames[40], string lastnames[40], float prog1[40],
float prog2[40], float prog3[40], float test1[40],
float test2[40], float test3[40], int &counter){
while(fin&&counter<40){
{fin>>firstnames[counter]>>lastnames[counter]>>prog1[counter]>>prog2[counter]>>
prog3[counter]>>test1[counter]>>test2[counter]>>test3[counter];}
counter++;
if(fin.peek ()=='\n')fin.ignore();}
}
//******************************************************************
//******************************************************************
//Void Function with Parameters
void outputfn(string firstnames[40], string lastnames[40], float prog1[40], float prog2[40], float prog3[40], float test1[40], float test2[40], float test3[40],int counter){
cout<<endl<<setw(40)<<"STUDENT GRADES SHEET"<<endl;
cout<<endl<<"-----------------------------------------------------------------"<<endl;
cout<<"Student Name"<<setw(10)<<"Total"<<setw(11)<<"Program"<<setw(8)<<"Test"<<setw(11)<<"Course"<<setw(10)<<"Grade"<<endl;
cout<<setw(23)<<"Points"<<setw(10)<<"Average"<<setw(10)<<"Average"<<setw(10)<<"Average"<<endl;
cout<<endl<<"-----------------------------------------------------------------"<<endl;
}
void outputfn2(string firstnames[10], string lastnames[10], float prog1[10], float prog2[10], float prog3[10], float test1[10], float test2[10], float test3[10],int counter){
for(int row=0; row<7;row++)
{
cout<<left<<setw(20)<<firstnames[row]+" "+lastnames[row]<<setw(10)
<<prog1[row]<<setw(10)<<prog2[row]<<setw(10)<<prog3[row]<<setw(10)
<<test1[row]<<setw(10)<<test2[row]<<setw(10)<<test3[row]<<endl;
}
}
| |