You are on page 1of 12

//project made by jitin

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
int n=0,check=0;
struct date
{
int dd,mm,yy;
};

struct student
{
int roll;
float marks[3],total;
date dob;
char name[30];
};

student s[50];

void add(int);
void taker(int);
void taken(int);
void taked(int);
void takem(int);
void line();
void menu();
void print(int=-1);
void append();
void insert();
void ipos(int=-1);
void iroll();
void dlt();
void dpos(int=-1);
void droll();
void modify();
void sort();
void bsort();
void ssort();
void isort(int=-1);
int search(int=-1);
void query();
void exitm();

void main()

{line();
cout<<"\n\t\t\tproject on structures\n";
line();
line();
cout<<"\n\n\nyou need to enter the details of atleast 3 students"<<endl;

add(0);
add(1);
add(2);
check=1;
n=3;
menu();
}

void menu(void)
{
cout<<endl<<endl;
line();
cout<<"\n\t\t\t*welcome to the main menu*\n";
line();
int ch;
cout<<"\nwhat do you want to do?\n"
<<"1. add data"<<endl
<<"2. print" <<endl
<<"3. insert" <<endl
<<"4. delete" <<endl
<<"5. modify" <<endl
<<"6. sort" <<endl
<<"7. search" <<endl
<<"8. query" <<endl
<<"9. exit" <<endl;

cin>>ch;clreol();
cout<<"your choice:"<<ch<<endl<<endl;

switch(ch)
{
case 1:add(n); break;
case 2:print(); break;
case 3:insert(); break;
case 4:dlt(); break;
case 5:modify(); break;
case 6:sort(); break;
case 7:search(); break;
case 8:query(); break;
case 9:exitm(); break;
default:cout<<"\nwrong choice entered!\n\n";menu();

}
}
void add(int a)
{
s[a].total=0;
line();

taker(a);
taked(a);
taken(a);
takem(a);

cout<<"\ntotal marks are"<<"\t"<<s[a].total<<endl;


n++;
line();

if(check==7)
isort();
if(check==1)
menu();
}

void print(int a)
{
int i,x;
cout<<endl;
line();
line();
cout<<"roll no."<<setw(20)<<"date of birth"<<setw(20)<<"name"<<setw(20)<<"marks"
<<endl<<setw(75)<<"sub.1 sub.2 sub.3\n";
line();

if(a<0)
{x=n;i=0;}
else
{i=a;x=a+1;}
for(;i<x;i++)
cout<<setw(8)<<s[i].roll<<setw(12)<<s[i].dob.dd<<"|"<<s[i].dob.mm<<"|"<<s[i].dob.y
y<<setw(25)<<s[i].name<<setw(10)<<s[i].marks[0]<<" "<<s[i].marks[1]<<"
"<<s[i].marks[2]<<endl;
line();
menu();
}

void insert(void)
{
cout<<endl;
line();
cout<<"\t\t\tinsertion menu\n";
line();
cout<<"how do you want to insert?\n";
cout<<"1.position wise\n"
<<"2.roll no. wise\n"
<<"3.exit\n";

char ch;
ch=getch();
cout<<"your choice: "<<ch<<endl;

switch(ch)
{
case '1': ipos(); break;
case '2':iroll(); break;
case '3': menu(); break;
default :cout<<"\n\nwrong choice entered\n\n";getch();insert();
}
}

