أعزائي أصحابي الكِـرام ..
لقد عملت برنامج ، و صادفتني عدة مشكلات فيه ، :(
و بعد عدة محاولات ، لجأت إليكم علني ألقي روح المساعده الطيبه و السريعه منكم
مع خالص الشكر والإحترام ..
و منكم دائماً نستفيد :rolleyes:
هذا هو البرنامج ....
#include<iostream.h>
#include<string.h>
typedef struct node *ptrType;
typedef int itemType;
struct node{
char code;
int grade;
int nCredits;
ptrType next;
};
class course{
protected:
ptrType head;
public:
course(){ head=NULL;};
int isFull(ptrType temp){ return (temp==NULL);};
int isEmpty(){ return (head==NULL);};
int addFront(itemType newItem)
{
ptrType temp=new node;
if (isFull(temp))
return 0;
else{
temp->code= newItem;
temp->grade= newItem;
temp->nCredits= newItem;
temp->next= head;
head= temp;
return 1;
}
};
int deleteFront(){
node* temp=head;
head= head->next;
delete temp;
}
int getHead (char item,struct node c ){
ptrType cur;
for (cur=head;cur!=NULL && cur->code!=item;cur=cur->next)
if (cur==NULL){
return 0;}
else{
strcpy(c.code,cur->code);
strcpy(c.grade,cur->grade);
c.nCredits=cur->nCredits;
cout<<cur->code
<<"\n"<<cur->grade
<<"\n"<<cur->nCredits;
}
return 1;
};
int set (char item, struct node c){
ptrType cur;
for (cur=head;cur!=NULL && cur->code!=item;cur=cur->next )
if (cur == NULL ){
return 0;}
else{
strcpy(cur->code ,c.code);
strcpy(cur->grade ,c.grade);
cur->nCredits=c.nCredits;
}
return 1;
};
int print(){
if (head == NULL){
cout<<"there is no data";
return 0;}
else{
for (ptrType cur=head; cur != NULL; cur = cur -> next)
cout<<cur->code
<<"\n"<<cur->grade
<<"\n"<<cur->nCredits;
}
}
};
int main (){
class course R;
struct node N;
char Ccode;
int choice;
cout<<"\n1.Add course details"<<"\n2.Remove course details"
<<"\n3.Set course details"<<"\n4.Get course details"
<<"\n5.Print course details"
<<"\n6.Calculate GPA"
<<"\n7.Exit";
cin>>choice;
while (choice !=7)
{
switch(choice){
case 1:
cout<<"Enter the code of the course:";
cin>>N.code;
cout<<"Enter the grade of the course:";
cin>>N.grade;
cout<<"Enter the number of credits of the course:";
cin>>N.nCredits;
R.addFront(N);
break;
case 2:
cout<<"Enter the code of the course you want to delete :";
cin>>Ccode;
R.deleteFront (Ccode);
break;
case 3:
cout<<"Enter the code of the course you want to set :";
cin>>Ccode;
cout<<"Enter the code of the course:";
cin>>N.code;
cout<<"Enter the grade of the course:";
cin>>N.grade;
cout<<"Enter the number of credits of the course:";
cin>>N.nCredits;
N.setHead (Ccode,N);
break;
case 4:
cout<<"Enter the code of the course you want to get :";
cin>>Ccode;
R.getHead (Ccode,N);
break;
case 5:
R.print();
break;
}
cout<<"\n1.Add course details"<<"\n2.Remove course details"
<<"\n3.Set course details"<<"\n4.Get course details"
<<"\n5.Print course details"<<"\n6.Exit";
cin>>choice;
case 6:
float sum=0.0;
int total=0;
for(ptrType cur=R.getHead();cur!=NULL;cur=cur->next)
if(cur->grade=='A')
sum+=4*cur->nCredits;
else if{
(cur->grade=='B')
sum+=3*cur->nCredits;
}
else if{
(cur->grade=='C')
sum+=2*cur->nCredits;
}
else if{
(cur->grade=='D')
sum+=1*cur->nCredits;
}
else
return 0;
}
return 0;
}