Skip to content

Instantly share code, notes, and snippets.

@mentix02
Created May 31, 2018 03:32
Show Gist options
  • Save mentix02/371a2f48a8289a0d173f8f4404b14db7 to your computer and use it in GitHub Desktop.
Save mentix02/371a2f48a8289a0d173f8f4404b14db7 to your computer and use it in GitHub Desktop.
hosting for a friend
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
struct date
{
int dd,mm,yy;
};
struct std_info
{
char nm[100];
date dob;
int age,grade;
char gender[10];
char stream[10];
};
struct cls
{
std_info stud[30];
};
class Student
{
private:
void details(cls,int);
public:
void display(cls,int);
void srch(cls,int,char);
void srch(cls,char,int);
void edit_rec(cls&,int);
void add_data(cls&,int&,int);
void del_data(cls&,int&);
};
void details(cls s,int i)
{
cout<<"\nName: "<<s.stud[i].nm;
cout<<"\nGrade: "<<s.stud[i].grade;
cout<<"\nStream: "<<s.stud[i].stream;
cout<<"\nAge: "<<s.stud[i].age;
cout<<"\nDate of Birth: "<<s.stud[i].dob.mm<<'/'<<s.stud[i].dob.dd<<'/'<<s.stud[i].dob.yy;
cout<<"\nSex: "<<s.stud[i].gender;
cout<<endl;
}
void display(cls s,int n)
{
cout<<"\nS.No. Name\t\tGrade\tStream\t\tAge\tDOB\t\tSex\n";
for(int i=0;i<n;i++)
{
cout<<(i+1)<<" "<<s.stud[i].nm<<'\t'<<s.stud[i].grade<<'\t'<<s.stud[i].stream<<"\t\t"<<s.stud[i].age<<'\t'<<s.stud[i].dob.mm<<'/'<<s.stud[i].dob.dd<<'/'<<s.stud[i].dob.yy<<'\t'<<s.stud[i].gender<<endl;
for(long int j=0;j<800;j+=1){for(long int k=0;k<10000;k++){}}
}
}
void srch(cls s,int n,char nm_l[])
{
int f,chk,i;
char *c,*ch;
re:cout<<"\nSearch Successful. Details are:";
for(f=0,i=0;i<n;i++)
{
c=strstr(s.stud[i].nm,nm_l);
chk=memicmp(nm_l,c,strlen(nm_l));
if(chk==0)
{
for(long int j=0;j<600;j++){for(long int k=0;k<10000;k++){;}}
f=1;
details(s,i);
}
}
if(f==0)
{
cout<<"\rName Search Unsuccessful.\t\n";
ask:cout<<"\nWould you want to search for another student? ";
strupr(gets(ch));
if(stricmp(ch,"Yes")==0)
{
cout<<"\nEnter the students name that you wish to search: ";
strupr(gets(nm_l));
goto re;
}
else
{
delete ch;
delete c;
}
}
else goto ask;
}
void srch(cls s,char strm[],int n)
{
int f=0;
cout<<"Search Successful. Details are:";
for(int i=0;i<n;i++)
{
int c=strcmp(s.stud[i].stream,strm);
if(c==0)
{
for(long int j=0;j<800;j++){for(long int k=0;k<10000;k++){;}}
f=1;
details(s,i);
}
}
if(f==0)
cout<<"\rStream Search Unsuccessful.\t\n";
}
void edit_rec(cls &s,int n)
{
char *c;
char ch[]={"YES"};
char *nm_l=new char[30];
int flag,chc;
edit_new:cout<<"\nPlease enter the name for which data is to be edited: ";
strupr(gets(nm_l));
flag=-1;
for(int i=0;i<n;i++)
{
c=strstr(s.stud[i].nm,nm_l);
if(memicmp(nm_l,c,strlen(nm_l))==0)
{
details(s,i);
cout<<"Is this the student for which data has to be edited? ";
strupr(gets(ch));
if(stricmp(ch,"Yes")==0)
{
flag=1;
cout<<"\nDetails are:-";
details(s,i);
cout<<"\nWhat do you want to change? ";
ch_ag:cout<<"\n1. Name";
cout<<"\n2. Grade";
cout<<"\n3. Stream";
cout<<"\n4. Age";
cout<<"\n5. DOB";
cout<<"\n6. Sex\n";
cout<<"\nChoose one: ";
cin>>chc;
if(chc==1)
{
cout<<"\nEnter New Name: ";
strupr(gets(s.stud[i].nm));
}
if(chc==2)
{
cout<<"\nEnter New Grade: ";
cin>>s.stud[i].grade;
}
if(chc==3)
{
cout<<"\nEnter New Stream: ";
strupr(gets(s.stud[i].stream));
}
if(chc==4)
{
cout<<"\nEnter New Age: ";
cin>>s.stud[i].age;
}
if(chc==5)
{
cout<<"\nEnter New Date of Birth(MM/DD/YYYY): ";
cin>>s.stud[i].dob.mm>>s.stud[i].dob.dd>>s.stud[i].dob.yy;
}
if(chc==6)
{
cout<<"\nEnter New Sex: ";
strupr(gets(s.stud[i].gender));
}
cout<<"\nThe updated information is:";
details(s,i);
cout<<"\nDo you want to edit any other information? ";
gets(ch);
if(stricmp(ch,"Yes")==0)
goto ch_ag;
cout<<"\nDo you want to edit any other students information? ";
gets(ch);
if(stricmp(ch,"Yes")==0)
goto edit_new;
else break;
}
else if(stricmp(ch,"NO"))
continue;
}
}
if(flag==-1) goto rerun;
rerun:if(flag==-1)
{
cout<<"Student not found. Do you want to edit data for another student? ";
strupr(gets(ch));
if(stricmp(ch,"Yes")==0)
{
goto edit_new;
}
}
}
void add_data(cls &s,int &n,int ch=0)
{
char *chc;
int i;
if(ch==1)
for(i=0;i<n;i++)
{
add:cout<<"\nEnter Details:-";
cout<<"\nEnter Name: ";
strupr(gets(s.stud[i].nm));
cout<<"Enter Grade: ";
cin>>s.stud[i].grade;
cout<<"Enter Stream: ";
strupr(gets(s.stud[i].stream));
cout<<"Enter Age: ";
cin>>s.stud[i].age;
cout<<"Enter Date of Birth(MM/DD/YYYY): ";
cin>>s.stud[i].dob.mm>>s.stud[i].dob.dd>>s.stud[i].dob.yy;
cout<<"Enter Sex: ";
strupr(gets(s.stud[i].gender));
if(ch==0) break;
}
else
{
run:n++;
i=n-1;
goto add;
}
if(ch==0)
{
cout<<"\nWould you wish to add any more students? ";
strupr(gets(chc));
if(stricmp(chc,"Yes")==0) goto run;
}
}
void del_data(cls &s,int &n)
{
char *c,y_n[5];
char *nm_l=new char[30];
int flag,i,j,chk,chc;
cout<<"\nEnter a name for which data has to be deleted: ";
strupr(gets(nm_l));
for(i=0;i<n;i++)
{
c=strstr(s.stud[i].nm,nm_l);
chk=memicmp(nm_l,c,strlen(nm_l));
if(chk==0)
{
details(s,i);
cout<<"\nIs this the student for which data has to be deleted? ";
gets(y_n);
chc=stricmp(y_n,"YES");
if(chc==0)
{
flag=1;
for(j=i;j<n;j++)
{
if(j==(n-1))
{
n--;
}
else
{
strcpy(s.stud[j].nm,s.stud[j+1].nm);
s.stud[j].grade=s.stud[j+1].grade;
strcpy(s.stud[j].stream,s.stud[j+1].stream);
s.stud[j].age=s.stud[j+1].age;
s.stud[j].dob.dd=s.stud[j+1].dob.dd;
s.stud[j].dob.mm=s.stud[j+1].dob.mm;
s.stud[j].dob.yy=s.stud[j+1].dob.yy;
strcpy(s.stud[j].gender,s.stud[j+1].gender);
}
}
cout<<"\nDo you want to delete data for any other person? ";
strupr(gets(y_n));
if(stricmp(y_n,"Yes")==0) goto del_new;
else break;
}
else
continue;
}
}
if(flag==-1) goto rerun;
rerun:if(flag==-1)
{
cout<<"\nName not found. Do you want to delete data for some other name?";
strupr(gets(y_n));
del_new:if(stricmp(y_n,"Yes")==0)
{
cout<<"\nEnter another name for which data is to be deleted: ";
strupr(gets(nm_l));
}
}
}
void main()
{
clrscr();
cls s;
char c[]={"YES"};
int a=0,f=0,n,ch,chc;
cout<<"Enter number of students: ";
cin>>n;
add_data(s,n,chc=1);
do
{
if(f==0)
{
cout<<"\nChoose one:";
cout<<"\n1. Display all";
cout<<"\n2. Search Name";
cout<<"\n3. Search Stream";
cout<<"\n4. Edit Records";
cout<<"\n5. Add Data of a New Student";
cout<<"\n6. Delete Student Data";
cout<<"\n7. Exit\n\n";
cin>>ch;
}
switch(ch)
{
case 1: cout<<"Displaying Information"<<endl;
display(s,n);
cout<<"\nDo you want to continue? ";
gets(c);break;
case 2: char nm_l[30];
cout<<"\nEnter a Name to be searched for: ";
strupr(gets(nm_l));
srch(s,n,nm_l);
cout<<"\nDo you want to continue? ";
gets(c);break;
case 3: char strm[10];
cout<<"\nEnter Stream to be searched for: ";
strupr(gets(strm));
srch(s,strm,n);
cout<<"\nDo you want to continue? ";
gets(c);break;
case 4: edit_rec(s,n);
cout<<"\nDo you want to continue? ";
gets(c);break;
case 5: add_data(s,n);
cout<<"\nDo you want to continue? ";
gets(c);break;
case 6: del_data(s,n);
cout<<"\nDo you want to continue? ";
gets(c);break;
case 7: cout<<"\nQuitting...";break;
default: cout<<"Please choose again";break;
}
a=stricmp(c,"NO");
if(a==0)
{
cout<<"Quitting...";
ch=7;
for(a=0;a<1000;a++)
{
for(f=0;f<10000;f++) {}
}
}
if(ch==7)
{
for(a=0;a<1000;a++)
{
for(f=0;f<10000;f++) {}
}
exit(0);
}
f=stricmp(c,"YES");
}while(f==0);
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment