#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
class student
{
protected:
int rollno;
char name[20];
public:
void getstudent()
{
cout << "\n\nEnter Roll no. : ";
cin >> rollno;
cin.ignore();
cout << "Enter name : ";
cin.getline(name, 20);
}
void displaystudent()
{
cin.ignore();
cout << "\nNAME : " << name;
cout << "\nRoll no. : " << rollno;
}
int ret()
{
return rollno;
}
};
class section : public student
{
private:
char sname[10];
public:
void create()
{
getstudent();
cin.ignore();
cout << "\nEnter Section Name : ";
cin.getline(sname, 10);
}
void display()
{
displaystudent();
cout << "\nSECTION : " << sname;
}
};
class staff
{
protected:
int id;
char name[20];
public:
void getstaff()
{
cout << "\n\nEnter unique id : ";
cin >> id;
cin.ignore();
cout << "Enter name : ";
cin.getline(name, 20);
}
void dispstaff()
{
cout << "\nNAME : " << name;
cout << "\nID : " << id;
}
int ret()
{
return id;
}
};
class teacher : public staff
{
char sub[20];
public:
void create()
{
getstaff();
cout << "\nEnter Subject : ";
cin.getline(sub, 20);
}
void display()
{
dispstaff();
cout << "\nSUBJECT : " << sub;
}
};
class result : public student
{
int eng;
int maths;
int science;
int urdu;
int sstudies;
int islamiyat;
double percentage;
double a;
int r;
public:
void getresult(int x)
{
cout << "Enter marks in Enlish : ";
cin >> eng;
cout << "\nEnter marks in Maths : ";
cin >> maths;
cout << "\nEnter marks in Science : ";
cin >> science;
cout << "\nEnter marks in Urdu : ";
cin >> urdu;
cout << "\nEnter marks in Social Studies : ";
cin >> sstudies;
cout << "\nEnter marks in islamiyat (out of 50) : ";
cin >> islamiyat;
a = (eng + maths + science + urdu + sstudies + islamiyat) ;
percentage = (a/550)*100;
r = x;
}
void dispresult()
{
cout << "==========================================" << endl;
cout << " Result of student with Roll number : ";
cout << r;
cout << "\n\nMarks in English : ";
cout << eng;
cout << "\nMarks in Maths : ";
cout << maths;
cout << "\nMarks in Science : ";
cout << science;
cout << "\nMarks in Urdu : ";
cout << urdu;
cout << "\nMarks in sstudies : ";
cout << sstudies;
cout << "\nMarks in Islamiyat : ";
cout << islamiyat;
cout << "\nPercentage : " << percentage << " %" << endl;
};
void writeStudent();
void writeResult(int n);
void readStudent();
void writeStaff();
void readStaff();
void writeStudent()
{
section s;
ofstream outFile;
outFile.open("student.dat", ios::out | ios::binary | ios::app);
s.create();
outFile.write(reinterpret_cast <char *> (&s), sizeof(section));
outFile.close();
cout << "\n\n\t\tRecord Has Been Saved !!!\a\n ";
cin.ignore();
cin.get();
void writeResult(int n)
{
section s;
result r;
ofstream outFile;
ifstream inFile;
bool flag = false;
inFile.open("student.dat", ios::in | ios::app);
if (!inFile.is_open())
{
cout << "Error opening the file";
cin.ignore();
cin.get();
return;
}
else
{
outFile.open("result.dat", ios::out | ios::app | ios::binary);
inFile.read(reinterpret_cast<char *>(&s), sizeof(section));
while (!inFile.eof())
{
if (n == s.ret())
{
r.getresult(n);
outFile.write(reinterpret_cast<char *> (&r),
sizeof(result));
flag = true;
inFile.read(reinterpret_cast<char *>(&s), sizeof(section));
}
outFile.close();
inFile.close();
if (flag == false)
{
cout << "Sorry the roll no you entered does not exist :( ";
cout << "\n\n\t\tRecord Has Been Saved !!!\a\n ";
cin.ignore();
cin.get();
void readResult()
{
result r;
ifstream inFile;
inFile.open("result.dat", ios::in | ios::app);
if (!inFile.is_open())
{
cout << "error opening the file";
cin.ignore();
cin.get();
return;
}
else
{
inFile.read(reinterpret_cast<char *>(&r), sizeof(result));
while (!inFile.eof())
{
r.dispresult();
inFile.read(reinterpret_cast<char *>(&r), sizeof(result));
}
inFile.close();
cin.ignore();
cin.get();
}
}
void readStudent()
{
section s;
ifstream inFile;
inFile.open("student.dat", ios::in | ios::app);
if (!inFile.is_open())
{
cout << "Eror opening the file";
cin.ignore();
cin.get();
return;
}
else
{
inFile.read(reinterpret_cast<char *> (&s), sizeof(section));
while (!inFile.eof())
{
s.display();
inFile.read(reinterpret_cast<char *> (&s), sizeof(section));
}
}
inFile.close();
cin.ignore();
cin.get();
}
void writeStaff()
{
teacher t;
ofstream outFile;
outFile.open("Staff.dat", ios::out | ios::app | ios::binary);
t.create();
outFile.write(reinterpret_cast<char *> (&t), sizeof(teacher));
outFile.close();
cin.ignore();
cin.get();
void readStaff()
{
teacher t;
ifstream inFile;
inFile.open("staff.dat", ios::in | ios::app);
if (!inFile.is_open())
{
cout << "Error opening the file !";
cin.ignore();
cin.get();
}
else
{
inFile.read(reinterpret_cast<char *> (&t), sizeof(teacher));
while (!inFile.eof())
{
t.display();
inFile.read(reinterpret_cast<char *> (&t), sizeof(teacher));
}
inFile.close();
cin.ignore();
cin.get();
}
}
void Result_menu()
{
char ch2;
system("cls");
cout << "\n\n\n\t\t****************************************************** ";
cout << "\n\t\t* * ";
cout << "\n\t\t* * ";
cout << "\n\t\t* Student Report Menu * ";
cout << "\n\t\t* * ";
cout << "\n\t\t* * ";
cout << "\n\t\t* 1 - View results . * ";
cout << "\n\t\t* 2 - Create result . * ";
cout << "\n\t\t* 3 - Back to Main Menu . * ";
cout << "\n\t\t* * ";
cout << "\n\t\t* Select Your Option . * ";
cout << "\n\t\t* * ";
cout << "\n\t\t* * ";
cout << "\n\t\t****************************************************** ";
cin >> ch2;
switch (ch2)
{
case '1':
{
system("cls");
readResult();
break;
}
case '2':
{
system("cls");
cout << "Enter the Roll no. of student whom result you want to enter .
";
int x;
cin >> x;
writeResult(x);
break;
}
case '3':
{
break;
}
default:
{
cout << "\a";
Result_menu();
}
}
}
void student_menu()
{
char ch2;
system("cls");
cout << "\n\n\n\t\t****************************************************** ";
cout << "\n\t\t* * ";
cout << "\n\t\t* * ";
cout << "\n\t\t* Student info Menu * ";
cout << "\n\t\t* * ";
cout << "\n\t\t* * ";
cout << "\n\t\t* 1 - View List of Students . * ";
cout << "\n\t\t* 2 - Enter new Student . * ";
cout << "\n\t\t* 3 - Back to Main Menu . * ";
cout << "\n\t\t* * ";
cout << "\n\t\t* Select Your Option . * ";
cout << "\n\t\t* * ";
cout << "\n\t\t* * ";
cout << "\n\t\t****************************************************** ";
cin >> ch2;
switch (ch2)
{
case '1':
{
system("cls");
readStudent();
break;
}
case '2':
{
system("cls");
writeStudent();
break;
}
case '3':
{
break;
}
default:
{
cout << "\a";
student_menu();
}
}
}
void staff_menu()
{
char ch2;
system("cls");
cout << "\n\n\n\t\t****************************************************** ";
cout << "\n\t\t* * ";
cout << "\n\t\t* * ";
cout << "\n\t\t* Teacher info Menu * ";
cout << "\n\t\t* * ";
cout << "\n\t\t* * ";
cout << "\n\t\t* 1 - View List of staff . * ";
cout << "\n\t\t* 2 - Enter new member . * ";
cout << "\n\t\t* 3 - Back to Main Menu . * ";
cout << "\n\t\t* * ";
cout << "\n\t\t* Select Your Option . * ";
cout << "\n\t\t* * ";
cout << "\n\t\t* * ";
cout << "\n\t\t****************************************************** ";
cin >> ch2;
switch (ch2)
{
case '1':
{
system("cls");
readStaff();
break;
}
case '2':
{
system("cls");
writeStaff();
break;
}
case '3':
{
break;
}
default:
{
cout << "\a";
staff_menu();
}
}
}
int main_menu()
{
char ch;
do
{
system("cls");
cout << endl << endl;
cout <<
"\n\n\n\t\t******************************************************** ";
cout << "\n\t\t* *
";
cout << "\n\t\t* *
";
cout << "\n\t\t* Main Menu *
";
cout << "\n\t\t* *
";
cout << "\n\t\t* *
";
cout << "\n\t\t* 1 - Student Entry/Info . *
";
cout << "\n\t\t* 2 - Student Report System . *
";
cout << "\n\t\t* 3 - Teacher Info/Entry . *
";
cout << "\n\t\t* 4 - Exit . *
";
cout << "\n\t\t* *
";
cout << "\n\t\t* *
";
cout << "\n\t\t* Select Your Option . *
";
cout << "\n\t\t* *
";
cout << "\n\t\t* *
";
cout << "\n\t\t********************************************************
";
cin >> ch;
switch (ch)
{
case '1':
{
system("cls");
student_menu();
break;
}
case '2':
{
system("cls");
Result_menu();
break;
}
case '3':
{
system("cls");
staff_menu();
break;
}
case '4':
{
system("cls");
cout << "\n\n\t\tThankx for using this Program \n\n ";
cin.get();
return 0;
}
default:
{
cout << "\a";
main_menu();
}
}
} while (ch != '4');
return 1;
}
int main()
{
main_menu();
return 0;