22f-3672 CP Ayesha
22f-3672 CP Ayesha
public:
void getdata();
void showdata() const;
void calculate();
Ayesha Naseer 22f-3672
void Student::calculate()
{
per = (oop_marks + ds_marks + ise_marks + eng_marks + is_marks) / 5.0;
if (per >= 85) {
grade = 'A';
gpa = 4;
}
else if (per >= 75) {
grade = 'B';
gpa = 3.33;
}
else if (per >= 65) {
grade = 'C';
gpa = 2.66;
}
else if (per >= 50) {
grade = 'D';
gpa = 2;
}
else
Ayesha Naseer 22f-3672
grade = 'F';
}
void Student::getdata()
{
cout << "\nEnter The roll number of student ";
cin >> rollno;
cout << "\nEnter The Name of student ";
cin.ignore();
cin.getline(name, 50);
cout << "\nEnter The marks in OOP out of 100: ";
cin >> oop_marks;
cout << "\nEnter The marks in DS out of 100: ";
cin >> ds_marks;
cout << "\nEnter The marks in ISE out of 100: ";
cin >> ise_marks;
cout << "\nEnter The marks in ENG out of 100: ";
cin >> eng_marks;
cout << "\nEnter The marks in IS out of 100: ";
cin >> is_marks;
Ayesha Naseer 22f-3672
calculate();
}
void write_student()
{
Student st;
ofstream outFile;
outFile.open("student.txt", ios::app);
st.getdata();
outFile.write(reinterpret_cast<char*> (&st), sizeof(Student));
outFile.close();
cout << "\n\nStudent record Has Been Created ";
cin.ignore();
cin.get();
}
void display_all()
{
Student st;
ifstream inFile;
inFile.open("student.txt", ios::binary);
Ayesha Naseer 22f-3672
if (!inFile)
{
cout << "File could not be open !! Press any Key...";
cin.ignore();
cin.get();
return;
}
cout << "\n\n\n\t\tDISPLAY ALL RECORD !!!\n\n";
while (inFile.read(reinterpret_cast<char*> (&st), sizeof(Student)))
{
st.showdata();
cout << "\n\n====================================\n";
}
inFile.close();
cin.ignore();
cin.get();
}
void display_sp(int n)
{
Student st;
Ayesha Naseer 22f-3672
ifstream inFile;
inFile.open("student.txt", ios::app);
if (!inFile)
{
cout << "File could not be open !! Press any Key...";
cin.ignore();
cin.get();
return;
}
bool flag = false;
while (inFile.read(reinterpret_cast<char*> (&st), sizeof(Student)))
{
if (st.getRollNo() == n)
{
st.showdata();
flag = true;
}
}
inFile.close();
if (flag == false)
cout << "\n\nrecord not exist";
Ayesha Naseer 22f-3672
cin.ignore();
cin.get();
}
void modify_student(int n)
{
bool found = false;
Student st;
fstream File;
File.open("student.txt", ios::app | ios::in | ios::out);
if (!File)
{
cout << "File could not be open !! Press any Key...";
cin.ignore();
cin.get();
return;
}
while (!File.eof() && found == false)
{
if (st.getRollNo() == n)
{
st.showdata();
cout << "\n\nPlease Enter The New Details of student" << endl;
st.getdata();
int pos = (-1) * static_cast<int>(sizeof(st));
File.seekp(pos, ios::cur);
File.write(reinterpret_cast<char*> (&st), sizeof(Student));
cout << "\n\n\t Record Updated";
found = true;
}
}
File.close();
if (found == false)
cout << "\n\n Record Not Found ";
cin.ignore();
cin.get();
}
void delete_student(int n)
{
Ayesha Naseer 22f-3672
Student st;
ifstream inFile;
inFile.open("student.txt", ios::app);
if (!inFile)
{
cout << "File could not be open !! Press any Key...";
cin.ignore();
cin.get();
return;
}
ofstream outFile;
outFile.open("Temp.txt", ios::out);
inFile.seekg(0, ios::beg);
while (inFile.read(reinterpret_cast<char*> (&st), sizeof(Student)))
{
if (st.getRollNo() != n)
{
outFile.write(reinterpret_cast<char*> (&st), sizeof(Student));
}
}
outFile.close();
Ayesha Naseer 22f-3672
inFile.close();
remove("student.txt");
rename("Temp.txt", "student.txt");
cout << "\n\n\tRecord Deleted ..";
cin.ignore();
cin.get();
}
void class_result()
{
Student st;
ifstream inFile;
inFile.open("student.txt", ios::app);
if (!inFile)
{
cout << "File could not be open !! Press any Key...";
cin.ignore();
cin.get();
return;
}
cout << "\n\n\t\t\t\tALL STUDENTS RESULT \n\n";
Ayesha Naseer 22f-3672
cout <<
"====================================================================================
====\n";
cout << "R.No Name OOP DS ISE ENG IS %age Grade GPA" << endl;
cout <<
"====================================================================================
====\n";
while (inFile.read(reinterpret_cast<char*> (&st), sizeof(Student)))
{
st.show_tabular();
}
cin.ignore();
cin.get();
inFile.close();
}
int main()
{
char ch;
cout.setf(ios::fixed | ios::showpoint);
cout << setprecision(2);
string username, password;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, 1);
cout << "**************************************" << endl;
cout << " Login Page " << endl;
cout << "**************************************" << endl;
case '1':
char ch;
int rno;
system("cls");
cout << "\n\
n************************************************************\n";
cout << "\t\tRESULT MENU";
cout << "\
n************************************************************\n";
cout << "\n\n\n\t1. Class Result";
cout << "\n\n\t2. Student Report Card";
cout << "\n\n\t3. Back to Main Menu";
cout << "\n\n\n\tEnter Choice (1/2/3)? ";
cin >> ch;
system("cls");
switch (ch)
{
case '1':
system("cls");
SetConsoleTextAttribute(hConsole, 5);
cout << "\n\
n************************************************************************************
****\n";
cout << "\t\t\t\tCLASS REPORT";
cout << "\
n************************************************************************************
****\n";
Ayesha Naseer 22f-3672
class_result();
break;
case '2':
system("cls");
SetConsoleTextAttribute(hConsole, 5);
cout << "\n\
n************************************************************\n";
cout << "\t\t\tSTUDENT REPORT CARD";
cout << "\
n************************************************************\n";
cout << "\n\n\tEnter Roll Number Of Student : ";
cin >> rno;
display_sp(rno);
break;
case '3':
break;
default:
cout << "\a";
}
break;
case '2':
char ch;
Ayesha Naseer 22f-3672
int num;
system("cls");
SetConsoleTextAttribute(hConsole, 5);
cout << "\n\
n************************************************************\n";
cout << "\t\t\tENTRY MENU";
cout << "\
n************************************************************\n";
cout << "\n\n\t1.Create Student Record";
cout << "\n\t2.Display all Student Record";
cout << "\n\t3.Search Student Record";
cout << "\n\t4.Modify Student Record";
cout << "\n\t5. Delete Student Record";
cout << "\n\t6.Back to Main Menu";
cout << "\n\tPlease Enter Your Choice (1-6) ";
cin >> ch;
system("cls");
switch (ch)
{
case '1':
system("cls");
SetConsoleTextAttribute(hConsole, 6);
Ayesha Naseer 22f-3672
SetConsoleTextAttribute(hConsole, 5);
display_all();
break;
case '3':
system("cls");
SetConsoleTextAttribute(hConsole, 6);
Ayesha Naseer 22f-3672
SetConsoleTextAttribute(hConsole, 5);
cout << "\n\n\tPlease Enter The roll number ";
cin >> num;
display_sp(num);
break;
case '4':
system("cls");
SetConsoleTextAttribute(hConsole, 6);
SetConsoleTextAttribute(hConsole, 5);
cout << "\n\n\tPlease Enter The roll number ";
cin >> num;
modify_student(num);
Ayesha Naseer 22f-3672
break;
case '5':
system("cls");
SetConsoleTextAttribute(hConsole, 6);
Login page:
Main Menu:
Ayesha Naseer 22f-3672
Entry Menu:
Result Menu:
Ayesha Naseer 22f-3672
Class Report