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
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
int asscalc(int [], int);
int calc(int, int, int, int, int);
using namespace std;
int main(){
ifstream infile;
ofstream outfile, outfileagain;
const int outof = 400;
const int ELEMENTS = 10;
int ass[ELEMENTS], stdntid, ex, tot = 0, mi, fin, cl, pts, i, countA = 0, countB = 0, countC = 0, countD = 0, countF = 0, sign;
double pct;
string gr;
//Input File
infile.open("C:\\Users\\leewi\\Desktop\\Computer Programs & Projects\\C++\\BentleyCIS22B\\CIS22BAss1\\ass1data.txt");
//Output File
outfile.open("C:\\Users\\leewi\\Desktop\\Computer Programs & Projects\\C++\\BentleyCIS22B\\CIS22BAss1\\studentreportoutputfile.txt");
//Ignore the outfileagain manipulator for now. This is to output the quantity of As, Bs, Cs, Ds, and Fs.
outfileagain.open("C:\\Users\\leewi\\Desktop\\Computer Programs & Projects\\C++\\BentleyCIS22B\\CIS22BAss1\\grades.txt");
outfile << "Stdnt Id Ex ------- Assignments --------- Tot Mi Fin CL Pts Pct Gr" << endl;
outfile << "-------- -- ----------------------------- --- -- --- -- --- --- --" << endl;
if(infile.fail()){
cout << "Can't Open File";
exit(0);
}
do{
infile >> stdntid;
if (stdntid <= 10000000){
outfile << 0;
}
infile >> ex;
for(i = 0; i < 10; i++){
infile >> ass[i];
}
infile >> mi;
infile >> fin;
infile >> cl;
outfile << stdntid << setw(4) << ex << setw(4);
for (i = 0; i < 10; i++){
outfile << ass[i] << setw(3);
}
tot = asscalc(ass, i);
pts = calc(ex, tot, mi, fin, cl);
pct = (static_cast<double>(pts)/outof) * 100;
sign = static_cast<int>(pct) % 10;
if (pct >= 90){
gr = "A";
countA++;
}
else if (pct >= 80){
gr = "B";
countB++;
}
else if (pct >= 70){
gr = "C";
countC++;
}
else if (pct >= 60){
gr = "D";
countD++;
}
else{
gr = "F";
countF++;
}
outfile << setw(5) << tot << setw(4) << mi << setw(5) << fin << setw(4) << cl << setw(5) << pts << setw(5) << setprecision(2) << pct << setw(4) << gr;
if (sign <= 1){
outfile << "-" << endl;
}
else if (sign >= 9){
outfile << "+" << endl;
}
else{
outfile << endl;
}
}while(!infile.eof());
cout << "Check Student Report on student \"reportoutputfile.txt\" & Grades on \"grades.txt\"" << endl;
outfileagain << "Number of A's = " << countA << endl;
outfileagain << "Number of B's = " << countB << endl;
outfileagain << "Number of C's = " << countC << endl;
outfileagain << "Number of D's = " << countD << endl;
outfileagain << "Number of F's = " << countF << endl;
infile.close();
outfile.close();
outfileagain.close();
return 0;
}
int calc(int ex, int tot, int mi, int fin, int cl){
int pts;
pts = ex + tot + mi + fin + cl;
return pts;
}
int asscalc(int ass[], int i){
int tot = 0;
int startScan, minIndex, hold;
const int ELEMENTS = 10;
for (startScan = 0; startScan < (ELEMENTS - 1); startScan++)
{
// find index of the largest value
minIndex = startScan;
for(int index = startScan + 1; index < ELEMENTS; index++)
{
if (ass[index] > ass[minIndex])
{
minIndex = index;
}
}
// swap
hold = ass[minIndex];
ass[minIndex] = ass[startScan];
ass[startScan] = hold;
}
for(i = 0; i < 9; i++){
tot += ass[i];
}
return tot;
}
|