You are on page 1of 18

MUHAMMAD HAMZA MALIK (BEE163074)

FAREED-UD-DIN HAIDER (BEE163051)

MUHAMMAD FAIZAN (BEE163116)

Section # S1

PROJECT:

DATABASE MANAGEMENT SYSTEM

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

struct node

string first_name, last_name, course, reg, department, message,fees;

int section;

node *next, *previous;

};

class list
{

node *head,*last;

public:

list()

head=NULL;

last=NULL;

void create_node(string _first_name,string _last_name, string _course, string _reg,string


_department,int _section,string _fees,string _message="-->Above_student's_data_complete")

node *temp=new node;

temp->first_name=_first_name;

temp->last_name=_last_name;

temp->course=_course;

temp->reg=_reg;

temp->department=_department;

temp->section=_section;

temp->fees=_fees;

temp->message=_message;

temp->next=NULL;

temp->previous=NULL;

if(head==NULL)
{

head=temp;

last=temp;

else

last->next=temp;

temp->previous=last;

last=last->next;

void display()

node *temp=head;

if(head==NULL)

cout<<"\n\t\tList is Empty\n"<<endl;

else

cout<<"\t\t\t*****|Arrangment of DATA is like|*****\n\n|NAMES|-|


SURNAMES|-|COURSES|-|REGISTRATIONS|-|DEPARTMENTS|-|SECTIONS|-|FEES|"<<endl<<endl;

while(temp!=NULL)

cout<<"|"<<temp->first_name<<"|\n";
cout<<"|"<<temp->last_name<<"|\n";

cout<<"|"<<temp->course<<"|\n";

cout<<"|"<<temp->reg<<"|\n";

cout<<"|"<<temp->department<<"|\n";

cout<<"|"<<temp->section<<"|\n";

cout<<"|"<<temp->fees<<"|\n";

cout<<"|"<<temp->message<<"|\n";

temp=temp->next;

void delete_student()

node *current=search_position();

if(current==NULL)

if(head==NULL)

cout<<"List is Empty"<<endl;

else

{
cout<<"Student not Found"<<endl;

else if(current==head && current==last)

delete current;

head=NULL;

last=NULL;

else if(current==head)

head=head->next;

head->previous=NULL;

delete current;

else if(current==last)

last=last->previous;

last->next=NULL;

delete current;

else

current->previous->next=current->next;

current->next->previous=current->previous;
delete current;

cout<<"\nSTUDENT deleted\n"<<endl;

node* search_position()

string student_to_delete;

cout<<"\nEnter Registration of student \n";

cin>> student_to_delete;

node *temp=head;

while(temp!=NULL)

if(temp->reg == student_to_delete)

cout <<"Student Found\n";

return temp;

else

temp=temp->next;

}
return temp;

void editing()

node *current=search_position();

if(current==NULL)

if(head==NULL)

cout<<"List is Empty"<<endl;

else

cout<<"Student not Found"<<endl;

char choice;

do

system("cls");

cout<<"\t\t\tCHOICES\n"<<endl;

cout<<"\t\t\t--> F for FIRST NAME"<<endl;

cout<<"\t\t\t--> L for LAST NAME"<<endl;


cout<<"\t\t\t--> C for COURSES"<<endl;

cout<<"\t\t\t--> R for REGISTRATION Number"<<endl;

cout<<"\t\t\t--> D for DEPARTMENT"<<endl;

cout<<"\t\t\t--> S for SECTION"<<endl;

cout<<"\t\t\t--> X for CHANGING FEES"<<endl;

cout<<"\t\t\t--> E tp EXIT"<<endl;

char editing_choice;

cout<<"\nWhat do you want to modify.Select your option\n"<<endl;

cin>>editing_choice;

system("cls");

switch(editing_choice)

case 'F':

string new_name;

cout<<"\nEnter changed First Name of student "<<endl;

cin>>new_name;

current->first_name=new_name;

cout<<"\nSuccessfully Changed\n"<<endl;

break;

case 'L':

{
string l_name;

cout<<"\nEnter changed Last Name of student "<<endl;

cin>>l_name;

current->last_name=l_name;

cout<<"\nSuccessfully Changed\n"<<endl;

break;

case 'C':

string new_courses;

cout<<"\nEnter changed Courses of student "<<endl;

cin>>new_courses;

current->course=new_courses;

cout<<"\nSuccessfully Changed\n"<<endl;

break;

case 'R':

string new_Reg;

cout<<"\nEnter changed Registration of student "<<endl;

cin>>new_Reg;

current->reg=new_Reg;

cout<<"\nSuccessfully Changed\n"<<endl;

break;
}

case 'D':

string new_department;

cout<<"\nEnter changed Department of student "<<endl;

cin>>new_department;

current->department=new_department;

cout<<"\nSuccessfully Changed\n"<<endl;

break;

case 'S':

int new_sec;

cout<<"\nEnter changed Section of student "<<endl;

cin>>new_sec;

current->section=new_sec;

cout<<"\nSuccessfully Changed\n"<<endl;

break;

case 'X':

string new_fee;

cout<<"\nEnter changed FEES of student "<<endl;

cin>>new_fee;

current->fees=new_fee;
cout<<"\nSuccessfully Changed\n"<<endl;

break;

case 'E':

break;

cout<<"\nDo you want to go the Modify Menu-->Press('Y' or 'y') \n"<<endl;

cin>>choice;

}while((choice=='y'||choice=='Y'));

void search()

string student_to_search;

cout<<"\nEnter Registration of student \n";

cin>> student_to_search;

node *temp=head;

while(temp!=NULL)

if(temp->reg == student_to_search)
{

cout <<"Student Found\n";

break;

else

temp=temp->next;

void save()

ofstream file("D:\\student_management_system.txt");

node* temp=head;

node* temp2=NULL;

while(temp!=NULL)

file<<temp->first_name <<"\n";

file<<temp->last_name <<"\n";

file<<temp->course <<"\n";

file<<temp->reg <<"\n";

file<<temp->department <<"\n";

file<<temp->section <<"\n";
file<<temp->fees <<"\n";

file<<temp->message <<"\n";

temp2=temp;

temp=temp->next;

delete temp2;

file.close();

void load()

ifstream file("D:\\student_management_system.txt");

if(!file)

cout<<"\nEmpty\n"<<endl;

else

while(!file.eof())

string fn;

file>>fn;

string ln;

file>>ln;
string cr;

file>>cr;

string rg;

file>>rg;

string dp;

file>>dp;

int sec;

file>>sec;

string f;

file>>f;

string msg;

file>>msg;

create_node(fn,ln,cr,rg,dp,sec,f,msg);

node*current=head;

node*pcurrent=current;

while(current->next!=NULL)

pcurrent=current;

current=current->next;

last=pcurrent;

pcurrent->next=NULL;
delete current;

};

int main()

list obj;

obj.load();

int choice;

char selection;

do

system("cls");

cout<<"\t\t\t******************************"<<endl<<endl;

cout<<"\t\t ******|STUDENT DATA BASE SYSTEM|******\n"<<endl;

cout<<"\t\t\t******************************"<<endl<<endl;

cout<<"\t\t\tPress 1 to add a new student"<<endl;

cout<<"\t\t\tPress 2 to delete a student"<<endl;

cout<<"\t\t\tPress 3 to search a student"<<endl;

cout<<"\t\t\tPress 4 to modify the database"<<endl;

cout<<"\t\t\tPress 5 to display database"<<endl;


cout<<"\nEnter your choice<---\n"<<endl;

cin>>choice;

system("cls");

switch(choice)

case 1:

string fname,lname,course,reg,department,fees;

int section ;

cout<<"Enter First Name"<<endl;

cin>>fname ;

cout<<"Enter Last Name"<<endl;

cin>>lname ;

cout<<"Enter Courses "<<endl;

cin>>course ;

cout<<"Enter Registraton Number"<<endl;

cin>>reg ;

cout<<"Enter Department"<<endl;

cin>>department ;

cout<<"Enter Section"<<endl;

cin>>section ;

cout<<"Enter Fees"<<endl;

cin>>fees ;

system("cls");

obj.create_node(fname,lname,course,reg,department,section,fees);
obj.display();

break;

case 2:

obj.delete_student();

obj.display();

break;

case 3:

obj.search();

break;

case 4:

obj.editing();

cout<<endl;

obj.display();

break;

case 5:

obj.display();

break;
}

cout<<"\n\nDo you want to Continue\t--->Press (y or Y)\n\nPress any other key to


exit\n"<<endl;

cin>>selection;

}while((selection=='y')||(selection=='Y'));

obj.save();

You might also like