Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <stdio.h> #include <stdlib.h> #include <string.h> struct student { char

ID: 3635198 • Letter: #

Question

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student
{
char id[100];
char firstname[200];
char lastname[20];
int score,assignment1,assignment2,assignment3,assignment4,assignment5,lab1,lab2,lab3,lab4,lab5,midterm,final;
struct student *next;
};

typedef struct student Stu;

Stu *s=0;
int n=0;



int main(){
int i;
do{
printf(" 1.view the information for a specific sutdent ");
printf("2.Add a new student ");
printf("3.Save the file ");
printf("4.load a file ");
printf("5.Show the data ");
printf("Choose a option:");
scanf("%d",&i);
if(i==1) search();
else if(i==2) add();
else if(i==3) save();
else if(i==4) load();
else if(i==5) display();


else{
Stu* p;
while(s!=0){
p=s->next;
free(s);
s=p;
}
break;
}
}while(1);
return 0;
}

void add(){
Stu *p;
if(s==0){
s=(Stu *)malloc(sizeof(Stu));
p=s;
}
else{
p=s;
while(p->next!=0) p=p->next;
p->next=(Stu *)malloc(sizeof(Stu));
p=p->next;
}
printf("Enter the student number here: ");
scanf("%s",p->id);
printf("Enter the firstname: ");
scanf("%s",p->firstname);
printf("Enter the lastname:");
scanf("%s",p->lastname);
printf("Enter the mark for assignment1:");
scanf("%d",&(p->assignment1));
printf("Enter the mark for assignment2:");
scanf("%d",&(p->assignment2));
printf("Enter the mark for assignment3:");
scanf("%d",&(p->assignment3));
printf("Enter the mark for assignment4:");
scanf("%d",&(p->assignment4));
printf("Enter the mark for assignment5:");
scanf("%d",&(p->assignment5));
printf("Enter the mark for Lab1:");
scanf("%d",&(p->lab1));
printf("Enter the mark for Lab2:");
scanf("%d",&(p->lab2));
printf("Enter the mark for Lab3:");
scanf("%d",&(p->lab3));
printf("Enter the mark for Lab4:");
scanf("%d",&(p->lab4));
printf("Enter the mark for Lab5:");
scanf("%d",&(p->lab5));
printf("Enter the mark for midterm:");
scanf("%d",&(p->midterm));
printf("Enter the mark for final:");
scanf("%d",&(p->final));

printf(" The following record has been added to the list: ");
printf("ID Name Assignment 1-5 lab1-5 midterm+final ");
printf("%s %s %s(%d %d %d %d %d) (%d %d %d %d %d) %d %d ",p->id,p->firstname,p->lastname,p->assignment1,p->assignment2,p->assignment3,p->assignment4,p->assignment5,p->lab1,p->lab2,p->lab3,p->lab4,p->lab5,p->midterm,p->final);

n++;
}

void search()
{
if(s==0){
printf("No record available. ");
return;
}
Stu *p;
p=s;

char id[100];
printf("Enter the student number of the student: ");
scanf("%s",id);
while(p!=0){
if(strcmp(p->id,id)==0) break;
p=p->next;
}

if(p==0)
printf("No such record exits. ");

else
{
printf("The following record has been found ");
printf("Student# first/last Name Assignment(1-5) lab(1-5), midterm final Score ");
printf("%s %s %s %s %d %d %d %d %d %d %d %d %d %d %d %d ",p->id,p->firstname,p->lastname,p->assignment1,p->assignment2,p->assignment3,p->assignment4,p->assignment5,p->lab1,p->lab2,p->lab3,p->lab4,p->lab5,p->midterm,p->final);
}
}



