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
|
#include <iostream>
#include <cstring>
#include <fstream>
#include <cstdlib> //!! for system()
using namespace std;
struct records {
int Eng, Math, Phy, Che, Bio, GPA;
char name[30], IC[30], Fcode[30], result[30];
char year[30];
};
//!!foo.cpp:13:6: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
//!! main()
//!! ^
int main()
{
int ns;
char IC[30], year1[30], result1[30];
char Egrade, Mgrade, Cgrade, Pgrade, Bgrade;
ifstream Test1;
Test1.open("Test1.txt");
struct records T1[3];
int i, x;
//!! Beware that reading 3 records from a file containing 3 records will still leave eof() as false
//!! eof() only becomes true AFTER an input function like getline() has also failed.
while (!Test1.eof()) {
//!! foo.cpp:31:31: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized]
//!! Test1.getline(T1[x].IC, 30);
Test1.getline(T1[x].IC, 30);
Test1.getline(T1[x].name, 30);
Test1.getline(T1[x].Fcode, 30);
Test1.getline(T1[x].result, 30);
Test1.getline(T1[x].year, 30);
Test1 >> T1[x].Eng;
Test1 >> T1[x].Math;
Test1 >> T1[x].Phy;
Test1 >> T1[x].Che;
Test1 >> T1[x].Bio;
Test1 >> T1[x].GPA;
//!! it might be a good idea to increment x as well
}
cout << "SAPS\n" << endl;
cout << "-----------\n" << endl;
cout << "Login" << endl;
cout << "-----------" << endl;
cout << "IC / Passport no :\n";
cin.getline(IC, 30);
system("pause"); // to pause the system
system("cls"); //clear screen for the next output screen
for (i = 0; i < 3; i++) {
if (strcmp(T1[i].IC, IC) == 0) {
do {
cout << "--------------" << endl;
cout << "Enter year :" << endl;
cout << "--------------\n" << endl;
cout << "2015" << endl;
cout << "2016" << endl;
cout << "2017\n" << endl;
cin >> year1;
cout << endl << endl;
system("pause"); // to pause the system
system("cls"); //clear screen for the next output screen
cout << "--------------" << endl;
cout << "Enter the number of the type of result needed:" << endl;
cout << "--------------\n" << endl;
cout << "1.Test 1" << endl;
cout << "2.Mid Term Test" << endl;
cout << "3.Final Test" << endl;
cin >> result1;
cout << endl << endl;
system("pause"); // to pause the system
system("cls"); //clear screen for the next output screen
//calculation for grades
if (T1[i].Eng >= 80)
Egrade = 'A';
else if (T1[i].Eng >= 60)
Egrade = 'B';
else if (T1[i].Eng >= 50)
Egrade = 'C';
else if (T1[i].Eng >= 40)
Egrade = 'D';
else
Egrade = 'F';
if (T1[i].Math >= 80)
Mgrade = 'A';
else if (T1[i].Math >= 60)
Mgrade = 'B';
else if (T1[i].Math >= 50)
Mgrade = 'C';
else if (T1[i].Math >= 40)
Mgrade = 'D';
else
Mgrade = 'F';
if (T1[i].Phy >= 80)
Pgrade = 'A';
else if (T1[i].Phy >= 60)
Pgrade = 'B';
else if (T1[i].Phy >= 50)
Pgrade = 'C';
else if (T1[i].Phy >= 40)
Pgrade = 'D';
else
Pgrade = 'F';
if (T1[i].Che >= 80)
Cgrade = 'A';
else if (T1[i].Che >= 60)
Cgrade = 'B';
else if (T1[i].Che >= 50)
Cgrade = 'C';
else if (T1[i].Che >= 40)
Cgrade = 'D';
else
Cgrade = 'F';
if (T1[i].Bio >= 80)
Bgrade = 'A';
else if (T1[i].Bio >= 60)
Bgrade = 'B';
else if (T1[i].Bio >= 50)
Bgrade = 'C';
else if (T1[i].Bio >= 40)
Bgrade = 'D';
else
Bgrade = 'F';
if ((strcmp(T1[i].year, year1) == 0)
&& (strcmp(T1[i].result, result1) == 0)) {
cout << "Student Name :" << T1[i].name << endl;
cout << "Student Faculty Code :" << T1[i].Fcode << endl;
cout << "Type of Test" << endl;
cout << "1.Test 1\n2.Mid Term Test \n3.Final Test" << endl;
cout << "Choosen :" << T1[i].result << endl;
cout << "-------------------------------" << endl;
cout << "No.| Subject | Marks | Grade " << endl;
cout << "-------------------------------" << endl;
cout << "1. | English |" << T1[i].Eng << " | " << Egrade << endl;
cout << "2. | Mathematics |" << T1[i].Math << " | " << Mgrade << endl;
cout << "3. | Physics |" << T1[i].Phy << " | " << Pgrade << endl;
cout << "4. | Chemistry |" << T1[i].Che << " | " << Cgrade << endl;
cout << "5. | Biology |" << T1[i].Bio << " | " << Bgrade << endl;
cout << "GPA for the test:" << T1[i].GPA << endl;
cout << "---------------------------------" << endl;
cout << "Choose 1-3 to proceed to next step :" << endl;
cout << "---------------------------------\n" << endl;
cout << "1. Print report card" << endl;
cout << "2. Back to result type page" << endl;
cout << "3. Quit\n" << endl;
cin >> ns;
}
system("pause"); // to pause the system
system("cls"); //clear screen for the next output screen
//calculation for grades
} while (ns == 2);
if (ns == 1) {
cout << "Printing Result..." << endl;
return 0;
} else if (ns == 3)
return 0;
}
}
Test1.close();
}
|