#include<iostream.h>
#include <string>
using namespace std;
struct sdata
{
char name[5];
int reg;
};
struct sub
{
char subject[30];
sub * move;
};
void instudent(sdata & ins );
void show(sdata * ins);
class inf
{
sub * begin;
sub * look(int limit)
{
sub *pointer=begin;
for(int i=1; i<limit; i++)
pointer=pointer->move;
return pointer;
}
int check;
public:
inf()
{
begin=NULL;
check=0;
}
bool isempty()
{
return check==0;
}
void into(int x )
{
char n[30];
char loose;
cout<<"enter subject name";
cin.get(loose);
cin.get(n,30);
cout<<endl;
if(x==1)
{
sub *pointer=new sub;
for(int z=0;z<4;z++)
{
pointer->subject[z]=n[z];
}
pointer->move=begin;
begin=pointer;
}
else
{
sub *pointer=new sub;
for(int z=0;z<4;z++)
{
pointer->subject[z]=n[z];
}
sub *last=look(x-1);
pointer->move=last->move;
last->move=pointer;
}
check++;
}
void show2(sdata * pull)
{
sub *pointer=begin;
cout<<"reg no"<<endl;
cout<<pull->reg<<endl;
cout<<"name"<<endl;
cout<<pull->name<<endl;
while(pointer!=NULL)
{
cout<<pointer->subject<<endl;
pointer=pointer->move;
}
}
void lookfor(sdata * ins)
{
char searchname[5],loose;
cout<<"enter name";
cin.get(loose);
cin.get(searchname,4);
if(searchname==ins->name)
{
sub *pointer=begin;
cout<<"reg no"<<endl;
cout<<ins->reg<<endl;
cout<<"name"<<endl;
cout<<ins->name<<endl;
while(pointer!=NULL)
{
cout<<pointer->subject<<endl;
pointer=pointer->move;
}
}
}
};
void instudent(sdata & ins)
{
cout<<"enter reg no"<<endl;
cin>>ins.reg;
cout<<"enter name"<<endl;
cin>>ins.name;
}
void main()
{
inf the;
sdata sa[4];
char sname[5],loof;
int spec;
cout<<"ADD RECORDS"<<endl;
for(int i=0;i<2;i++)
{
instudent(sa[i]);
cout<<"u can enter 2 course subjcts"<<endl;
for(int k=1;k<3;k++)
{
the.into(k);
}
}
cout<<"YOUR SAVED RECORDS ARE"<<endl;
for(i=0;i<2;i++)
{
the.show2(&sa[i]);
}
//cout<<"for deleting a student's record press 1,for printing a specific student's record press 2 ";
//cin>>spec;
cout<<"to print the required student record"<<endl;
for(i=0;i<2;i++)
{
the.lookfor(&sa[i]);
}
sdata* pox[1];
cin.get(loof);
cin.get(sname,4);
pox[0]->name=sname;
cout<<"to delete the required student record"<<endl;
for(i=0;i<2;i++)
{
if(sa[i]->name == pox[0]->name)
{
delete [i]sa;
}
}
cout<<"viewing records after deletion"<<endl;
for(i=0;i<2;i++)
{
the.show2(&sa[i]);
}
}
hey this is my code for adding student record which further takes in courses taken by students,but it seems to be giving me trouble
PROBLEMS
*its displaying subjects taken by both students for each student record
*its lookfor ftn isnt working good.
this ftn has to print the data of the student user enters.
*in the last it has to delete the record of the student user enters.
these things arent working well i will be thankful if any one could tell me what i am doing wrong in these