//*********************************************************//
// STUDENT MANAGEMENT SYSTEM BY DHUSKA //
//*******************************************************//
#include<fstream.h>
#include<ctype.h>
#include<iomanip.h>
#include<conio.h>
#include<stdio.h>
class student
{
int studentid;
char firstname;
char lastname;
char address;
char city;
char state;
char country;
char course;
public:
void create_details(); //function to create student details
void show_student(); //fucntion to show data on screen
void modify(); //function to get new data from student
void report(); // Function to show data in tabular format
int retstudentid(); //function to return studentID
char retcourse(); //function to return course
}; //end of class
void student::create_details()
{
cout<<"\nEnter the studentID. ";
cin>>studentid;
cout<<"\nEnter the Student Firstname:";
cin>>firstname;
cout<<"\n\nEnter the student LastName: ";
cin>>lastname;
cout<<"\nEnter the student address: ";
cin>>address;
cout<<"\nEnter the City: ";
cin>>city;
cout<<"\nEnter the State: ";
cin>>state;
cout<<"\nEnter the Country: ";
cin>>country;
cout<<"\nEnter the Course: ";
cin>>course;
cout<<"\n\n\nStudent Details Created..";
}
void student::show_student()
{
cout<<"\nStudentId : "<<studentid;
cout<<"\firstName : "<<firstname;
cout<<"\lastName : "<<lastname;
cout<<"\address : "<<address;
cout<<"\city : "<<city;
cout<<"state : "<<state;
cout<<"country : "<<country;
cout<<"course : "<<course;
}
void student::modify()
{
cout<<"\nThe StudentID. "<<studentid;
cout<<"\n\nEnter the Student FirstName: ";
cin>>firstname;
cout<<"\n\nEnter the Student LastName: ";
cin>>lastname;
cout<<"\n\nEnter the student Address: ";
cin>>address;
cout<<"\n\nEnter the Student City: ";
cin>>city;
cout<<"\n\nEnter the Student State: ";
cin>>state;
cout<<"\n\nEnter the student Country: ";
cin>>country;
cout<<"\n\nEnter the Student Course: ";
cin>>course;
}
void student::report()
{
cout<<studentid<<setw(10)<<" "<<firstname<<setw(10)<<" "<<lastname<<setw(10)<<" "<<address<<setw(10)<<" "<<city<<setw(10)<<" "<<state<<setw(10)<<" "<<country<<setw(10)<<" "<<course<<endl;
void student::retstudentid()
{
return studentid;
}
char student::retcourse()
{
return course;
}
//******************************************************//
// FUNCTION DECLARATION //
//****************************************************//
int main()
{
char ch;
int id;
clrscr();
intro();
do
{
clrscr();
cout<<"\n\n\n\tMAIN MENU";
cout<<"\n\n\t01. NEW STUDENT";
cout<<"\n\n\t02. SEARCH FOR STUDENT";
cout<<"\n\n\t03. ALL STUDENT LISt";
cout<<"\n\n\t04. DELETE STUDENT";
cout<<"\n\n\t05. MODIFY STUDENT DETAILS";
cout<<"\n\n\t06. EXIT";
cout<<"\n\n\tSELECT YOUR OPTION (1-6) ";
cin>>ch
clrscr();
switch(ch)
{
case '1':
write_details();
break;
case '2':
cout<<"\n\n\tEnter the StudentID : ";cin>>id;
display_st(id);
break;
case '3':
display_all();
break;
case '4':
cout<<"\n\n\tEnter the StudentID : ";cin>>id;
delete_student(id);
break;
case '5':
cout<<"\n\n\tEnter the StudentID : ";cin>>id;
modify_details(id);
break;
case '6':
cout<<"\n\n\tThank you for using the student management system";
break;
default :cout<<"\a";
}
getch();
}while(ch!='6');
return 0;
}
//*******************************************************//
// FUNCTION TO WRITE TO FILE //
//*****************************************************//
void write_details()
{
student sid;
ofstream outFile;
outFile.open("student.dat",ios::binary|ios::app);
sid.create_details();
outFile.write((char *) &sid, sizeof(student));
outFile.close();
}
//***************************************************//
// FUNCTION TO READ SPECIFIC RECORD FROM FILE //
//***************************************************//
void display_st(int n)
{
student sid;
int flag=0;
instream inFile;
inFile.open("student.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be open !!! Press any key.....";
cout<<"\nStudent Details\n";
while(inFile.read((char *) &sid, sizeof(student)))
{
if(sid.show_student()==n)
{
sid.show_student();
flag=1;
}
}
inFile.close();
if(flag==0)
cout<<"\n\nStudent Details does not exist";
}
//*************************************************//
// FUNCTION TO MODIFY RECORD OF FILE
//************************************************//
void modify_details(int n)
{
int found=0;
student sid;
fstream File;
File.open("student.dat",ios::binary|ios::in|ios::out);
if(!File)
{
cout<<"File could not be open!! Press any Key....";
return;
}
while(File.read((char *) &sid, sizeof(student)) && found==0)
{
if(sid.retstudentid()==n)
{
sid.show_details();
cout<<"\n\nnEnter the New Student Details"<<endl;
sid.modify();
int pos=(-1)*sizeof(student);
File.seekp(pos,ios::cur);
File.write((char *) &sid, sizeof(student));
cout<<"\n\n\t Record Updated!";
found=1;
}
}
File.close();
if(found==0)
cout<<"\n\n Record Not Found! ";
}
//*************************************************//
// FUNCTION TO DELETE RECORD
//************************************************//
void delete_student(int n)
{
student sid;
ifstream inFile;
ofstream outFile;
inFile.open("student.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be found!! Press any Key....";
return;
}
outFile.open("Temp.dat"ios::binary);
inFile.seekg(0,ios::beg);
while(inFile.read((char *) &sid, sizeof(student)))
{
if(sid.retstudentid()!=n)
{
outFile.write((char *) &sid, sizeof(student));
}
}
inFile.close();
outFile.close();
remove("student.dat");
rename("Temp.dat","student.dat");
cout<<"\n\n\tRecord Deleted!...";
}
//*************************************************//
// FUNCTION TO DISPLAY ALL STUDENTS
//************************************************//
void display_all()
{
student sid;
ifstream inFile;
inFile.open("student.dat",ios::binary);
{
cout<<"File could not be open!! Press any Key....";
return;
}
cout<<"\n\n\t\tREGISTERED STUDENT LIST\n\n";
cout<<"================================================================================\n";
cout<<"STUDENTID FIRSTNAME LASTNAME ADDRESS CITY STATE COUNTRY COURSE"
cout<<"==================================================================================\n";
while(inFile.read((char *) &sid,sizeof(student)))
{
sid.report();
}
inFile.close();
}
void intro()
{
cout<<"\n\n\n\t STUDENT";
cout<<"\n\n\tMANAGEMENT";
cout<<"\n\n\t SYSTEM";
cout<<"\n\n\n\nMADE BY : DHUSKA";
cout<<"\n\nSCHOOL: NIIT";
getch();
}
//********************************************//
// END OF PROJECT //
//*******************************************//
*** Edit ***
Please use code tags when posting code
PLEASE HELP ME CORRECT IT
This post has been edited by GunnerInc: 14 July 2012 - 03:20 PM
Reason for edit:: Added code tags

New Topic/Question
Reply



MultiQuote









|