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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
//********************************************************************START OF CODE**********************************************************************************************
//Declare Variable for names, two test grades, counter for number students, average of test, average of all assignments and tests, letter grade, etc...
string firstname;
string lastname;
double testgrade1;
double testgrade2;
double assign1;
double assign2;
double assign3;
int counter;
counter=0;
double testaverage;
double assignaverage;
double totalpoints;
//Getting the sum of the entire class in the loop
double sum=0;
double numericgrade;
//Set minimum to 100 to find the minimum value
double minimum=100;
//Declare and initilize maximum to find the maximum value of the student
double maximum=0;
//Declare average to find the class average
double average;
//Ask the user which file they want to read from
cout<<"Which file would you like to read data from: (A, B, C)";
//Declare the variable where user will type in a character
char answer;
cout<<"\n\t\t\tA.) File1.txt";
cout<<"\n\t\t\tB.) File2.txt";
cout<<"\n\t\t\tC.) File3.txt";
cout<<"\n\n\t\t\tFile: ";
cin>>answer;
switch (answer)
{
case 'A':
cout<<"\n\n\tFile1.txt opening";
break;
case 'B':
cout<<"\n\n\tFile2.txt opening";
break;
case 'C':
cout<<"\n\n\tFile3.txt opening";
break;
default:
cout<<"\n\n\tInvalid Input!";
}
// Open file2.txt
ifstream fin;
fin.open("File1.txt");
//In case, file doesnt open. Print out an error message
if (!fin)
{
cout<<"Cannot open the input file" <<"\nProgram Terminates";
//This return1 will exit the program due to error
return 1;
}
//**************************************************CONSOLE OPEN**************************************************************************************************************
//Outputing data names that will be outputted on the screen. For instance, name, grades, letter grade
cout<< " Student Statistics: " << endl <<endl<<endl;
cout<< "Name\t" << "\tTest" << "\t Assignments" << "\t Points" <<"\t Numeric " <<"\tLetter ";
cout<< endl << "\t\t Avg" << "\t Avg"<< "\t\t\t Grd" << "\t\t Grd ";
//Enter in first name and last name in the filetxt
fin>>firstname >>lastname;
fin>>testgrade1 >>testgrade2;
fin>> assign1 >>assign2>>assign3;
//Going into the while loop.
while (fin)
{
//Print out the first and last name of the student
cout<<left;
cout<< "\n\n" << setw(11)<< firstname+ " " +lastname;
//Calculate the testaverage. Round it to two decimal places, with trailing zeroes
testaverage=(testgrade1+testgrade2)/2;
cout<<setprecision(2) <<fixed<<showpoint;
cout<<right<<setw(10) <<testaverage;
//Calculate the assignment average of each student
assignaverage=(assign1+assign2+assign3)/3;
cout<< setw(15);
cout<<assignaverage;
//Calculate the total points accumalated
totalpoints= testgrade1+testgrade2+assign1+assign2+assign3;
cout<< setw(16) <<totalpoints;
//Calculate the the numericgrade. Add up assignments and test, then divide by 5 to find the numericavg grade
numericgrade= (testgrade1+testgrade2+assign1+assign2+assign3)/5;
cout<< setw(12) <<numericgrade;
//you will use the if and else statement to calculate the letter grade
//If number is higher then 90. Student gets an A
if(numericgrade>=90)
cout<<setprecision(15)<<"\t A";
//If number is higher then 80. Students gets a B
else if (numericgrade>=80)
cout<<setprecision(15)<<"\t B";
//If number is higher then 70. Student gets a C
else if (numericgrade>=70)
cout<<setprecision(15)<<"\t C";
//Any lower then 70, gets an F
else
{
cout<<setprecision(15)<<"\t F";
}
//Minimum is declared as 100. If minimum is greater then numeric grade, then numeric grrade will become minimum
//For instance, numeric grade is 89 and minimum is 100. Minimum is greater then 89. 89 becomes the minimum.
//During the next loop, 89 is stored in mininum.
if(minimum>numericgrade)
minimum=numericgrade;
//Maximum is declared at zero. If maxium is less then numeric grade then maxium will become numeric grade.
if (maximum<numericgrade)
maximum=numericgrade;
//Prevent the loop from becoming an infinite loop. Enter in names, scores, etc...
fin>>firstname >>lastname;
fin>> testgrade1 >>testgrade2;
fin>> assign1 >>assign2>>assign3;
//Sum is used in this loop to find the total sum of numeric grades
sum=sum+numericgrade;
//Add counter++ to determine the total number of students
counter++;
}
//Find the average of students
average=sum/counter;
//If the file is an empty set, I will set counter=0 and other values to zero.
if (counter==0)
{
average=0;
minimum=0;
maximum=0;
}
//Overall Class Statistics output
//Display Class Statistic on console
cout<<"\n\n\n\tClass Statistics ";
//Display The minimum grade out of the whole class and have all the values right manipulated
cout<<right;
//Display number of students in class and the calculation of total students
cout<<"\n\n\t\tNumber: "<< setw(7)<<counter;
cout<<"\n\n\t\tMinimum: " <<setw(6)<<setprecision(2)<<minimum;
//Display the maximum grade out of the whole class
cout<<"\n\n\t\tMaximum: " <<setw(6)<<setprecision(2)<<maximum;
cout<<"\n\n\t\tAverage: " <<setprecision(2)<<setw(6)<<average;
//Close the file
fin.close();
_getch();
return 0;
}
|