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 <string>
#include <fstream>
using namespace std; // <--- Best not to use.
const double HOMEWORK_WEIGHT{ 0.55 };
const double MIDTERM_WEIGHT{ 0.20 };
const double FINAL_WEIGHT{ 0.25 };
const string FILL_LINE(60, '=');
const string RULER{ "1234567890" };
int main()
{
int unsigned index{};
const std::string fileNames[]
{
"inData.txt", "inData2.txt", "inData3.txt", "inData4.txt",
"inData5.txt", "inData6.txt", "inData7.txt", "inData8.txt",
"inData9.txt", "inData10.txt", "inData11.txt", "inData12.txt",
"inData13.txt", "inData14.txt", "inData15.txt", "inData16.txt",
"inData17.txt", "inData18.txt", "inData19.txt", "inData20.txt"
};
ifstream inFile;
ofstream outFile("outData.txt");
if (!outFile)
{
return std::cerr<< "\n\n File \"outData.txt\" did not open.\n", 1;
}
outFile << fixed << /*showpoint <<*/ setprecision(2); // <--- Not required, but OK if you leave
string firstName, lastName, level;
double homeworkAVG{}, finalGrade{}; // <--- ALWAYS initialize all your variables.
string rulerLine = RULER + RULER + RULER + RULER + RULER + RULER;
//string fillLine = Fill + Fill + Fill + Fill + Fill + Fill;
int absent{}, present{}; // <--- ALWAYS initialize all your variables.
while (true)
{
ifstream inFile(fileNames[index]);
if (!inFile)
{
std::cerr << "\n\n File "<<std::quoted(fileNames[index]) <<" did not open. Or does not exist.\n\n";
break;
}
while (inFile >> firstName >> lastName >> level)
{
double grades[14]{}, totalgrades{};
for (unsigned idx = 0; idx < 14 && inFile >> grades[idx]; idx++)
{
if (idx < 9)
{
totalgrades += grades[idx];
}
}
//inFile >> grades[]1 >> grades[]2 >> grades[]3 >> grades[]4 >> grades[]5 >> grades[]6
// >> grades[]7 >> grades[]8 >> grades[]9 >> grades[]10 >> midterm >> finalExamGrade
// >> present >> absent;
//algorithms;
homeworkAVG = totalgrades / 10.0;
//grades[]AVG = (grades[]1 + grades[]2 + grades[]3 + grades[]4 + grades[]5 + grades[]6 + grades[]7 + grades[]8 + grades[]9 + grades[]10) / 10;
finalGrade = (homeworkAVG * HOMEWORK_WEIGHT) + (grades[10] * MIDTERM_WEIGHT) + (grades[11] * FINAL_WEIGHT);
//finalGrade = (grades[]AVG * grades[]_Weight) + (midterm * MIDTERM_WEIGHT) + (finalExamGrade * FINAL_WEIGHT);
//outputs;
outFile
<< left
<< rulerLine << " // <--- Is this really needed?\n" // <--- Is this really needed?
<< FILL_LINE << "\n"
<< "|" << setw(10) << " Student" << "| " << setw(20) << lastName + "," + " " + firstName
<< "|" << setw(13) << " Grade Level" << "| " << setw(10) << level << "|" << endl
<< FILL_LINE << "\n"
<< "|" << left << setw(10) << " Present" << "|" <<
setw(4) << right << setw(7) << grades[12] << " " << "-" << setw(6) <<
(grades[12] / grades[12] + grades[13]) * 100.0 << "% ";
outFile << "|" << left << setw(10) << " Absent" << "|" << setw(4) << right << setw(8) << grades[13] << " " << "-" << setw(6) <<
(grades[13] / grades[12] + grades[13]) * 100.0 << "% | " << endl;
outFile << FILL_LINE << endl;
outFile << "|" << setw(25) << left << " Homework" << setw(20) << "| Average" << "|" << setw(12) << right << homeworkAVG << "|" << endl;
outFile << FILL_LINE << endl;
outFile << "|" << setw(25) << left << " Assignment 1" << "|" << setw(19) << right << grades[0] << "|" << setw(13) << "|" << endl;
outFile << "|" << setw(25) << left << " Assignment 2" << "|" << setw(19) << right << grades[1] << "|" << setw(13) << "|" << endl;
outFile << "|" << setw(25) << left << " Assignment 3" << "|" << setw(19) << right << grades[2] << "|" << setw(13) << "|" << endl;
outFile << "|" << setw(25) << left << " Assignment 4" << "|" << setw(19) << right << grades[3] << "|" << setw(13) << "|" << endl;
outFile << "|" << setw(25) << left << " Assignment 5" << "|" << setw(19) << right << grades[4] << "|" << setw(13) << "|" << endl;
outFile << "|" << setw(25) << left << " Assignment 6" << "|" << setw(19) << right << grades[5] << "|" << setw(13) << "|" << endl;
outFile << "|" << setw(25) << left << " Assignment 7" << "|" << setw(19) << right << grades[6] << "|" << setw(13) << "|" << endl;
outFile << "|" << setw(25) << left << " Assignment 8" << "|" << setw(19) << right << grades[7] << "|" << setw(13) << "|" << endl;
outFile << "|" << setw(25) << left << " Assignment 9" << "|" << setw(19) << right << grades[8] << "|" << setw(13) << "|" << endl;
outFile << "|" << setw(25) << left << " Assignment 10" << "|" << setw(19) << right << grades[9] << "|" << setw(13) << "|" << endl;
outFile << FILL_LINE << endl;
outFile << "|" << setw(25) << left << " Midterm Grade:" << setw(20) << "|" << "|" << setw(12) << right << grades[10] << "|" << endl;
outFile << FILL_LINE << endl;
outFile << "|" << setw(25) << left << " Final Exam Grade:" << setw(20) << "|" << "|" << setw(12) << right << grades[11] << "|" << endl;
outFile << FILL_LINE << endl;
outFile << "|" << setw(25) << left << " Course Grade:" << setw(20) << "|" << "|" << setw(12) << right << finalGrade << "|\n";
outFile << FILL_LINE << "\n\n";
}
// Close
inFile.close(); // <--- This is required here.
index++;
}
//outFile.close(); // <--- Not required as the dtor will close the file when the function looses scope.
cout << "Progressing Complete!!!!!" << endl;
return 0; // <--- Not required, but makes a good break point for testing.
}
|