#include <iostream>
using namespace std;
#include <fstream>
struct student
{
char name[40];
int id;
};
int main ()
{
int menu;
student std;
do
{
cout << "\n ========================================" << endl;
cout << " Welcome To Student Record Program " << endl;
cout << " ========================================" << endl;
cout << "\n 1. Show A Student Info " << endl;
cout << " 2. Insert A New Student Record " << endl;
cout << " 3. Exit Program " << endl;
cout << "\n Enter Your Choice : ";
cin >> menu;
cin.ignore(80,'\n');
if (menu <1 || menu >3) cout << "\n Please Enter The Correct Choice" <<endl;
else if (menu == 1)
{
ifstream stdfile("student", ios::in | ios::binary);
if (stdfile.is_open())
{
cout << "\n\n ========================================"<<endl;
cout << " The Student Record "<< endl;
cout << " ========================================\n"<<endl;
while (!stdfile.eof())
{
stdfile.read((char*)(&std), sizeof(student));
cout << " " << std.id << "\t" << std.name << endl;
}
stdfile.close();
}
else
{
cout << "\n\n ========================================"<<endl;
cout << " No Data Record "<< endl;
cout << " ========================================\n"<<endl;
}
system("PAUSE");
}
else if (menu == 2)
{ cout << "\n\n ========================================"<<endl;
cout << " Enter A New Student Record "<< endl;
cout << " ========================================\n"<<endl;
cout << " Enter Student ID number: ";
(cin >> std.id).get();
cout << " Enter Student Name: ";
cin.getline(std.name,40);
ofstream rstdfile("student", ios::out | ios::app | ios::binary);
rstdfile.write((char*)(&std), sizeof(student));
rstdfile.close();
}
} while (menu != 3);
system("PAUSE");
return 0;
}
========================================
The Student Record
========================================
123 abc
456 def
789 ghi
789 ghi
Press any key to continue . . .