Untitled
unknown
plain_text
3 years ago
4.3 kB
24
Indexable
struct nodeClass
{
int classID;
double classMidtermAverage;
struct nodeClass *next;
struct nodeStudent *studentPtr;
};
struct nodeStudent
{
int studentID;
int midterm;
struct nodeStudent *next;
};
struct nodeStudent* head1=NULL;
struct nodeStudent* tail1=NULL;
struct nodeStudent* head2=NULL;
struct nodeStudent* tail2=NULL;
struct nodeStudent* head3=NULL;
struct nodeStudent* tail3=NULL;
struct nodeStudent* head4=NULL;
struct nodeStudent* tail4=NULL;
void insert(struct nodeClass** head,int id,int midterm){
if(*head==NULL){
struct nodeClass * bir;
bir= (struct nodeClass *)malloc(sizeof(struct nodeClass));
struct nodeClass * iki;
iki= (struct nodeClass *)malloc(sizeof(struct nodeClass));
struct nodeClass * uc;
uc= (struct nodeClass *)malloc(sizeof(struct nodeClass));
struct nodeClass * dort;
dort= (struct nodeClass *)malloc(sizeof(struct nodeClass));
*head=bir;
bir->classID=1;
iki->classID=2;
uc->classID=3;
dort->classID=4;
bir->next=iki;
iki->next=uc;
uc->next=dort;
dort->next=NULL;
bir->studentPtr=head1;
iki->studentPtr=head2;
uc->studentPtr=head3;
dort->studentPtr=head4;
}
if (id>=66000&&id<77000){
if(head1==NULL){
struct nodeStudent *new=(struct nodeStudent *)malloc(sizeof(struct nodeStudent));
new->midterm=midterm;
new->studentID=id;
new->next=NULL;
head1=tail1=new;
}
else{
struct nodeStudent *new=(struct nodeStudent *)malloc(sizeof(struct nodeStudent));
new->midterm=midterm;
new->studentID=id;
new->next=NULL;
tail1->next=new;
tail1=new;
}
}
else if(id>=77000&&id<88000){
if(head2==NULL){
struct nodeStudent *new=(struct nodeStudent *)malloc(sizeof(struct nodeStudent));
new->midterm=midterm;
new->studentID=id;
new->next=NULL;
head2=tail2=new;
}
else{
struct nodeStudent *new=(struct nodeStudent *)malloc(sizeof(struct nodeStudent));
new->midterm=midterm;
new->studentID=id;
new->next=NULL;
tail2->next=new;
tail2=new;
}
}
else if(id>=88000&&id<99000){
if(head3==NULL){
struct nodeStudent *new=(struct nodeStudent *)malloc(sizeof(struct nodeStudent));
new->midterm=midterm;
new->studentID=id;
new->next=NULL;
head3=tail3=new;
}
else{
struct nodeStudent *new=(struct nodeStudent *)malloc(sizeof(struct nodeStudent));
new->midterm=midterm;
new->studentID=id;
new->next=NULL;
tail3->next=new;
tail3=new;
}
}
else if(id>=99000){
if(head4==NULL){
struct nodeStudent *new=(struct nodeStudent *)malloc(sizeof(struct nodeStudent));
new->midterm=midterm;
new->studentID=id;
new->next=NULL;
head4=tail4=new;
}
else{
struct nodeStudent *new=(struct nodeStudent *)malloc(sizeof(struct nodeStudent));
new->midterm=midterm;
new->studentID=id;
new->next=NULL;
tail4->next=new;
tail4=new;
}
}
}
void computeClassAverage(struct nodeClass* head){
struct nodeClass* sinif=head;
printf("%d \n",sinif->next->classID);
struct nodeStudent* ogrenci=sinif->studentPtr;
printf("%d \n",ogrenci->midterm);
do{
ogrenci=sinif->studentPtr;
int toplam=0,sayi=0;
double ort=0.0;
do{
sayi++;
toplam+=ogrenci->midterm;
ogrenci=ogrenci->next;
}while(ogrenci->next!=NULL);
ort=toplam/sayi;
sinif->classMidtermAverage=ort;
sinif=sinif->next;
}while(sinif->next!=NULL);
}
void printAll(struct nodeClass* head){
struct nodeClass* sinif=head;
struct nodeStudent* ogrenci=sinif->studentPtr;
do{
ogrenci=sinif->studentPtr;
printf("%d %f\n",sinif->classID,sinif->classMidtermAverage);
do{
printf("%d %d\n",ogrenci->studentID,ogrenci->midterm);
ogrenci=ogrenci->next;
}while(ogrenci->next!=NULL);
}while(sinif->next!=NULL);
}
// You must write all the function definitions to be used in this lab into this file.
// You may also write other functions that may be called from our functions.
// Do not make any changes to the main.c file.
// Upload function.h file to the system as StudentNumber.h.
Editor is loading...