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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
//Declare first name and lastname
string firstname;
string lastname;
//Declare The two test grades for students
double testgrade1;
double testgrade2;
//Decllare the three assignment grades for students
double assign1;
double assign2;
double assign3;
//Declare the counter which will be used to count the total number of students
int counter;
counter=0;
//Declare testaverage and assignment average to find the aveage of test and assignment
double testaverage;
double assignaverage;
//Declare totalpoints accumalted from all of the assignments and test
double totalpoints;
//Getting the sum of the entire class in the loop. Sum is set to store the previous value of numbergrade
double sum;
sum=0;
//Numeric grade determined of the student
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;
//The user will input an answer regarding which file to open. Three options will be given. A, b, or c
char answer;
//Declare a string variable that will open up a file wanted by the user
string filetopen;
//Declare the ifstream to open the input file
ifstream infile;
//*********************************************************************What File To Open?****************************************************************************************
//Ask the user which file they want to read from
cout<<"Which file would you like to read data from: (A, B, C)";
//Displays on the console the options of which file are available to read
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: ";
//Prompting the user to enter in a choice
cin>>answer;
//Switch Statement telling the program what to do if the user enters in a specific character
switch (answer)
{
case 'A':
case 'a':
cout<<"\n\n\tFile1.txt opening";
filetopen="File1.txt";
break;
case 'B':
case 'b':
cout<<"\n\n\tFile2.txt opening";
filetopen="File2.txt";
break;
case 'C':
case 'c':
cout<<"\n\n\tFile3.txt opening";
filetopen="File3.txt";
break;
default:
{cout<<"\n\n\tInvalid Input!";
return 0;
}
}
// Opening up the file user wanted
infile.open(filetopen);
//************************************************************************ERROR MESSAGE IF FILE DOES NOT OPEN************************************************************************
//In case, file doesnt open. Print out an error message
if (!infile)
{
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: ";
cout<< "\n\n\n";
cout<< "Name\t";
cout<< "\tTest";
cout<<"\t Assignments";
cout<< "\t Points";
cout <<"\t Numeric ";
cout<<"\tLetter ";
cout<<endl;
cout<<"\t\t Avg";
cout<< "\t Avg";
cout<<"\t\t\t Grd";
cout<< "\t\t Grd ";
//Enter in first name and last name in the filetxt
infile>>firstname;
infile>>lastname;
//User gets to type in the test grades and assignment grades
infile>>testgrade1 >>testgrade2;
infile>> assign1;
infile>>assign2;
infile>>assign3;
//**************************************************************************WHILE LOOP OF THE FILEDATA ENTRY******************************************************************************
while (infile)
{
//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);
cout<<fixed;
cout<<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 && numericgrade<=100)
{
cout<<setprecision(15);
cout<<"\t A";
}
//If number is higher then 80. Students gets a B
else if (numericgrade>=80 && numericgrade<90)
{
cout<<setprecision(15);
cout<<"\t B";
}
//If number is higher then 70. Student gets a C
else if (numericgrade>=70 && numericgrade<80)
{
cout<<setprecision(15);
cout<<"\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...again!
infile>>firstname;
infile>>lastname;
infile>> testgrade1;
infile>>testgrade2;
infile>> assign1;
infile>>assign2;
infile>>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;
//********************************************************************************DATA EMPTY. PRINT OUT 0!**************************************************************************
//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;
//Display the minimum grade out of the class
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;
//Display class average
cout<<"\n\n\t\tAverage: " <<setprecision(2)<<setw(6)<<average;
//Close the file
infile.close();
cout<<endl<<endl;
_getch();
return 0;
}
|