#include<iostream.h>
#include<string.h>
void PrintAll()
struct stud
{
char *name,*address,*date;
float Avg;
int *grade,Nog;
long ID;
stud *next,*prev;
};
void Add(stud**root)
{
int n,*T;
long ID;
char *name,*date,*address;
float Avg;
cout<<"Please Enter Student Name : ";
cin>> *name;
cout<<"Please Enter Student ID.No : ";
cin>> ID;
cout<<"Please Enter Student BirthDate : ";
cin>> *date;
cout<<"Please Enter Student Address : ";
cin>> *address;
cout<<"Please Enter The Number OF Grades : ";
cin>>n;
T=new int[n];
int sum=0;
for(int i=0;i<n;i++)
{
cin>>T[i];
sum+=T[i];
}
Avg=float(sum/n);
stud*p=NULL;
p=new stud;
strcpy(p->name,name);
strcpy(p->address,address);
strcpy(p->date,date);
p->grade=new int[n];
p->Nog=n;
p->grade=T;
p->ID=ID;
p->next=p->prev=NULL;
p->Avg;
if(*root==NULL)
{
*root=p;
(*root)->next=(*root)->prev=*root;
}
else {
stud*cur=*root;
stud*prev=cur->prev;
if (stricmp(cur->name,p->name)>0)
{
p->next=cur;
p->prev=cur->prev;
prev->next=p;
*root=p;
}//add at head
else if (stricmp(prev->name,p->name)<0)
{
prev->next=p;
p->next=prev->next;
p->prev=prev;
(*root)->prev=p;
}//add at tail
else
{
while(cur->next!=*root && stricmp(cur->name,p->name)<0)
{
prev=cur;
cur=cur->next;
}
p->next=cur;
cur->next=p;
p->prev=prev;
prev->next=p;
}
}
}// end of add
void Delete(stud**root)
{
if(*root==NULL) cout<<"There's no elements to be Deleted";
else
PrintAll(*root);
cout<<"please Enter The ID.No That You Want To Delete :";
long n;
{
cin>>n;
stud*cur=*root;
stud*prev=cur->prev;
if(cur->ID==n)
{
prev->next=cur->next;
cur->next->prev=prev;
*root=cur->next;
delete cur;
}//delete at head
else if(prev->ID==n)
{
cur->prev=prev->prev;
cur->prev->next=*root;
delete prev;
}//delete at tail
else
{
while(cur->ID!=n && cur->next!=*root)
{
prev=cur;
cur=cur->next;
}
if(cur->next==*root)
cout<<"Not Found";
else
{
prev->next=cur->next;
cur->next->prev=prev;
delete cur;
}
}//delete at middle
}
}//end Of delete
void SearchID(stud*root)
{
int n;
if(root==NULL) cout<<"List Is Empty ";
else
long n;
{
cin>>n;
stud*cur=root;
stud*prev=cur->prev;
if(cur->ID==n) cout<<"Not FounD";
else
if(prev->ID==n) cout<<"FounD";
else
{
while(cur->next!=root && cur->ID!=n)
cur=cur->next;
if(cur->next==root)
cout<<"NoT FounD";
else
cout<<"FounD";
}
}
}// end of SearchID
void SearchName(stud*root)
{
if(root==NULL) cout<<"Empty List , Please Fill It Up";
else
char *m;
{
cin>>*m;
stud*cur=root;
stud*prev=cur->prev;
if(stricmp (cur->name,m)==0) cout<<"FounD" ;
else
if(stricmp (prev->name,m)==0) cout<<"FounD" ;
else
{
while(cur->next!=root && stricmp(cur->name,m)!=0)
cur=cur->next;
if(cur->next=root) cout<<"NoT FounD";
else
cout<<"FounD";
}
}
}
void ComputeAvg(stud*root)
{
stud*p=r;
float sum=0;
int n=0;
p=p->next;
while(p)
{
sum+=p->Avg;
n++;
}
cout<<"The All Average= "<<sum/n;
}
void Display()
{
cout<<"Please Choose Your Operation" <<endl;
cout<<"1.Add Student"<<endl;
cout<<"2.Delete Student"<<endl;
cout<<"3.Search By Name Or By ID.No"<<endl;
cout<<"4.Compute All Students Average"<<endl;
cout<<"5.EnD Program"<<endl;
}
void PrintNode(struct p)
{
cout<<p.name<<endl;
cout<<p.date<<endl;
cout<<p.ID<<endl;
cout<<p.address<<endl;
int *s=p.grade;
while(s)
{
cout<<*s;
s++;
}
cout<<p.avg;
}
void PrintAll(stud*r)
{
if(p==NULL) cout<<"Empty";
else
{
stud*p=r;
while (p->next!=root)
{
PrintNode(*p);
p=p->next;
}
PrintNode(*p);
}
}
void main ()
{
stud *r=NULL;
while (1)
{
Display();
int op;
cin>>op;
if (op==1) Add(&root);
else if (op==2) Delete(&root);
else if (op==3)
{
int op2;
cout<<"1.Search By Name . ";
cout<<"2.Search By ID.No " ;
cin<<op2;
if (op2==1) SearchName(root);
else if (op2==2) SearchID(root);
else
cout<<"Invalid Entry";
}
else if (op==4) ComputeAvg(root);
else if (op==5) break;
else cout<<"Invalid Entry ";
}
}
** but i have 2 errors and i cant solve them
1. error C2143: syntax error : missing ';' before '<class-head>'
2. fatal error C1004: unexpected end of file found Error executing cl.exe.
[Noelle Mallory - MSFT] Please post questions to the MSDN Forums at
http://forums.microsoft.com/msdn. You will likely get a quicker response through the forum than through the Community Content.