0% found this document useful (0 votes)
15 views9 pages

Microp

My microproject

Uploaded by

khaparderahil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views9 pages

Microp

My microproject

Uploaded by

khaparderahil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

#include<iostream.

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);
}

cout << "\nID\tName\t\tAge\tCourse\t\tStatus\n";

while (!file.eof())
{
file.read((char*)&s, sizeof(s));
if(!file.eof())
s.putdata();

file.close();
}

void modifystudent(int id)


{
student s;
fstream file;
file.open("student.dat", ios::in | ios::out | ios::binary);

if (file.fail())
{
cout << "Error opening file for reading and writing.\n";
exit(0);
}

int found = 0;

while (file.read((char*)&s, sizeof(s)))


{
if (s.s_id == id)
{
cout << "Enter new details for Student ID " << id << ":\n";
s.getdata();
file.seekp(file.tellg() - sizeof(s));
file.write((char*)&s, sizeof(s));
found = 1;
break;
}
}

if (found)
{
cout << "Student registration is successfully modified.\n";
}
else
{
cout << "Student with ID " << id << " not found.\n";
}

file.close();
}

void updatepaymentstatus(int id)


{
student s;
fstream file;
file.open("student.dat", ios::binary | ios::in | ios::out);

if (file.fail())
{
cout << "Error opening file for reading and writing.\n";
exit(0);
}

int found = 0;

while (file.read((char*)&s, sizeof(s)))


{
if (s.s_id == id)
{
cout << "Update payment status of Student ID " << id << "
(1 for Paid or 0 for Not Paid): ";
cin >> s.pay_sta;
file.seekp(file.tellg() - sizeof(s));
file.write((char*)&s, sizeof(s));
found = 1;
break;
}
}

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();

 }

You might also like