void display(){
if(s==0){
printf("No this student in the data base. ");
return;
}
Stu *p;
p=s;
printf("student number Name Assignments1-5, labs 1-5 midterm+final ");
while(p!=0){
printf("%s %s %s (%d %d %d %d %d) (%d %d %d %d %d) %d %d ",p->id,p->firstname,p->lastname,p->assignment1,p->assignment2,p->assignment3,p->assignment4,p->assignment5,p->lab1,p->lab2,p->lab3,p->lab4,p->lab5,p->midterm,p->final);
p=p->next;
}
}

void save(){
if(s==0){
printf("No record. ");
return;
}
char filename[100];
printf("Please enter the file name you wish to save : ");
scanf("%s",filename);
FILE *p;
if((p=fopen(filename,"w"))==0){
perror("Cannot open file. ");
return;
}
Stu *q;
q=s;
while(q!=0){
fprintf(p,"%s %s %s %s %d %d %d %d %d %d %d %d %d %d %d %d ",q->id,q->firstname,q->lastname,q->assignment1,q->assignment2,q->assignment2,q->assignment3,q->assignment4,q->assignment5,q->lab1,q->lab2,q->lab3,q->lab4,q->lab5,q->midterm,q->final);
q=q->next;
}
fclose(p);
}

void load(){
char filename[100];
int m;
printf("Please enter your file name here: ");
scanf("%s",filename);
FILE *p;
if((p=fopen(filename,"r"))==0){
perror("Can not open the file ");
return;
}
Stu *q,*r;
while(s!=0)
{
q=s->next;
free(s);
s=q;
}
n=0;
while(1){
if(s==0){
s=(Stu *)malloc(sizeof(Stu));
q=s;
}
else{
q->next=(Stu *)malloc(sizeof(Stu));
r=q;
q=q->next;
}
m=fscanf(p,"%s %s %s %d %d %d %d %d %d %d %d %d %d",q->id,q->firstname,q->lastname,&(q->assignment1),&(q->assignment2),&(q->assignment3),&(q->assignment4),&(q->assignment5),&(q->lab1),&(q->lab2),&(q->lab3),&(q->lab4),&(q->lab5),&(q->midterm),&(q->final));
if(m==-1){
if(q==s){
free(s);
s=0;
}
else{
free(q);
r->next=0;
}
break;
}
n++;
}
fclose(p);
display();
}

Explanation / Answer

