Microp
Microp
h>
#include<conio.h>
#include<string.h>
#include<fstream.h>
#include<stdlib.h>
class person
{
public:
int age;
char name[30];
void getdata()
{
cout << "Enter the name of student: ";
cin >> name;
cout << "Enter the age: ";
cin >> age;
}
void putdata()
{
cout << "\t" << name << "\t" << age;
}
};
class student: public person
{
public:
int s_id, pay_sta;
char course[30];
void getdata()
{
cout << "Enter the Student ID: ";
cin >> s_id;
person::getdata();
cout << "Enter the course: ";
cin >> course;
cout << "Payment Status(1 for Paid or 0 for Not Paid): ";
cin >> pay_sta;
}
void putdata()
{
cout << "\nID: " << s_id;
person::putdata();
cout << "\t" << course << "\t" << (pay_sta ? "Paid" : "Not
Paid");
}
};
void addstudent()
{
student s;
fstream file;
file.open("student.dat", ios::app | ios::binary);
if (file.fail())
{
cout << "Error opening file for writing.\n";
exit(0);
}
s.getdata();
file.write((char*)&s, sizeof(s));
file.close();
cout << "Student registration is successful!\n";
}
void displaystudent()
{
student s;
fstream file;
file.open("student.dat", ios::in | ios::binary);
if (file.fail())
{
cout << "No student data found.\n";
exit(0);
}
while (!file.eof())
{
file.read((char*)&s, sizeof(s));
if(!file.eof())
s.putdata();
file.close();
}
if (file.fail())
{
cout << "Error opening file for reading and writing.\n";
exit(0);
}
int found = 0;
if (found)
{
cout << "Student registration is successfully modified.\n";
}
else
{
cout << "Student with ID " << id << " not found.\n";
}
file.close();
}
if (file.fail())
{
cout << "Error opening file for reading and writing.\n";
exit(0);
}
int found = 0;
if (found)
{
cout << "Payment status is successfully updated!\n";
}
else
{
cout << "Student with ID " << id << " not found.\n";
}
file.close();
}
void main()
{
clrscr();
int choice, id;
do
{
cout << "\n====Course Registration System====\n";
cout << "1. Add Student\n";
cout << "2. Display all Students\n";
cout << "3. Modify Student Details\n";
cout << "4. Update Payment Status\n";
cout << "5. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice)
{
case 1:
addstudent();
break;
case 2:
displaystudent();
break;
case 3:
cout << "Enter the Student ID to modify: ";
cin >> id;
modifystudent(id);
break;
case 4:
cout << "Enter the Student ID to update payment status: ";
cin >> id;
updatepaymentstatus(id);
break;
case 5:
cout << "Exiting...\n";
break;
default:
cout << "Invalid choice! Please try again.\n";
}
} while (choice != 5);
getch();
}