#include<iostream>
void menu(void);
using namespace std;
/**************************************/
struct data
{
char name[10];
int id;
int gpa;
};
struct student
{
struct data info;
struct student *next;
};
void readdata(struct student*);
/**************************************/
template<class ttype>class slist
{
student* h; //head of list
public:
void prepend(ttype n); //adds to the front of the list
void del(); //delete first element
void print(); //print list contents
void release(); //destroy list
slist()
{
h=NULL;
}
};
/***************************************/
template<class ttype>void slist<ttype>::prepend(ttype n)/*EACH TIME THIS FUNCTION IS CALLED ,WE ADD A NEW ELEMENT 2 THE LIST*/
{
struct student *newptr;
struct student *current;
newptr = new student;
if(newptr!=NULL)
{
newptr->info=n;
newptr->next=NULL;
if(h==NULL)/*IF THE LIST IS EMPTY*/
h=newptr;
else
{
current=h;
while(current->next!=NULL)
current=current->next;
current->next=newptr;
}
}
}
/************************************/
template<class ttype>void slist<ttype>::print()
{
if(h==NULL)
cout<<"the list is empty!!!\n";
else
{
while(h!=NULL)
{
cout<<"THE NAME IS "<< h->name<<endl;
cout<<"THE ID IS IS "<< h->id<<endl;
cout<<"THE GPA IS "<< h->gpa<<endl;
h=h->next;
}
cout<<endl;
}
}
/**********************************
/*****************************************/
template<class ttype>void slist<ttype>::del()
{
struct student*temp;
temp=h;
if(h!=NULL)
h=h->next;
free(temp);
}
/******************************************/
template<class ttype>void slist<ttype>::release()
{
while(h!=NULL)
h->next=NULL;
}
/***********************/
int main()
{
int n;
struct student var;
cout<<"HOW MANY ELELMENT U WANT TO ADD\n";
scanf("%d",&n);
slist<student>obj;
for(int i=0;i<n;i++)
readdata(&var);
obj.prepend(var);
/**********************/
void readdata(struct student *x)
{
cout<<"ENTER A NAME OF THE STUDENT\n";
scanf("%s",x->info.name);
cout<<"ENTER THE STUDENT ID\n";
scanf("%d",&x->info.id);
cout<<"ENTER THE STUDENT GPA\n";
scanf("%d",&x->info.gpa);
}لم اتمكن من فهم الخطا , هل لازم اعمل OVERLOAD او ايش؟؟مع ان الطريقة هذه تضبط في برامج اخرى