#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

the code actually goes like this

struct student
{
char name[5];
int reg;
};
struct studentcourse
{
char subject[30];
sub * move;
};

these are my structure definitions
what the code has to do is to input data for a student i.e. his name and registration number.for every student there is a linked list of courses which would ask what courses is that particular student taking(no of courses is same for every student).
The Problem im getting is that in the display of every single student courses taken by all the students appear rather then just those taken by that student.
Im not sure whether the problem is with association or what can anyone plz tell me what is wrong here.ive taken student structure as an object in main and student courses as link list.
My function for taking courses is
//ftn defined in class

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++;
}

and for taking name and reg no. is

//ftn defined outside class
void instudent(student & ins)
{

cout<<"enter reg no"<<endl;
cin>>ins.reg;
cout<<"enter name"<<endl;
cin>>ins.name;

}

for taking values (code), in main is

cout<<"ADD RECORDS"<<endl;
for(int i=0;i<2;i++)
{
instudent(sa[i]);//sa[4] is the object of struct student
cout<<"u can enter 2 course subjcts"<<endl;

for(int k=1;k<3;k++)
{
the.into(k);//where the is object of class
}
}

display ftn in class is

void show2(student * 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;

}
}

which is called in main as

cout<<"YOUR SAVED RECORDS ARE"<<endl;
for(i=0;i<2;i++)
{
the.show2(&sa[i]);
}

PROBLEMS
2))its lookfor ftn isnt working good as well
what is has to do is to print a specicific students record i.e, user enters a student name and it has to search through all students and find the one asked for and print record of only that student(his name,reg no. ,courses taken by him)

my ftn is

void lookfor(student * 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;

}
}
}

but it doesn’t work.is there something wrong with the syntax.
My call ftn in main()

cout<<"to print the required student record"<<endl;
for(i=0;i<2;i++)
{
the.lookfor(&sa[i]);//the is class object and sa[4] is struct student object
}

3))problem
in the last it has to delete the record of student (name entered by the student)
code for deletion I came up with

student* pox[1];
 
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;
}
}

these things arent working well i will be thankful if any one could tell me what i am doing wrong in these

try to improve your code by removing unncessary code.
it would be far simplier if you wrote:

sub *pointer=new sub;
for(int z=0;z<4;z++)
   pointer->subject[z]=n[z]; //You dont need braces if you use only one statement

if (x==0)
{
pointer->move=begin;
begin=pointer;
}
else
{
sub *last=look(x-1);
pointer->move=last->move;
last->move=pointer;
}

i didnt analize the whole code but you should analyze the whole code like this, eliminate unnecessary code and then post again,
regards

This article has been dead for over six months. Start a new discussion instead.