Dear Friend here is the program u want PLEASE RATE #include #include #include struct student { char id[100]; char firstname[200]; char lastname[20]; int score,assignment1,assignment2,assignment3,assignment4,assignment5,lab1,lab2,lab3,lab4,lab5,midterm,final; struct student *next; }; void add(); void load(); void search(); void display(); void save(); typedef struct student Stu; Stu *s=0; int n=0; int main(){ int i; do{ printf(" 1.view the information for a specific sutdent "); printf("2.Add a new student "); printf("3.Save the file "); printf("4.load a file "); printf("5.Show the data "); printf("Choose a option:"); scanf("%d",&i); if(i==1) search(); else if(i==2) add(); else if(i==3) save(); else if(i==4) load(); else if(i==5) display(); else{ Stu* p; while(s!=0){ p=s->next; free(s); s=p; } break; } }while(1); return 0; } void add(){ Stu *p; if(s==0){ s=(Stu *)malloc(sizeof(Stu)); p=s; } else{ p=s; while(p->next!=0) p=p->next; p->next=(Stu *)malloc(sizeof(Stu)); p=p->next; } printf("Enter the student number here: "); scanf("%s",p->id); printf("Enter the firstname: "); scanf("%s",p->firstname); printf("Enter the lastname:"); scanf("%s",p->lastname); printf("Enter the mark for assignment1:"); scanf("%d",&(p->assignment1)); printf("Enter the mark for assignment2:"); scanf("%d",&(p->assignment2)); printf("Enter the mark for assignment3:"); scanf("%d",&(p->assignment3)); printf("Enter the mark for assignment4:"); scanf("%d",&(p->assignment4)); printf("Enter the mark for assignment5:"); scanf("%d",&(p->assignment5)); printf("Enter the mark for Lab1:"); scanf("%d",&(p->lab1)); printf("Enter the mark for Lab2:"); scanf("%d",&(p->lab2)); printf("Enter the mark for Lab3:"); scanf("%d",&(p->lab3)); printf("Enter the mark for Lab4:"); scanf("%d",&(p->lab4)); printf("Enter the mark for Lab5:"); scanf("%d",&(p->lab5)); printf("Enter the mark for midterm:"); scanf("%d",&(p->midterm)); printf("Enter the mark for final:"); scanf("%d",&(p->final)); printf(" The following record has been added to the list: "); printf("ID Name Assignment 1-5 lab1-5 midterm+final "); printf("%s %s %s(%d %d %d %d %d) (%d %d %d %d %d) %d %d ",p->id,p->firstname,p->lastname,p->assignment1,p->assignment2,p->assignment3,p->assignment4,p->assignment5,p->lab1,p->lab2,p->lab3,p->lab4,p->lab5,p->midterm,p->final); n++; } void search() { if(s==0){ printf("No record available. "); return; } Stu *p; p=s; char id[100]; printf("Enter the student number of the student: "); scanf("%s",id); while(p!=0){ if(strcmp(p->id,id)==0) break; p=p->next; } if(p==0) printf("No such record exits. "); else { printf("The following record has been found "); printf("Student# first/last Name Assignment(1-5) lab(1-5), midterm final Score "); printf("%s %s %s %d %d %d %d %d %d %d %d %d %d %d %d ",p->id,p->firstname,p->lastname,p->assignment1,p->assignment2,p->assignment3,p->assignment4,p->assignment5,p->lab1,p->lab2,p->lab3,p->lab4,p->lab5,p->midterm,p->final); } } void display(){ if(s==0){ printf("No this student in the data base. "); return; } Stu *p; p=s; printf("student number Name Assignments1-5, labs 1-5 midterm+final "); while(p!=0){ printf("%s %s %s (%d %d %d %d %d) (%d %d %d %d %d) %d %d ",p->id,p->firstname,p->lastname,p->assignment1,p->assignment2,p->assignment3,p->assignment4,p->assignment5,p->lab1,p->lab2,p->lab3,p->lab4,p->lab5,p->midterm,p->final); p=p->next; } } void save(){ if(s==0){ printf("No record. "); return; } char filename[100]; printf("Please enter the file name you wish to save : "); scanf("%s",filename); FILE *p; if((p=fopen(filename,"w"))==0){ perror("Cannot open file. "); return; } Stu *q; q=s; while(q!=0){ fprintf(p,"%s %s %s %d %d %d %d %d %d %d %d %d %d %d %d ",q->id,q->firstname,q->lastname,q->assignment1,q->assignment2,q->assignment2,q->assignment3,q->assignment4,q->assignment5,q->lab1,q->lab2,q->lab3,q->lab4,q->lab5,q->midterm,q->final); q=q->next; } fclose(p); } void load(){ char filename[100]; int m; printf("Please enter your file name here: "); scanf("%s",filename); FILE *p; if((p=fopen(filename,"r"))==0) { perror("Can not open the file "); return; } Stu *q,*r; while(s!=0) { q=s->next; free(s); s=q; } n=0; while(1){ if(s==0){ s=(Stu *)malloc(sizeof(Stu)); q=s; } else{ q->next=(Stu *)malloc(sizeof(Stu)); r=q; q=q->next; } m=fscanf(p,"%s %s %s %d %d %d %d %d %d %d %d %d %d",&(q->id),&(q->firstname),&(q->lastname),&(q->assignment1),&(q->assignment2),&(q->assignment3),&(q->assignment4),&(q->assignment5),&(q->lab1),&(q->lab2),&(q->lab3),&(q->lab4),&(q->lab5),&(q->midterm),&(q->final)); if(m==-1){ if(q==s){ free(s); s=0; } else{ free(q); r->next=0; } break; } n++; } fclose(p); display(); }