void ipos(int a)
{
cout<<endl<<endl;
line();
int pos;
if(a<0)
{cout<<"\nenter the position at which you want to insert the student\n";
cin>>pos;
if(pos>=n-1){cout<<"\nplease enter a valid position. you can only insert between
present positions\n";ipos(-9);}}
else
pos=a;
for(int i=n;i>pos;i--)
{
s[i]=s[i-1];
}
add(pos);

void iroll()
{check=7;
ipos(n);

void dlt(void)
{cout<<endl;
line();
cout<<"\t\t\tdeletion menu\n";
line();
cout<<"\nhow do you want to delete?\n";
cout<<"1.position wise\n"
<<"2.roll no. wise\n"
<<"3.exit\n";

char ch;
ch=getch();
cout<<"your choice: "<<ch<<endl;

switch(ch)
{
case '1': dpos(); break;
case '2':droll(); break;
case '3': menu(); break;
default :cout<<"\n\nwrong choice entered\n\n";dlt();
}
cout<<"\n";
line();
menu();

void dpos(int a)
{int pos;

if(a>0)
pos=a;
else
{
cout<<"\nenter the position at which you want to delete the student\n";
cin>>pos;
}

for(int i=pos;i<n-1;i++)
{
s[i]=s[i+1];
}
n--;
}

void droll()
{ int roll,pos;
cout<<"enter roll number";
cin>>roll;
pos=search(roll);
dpos(pos);
n--;
}
void modify(void)
{
cout<<endl;
line();
cout<<endl;
int roll,pos;
cout<<"enter the roll no. of the student whose details you want to modify\n";
cin>>roll;
pos=search(roll);

mod:
char ch;
cout<<"what do you want to modify?\n"
<<"1.roll no." <<endl
<<"2.date of birth" <<endl
<<"3.name" <<endl
<<"4.marks" <<endl
<<"exit" <<endl;
ch=getch();
cout<<"your choice: "<<ch<<endl;

switch(ch)
{
case '1':taker(pos); break;
case '2':taked(pos); break;
case '3':taken(pos); break;
case '4':takem(pos); break;
default :cout<<"\n\nwrong choice entered\n\n"; goto
mod;
}
menu();

void sort(void)
{line();
cout<<"\n\t\t\tsorting menu\n";
line();
cout<<"\nhow do you want to sort?\n"
<<"1.bubble sort\n"
<<"2.insertion sort\n"
<<"3.selection sort\n"
<<"4.exit";
char ch;
ch=getch();
cout<<"\nyour choice: "<<ch<<endl;

switch(ch)
{
case '1': bsort(); break;
case '2': isort(); break;
case '3': ssort(); break;
case '4': menu(); break;
default :cout<<"\n\nwrong choice entered\n\n";sort();

}
}

void bsort(void)
{
line();
student temp;

for(int i=0;i<n;i++)
{for(int j=0;j<n-i-1;j++)
if(s[j].roll>s[j+1].roll)
{temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
}
cout<<"the sorted list is being printed...\n";
print();

void ssort(void)
{
student small,temp;
int pos,i,j;

for(i=0;i<n;i++)

{
small.roll=s[i].roll;
pos=i;

for(j=i+1;j<n;j++)
{
if(s[j].roll<small.roll)
{
small.roll=s[j].roll;
pos=j;
}
}

temp=s[i];
s[i]=small;
s[pos]=temp;
}

/*

student temp;
int small,pos;

for(int i=0;i<n;i++)
{student small;

small.roll=s[i].roll;
pos=i;

for(int j=i+1;j<n;j++)
if(s[j].roll<small.roll)
{small.roll=s[j].roll;
pos=j;
}

temp=s[j];
s[j]=small;
s[pos]=temp;

}*/
cout<<"the sorted list is being printed...\n";
print();

void isort(int a)
{student temp;
char flag;
int i,j;
for(i=1;i<n;i++)
{ flag='t',j=i;

while((j>0)&&(flag=='t'))
{
if(s[j].roll<s[j-1].roll)
{ temp=s[j];
s[j]=s[j-1];
s[j-1]=temp;
j--;
}
else flag='f';
}

if(a==1)
search(-100);
else
//{ //if(a==-900)
//menu();
//else
{cout<<"\nthe new list is being printed...\n";
print();
}
} //}

int search(int a)
{

if((a)==(-100))
{goto back;}

isort(1);

back:

int roll;
if((a<0)&&(a!=-100))
{

cout<<"enter the roll number to be searched\t";


cin>>roll;
}
else
roll=a;

int l=0,h=5;
int m=(l+h)/2;

char flag;
while((h>=l)&&(flag=='t'))
if(s[m].roll==roll)
flag='f';
else
if(s[m].roll>roll)
h=m-1;
else
l=m+1;

if(flag=='t')

{cout<<"roll number not found. please try again."; getch();


if((a<0)&&(a!=-100))
search();
else
query();
}
else

if((a<0)&&(a!=-100))
{cout<<"roll number found at position "<<m<<endl;line(); menu();}
else
return m;

void query(void)
{
cout<<endl;
line();
cout<<"\t\t\tquery\n";
line();
int roll,pos;
cout<<"\nplease enter roll no.";
cin>>roll;

pos=search(roll);
cout<<"\nthe roll number was found at position"<<pos<<endl;
print(pos);

void taker(int x)
{
cout<<"\n\n\nplease enter the roll no. of the student\t";
cin>>s[x].roll;

}
void taken(int x)
{
cout<<"\nplease enter name"<<"\t";
gets(s[x].name);

void takem(int x)
{cout<<"\nplease enter marks in";
for(int i=0;i<3;i++)
{cout<<"\nsubject "<<i+1<<"\t";
cin>>s[x].marks[i];
s[x].total+=s[x].marks[i];
}
}

void taked(int x)
{
cout<<"\nplease enter date of birth\n";
cout<<"please enter the date,month and the year in the dd/mm/yy
format\n\n";

date:cout<<"please enter the date"<<"\t";


cin>>s[x].dob.dd;
if(s[x].dob.dd>31||s[x].dob.dd<0)
{cout<<"\nplease enter a proper date\n";goto date;}

month:cout<<"please enter the month"<<"\t";


cin>>s[x].dob.mm;
if(s[x].dob.mm>12||s[x].dob.mm<0)
{cout<<"\nplease enter a proper month\n";goto month;}

year:cout<<"please enter the year"<<"\t";


cin>>s[x].dob.yy;
if(s[x].dob.yy>99||s[x].dob.yy<0)
{cout<<"\nplease enter a proper year in yy format\n";goto year;}

void line(void)
{
for(int i=0;i<80;i++)
cout<<"_";
}

void exitm()
{
cout<<"\n\n";
line();
cout<<"\nthank you for using the program\nmade by jitin\n";
line();
exit(0);
}
//table fix, ssort fix, roll exisits ,exit option in diffrn menus, lines, headings
in menus,sorting 3 methods ?? append??

You might also like