1. You are to write a complete menu driven program to display: 1. Print list of
ID: 3621865 • Letter: 1
Question
1. You are to write a complete menu driven program to display:1. Print list of students
2. Print list of students with letter grade
3. Print list of those whom made an A grade
4. Print list of those e whom made an F grade
5. Print list of students sorted by name
6. add student to the class list
7. delete student from class list
8. quit
Note print should display to screen
Your program must-reads from already existing data file which contains the following data fields:
Name: 15
SSN:11
Sex: 1
Assignment average
Quiz Average
Midterm
Participation
Final
After program reads these data must compute a letter grade according to the syllabi that is
0.40* Assignment average+ Quiz Average*0.15+ participation*0.10+Midterm*0.15+ final*0.20 which makes a total, then if total >90 then A,…
Explanation / Answer
please rate - thanks
get back to me with the answer to my message, and I'll make any corrections
#include<stdio.h>
#include<conio.h>
#include <string.h>
struct CLASS
{char name[16];
char SSN[12];
char sex;
double assign;
double quiz;
double mid;
double part;
double final;
char grade;
};
void printhead();
void printwithgrade(struct CLASS[],int);
void printgrade(struct CLASS[],int,char );
void sort(struct CLASS[],int);
void print(struct CLASS[],int);
void add(struct CLASS[],int);
int deletes(struct CLASS[],int);
void calgrade(struct CLASS[],int);
int menu();
int main()
{int choice,n=0,m;
struct CLASS stu[50];
FILE *input;
char in[80];
char instring;
input = fopen("student.txt","r");
if(input == NULL)
{ printf("Error opening input file! ");
return 0;
}
while(fscanf(input,"%15c",&stu[n].name)>0)
{fscanf(input,"%11c",&stu[n].SSN);
fscanf(input,"%c",&stu[n].sex);
fscanf(input,"%lf",&stu[n].assign);
fscanf(input,"%lf",&stu[n].quiz);
fscanf(input,"%lf",&stu[n].mid);
fscanf(input,"%lf",&stu[n].part);
fscanf(input,"%lf",&stu[n].final);
n++;
}
calgrade(stu,n);
fclose(input);
for(;;)
{
choice=menu();
while(choice<1||choice>8)
{printf("Invalid choice ");
choice=menu();
}
switch (choice)
{
case 2:printwithgrade(stu,n);break;
case 3: printgrade(stu,n,'A');break;
case 4: printgrade(stu,n,'F');break;
case 5: sort(stu,n);
case 1: print(stu,n);break;
case 6: add(stu,n);
n++;
break;
case 7:n-=deletes(stu,n);
break;
case 8:
return 0;
}
}
}
int deletes(struct CLASS s[],int m)
{char n[15];
int i,j;
printf("Enter name of student to delete: ");
scanf("%s",n);
for(i=0;i<m;i++)
{ if(strcmp (s[i].name,n)==0)
{if(i==m-1)
return 1;
for(j=i;j<m-1;j++)
s[i]=s[i+1];
return 1;
}
}
printf("student not found ");
return 0;
}
void printgrade(struct CLASS s[],int n,char g)
{int i;
printf("Students with a grade of %c ",g);
printhead();
for(i=0;i<n;i++)
if(s[i].grade==g)
printf("%s %s %c %.2f %.2f %.2f %.2f %.2f ",s[i].name,s[i].SSN,
s[i].sex,s[i].assign,s[i].quiz,s[i].mid,s[i].part,s[i].final);
}
void printwithgrade(struct CLASS s[],int n)
{int i;
printhead();
for(i=0;i<n;i++)
printf("%s %s %c %.2f %.2f %.2f %.2f %.2f %c ",s[i].name,s[i].SSN,
s[i].sex,s[i].assign,s[i].quiz,s[i].mid,s[i].part,s[i].final,s[i].grade);
}
void calgrade(struct CLASS s[],int n)
{double tot;
int i;
for(i=0;i<n;i++)
{
tot=.4*s[i].assign+.15*s[i].quiz+.1*s[i].part+.15*s[i].mid+.2*s[i].final;
switch((int)tot/10) // using integer arithmetic by dividing
{case 10: // score by 10 anything between 90 to 99 becomes 9
case 9: // anything between 80 to 89 becomes 8 etc.
s[i].grade='A';
break;
case 8:
s[i].grade='B';
break;
case 7:
s[i].grade='C';
break;
case 6:
s[i].grade='D';
break;
default:
s[i].grade='F';
}
}
}
int menu()
{int choice;
printf("What would you like to do to the database? ");
printf("1. Print list of students ");
printf("2. Print list of students with letter grade ");
printf("3. Print list of those whom made an A grade ");
printf("4. Print list of those e whom made an F grade ");
printf("5. Print list of students sorted by name ");
printf("6. add student to the class list ");
printf("7. delete student from class list ");
printf("8. quit ");
printf("Enter choice: ");
scanf("%d",&choice);
return choice;
}
void add(struct CLASS stu[],int n)
{int i=n;
printf("Enter name: ");
scanf("%s",&stu[n].name);
printf("Enter Social Security Number: ");
scanf("%11c",&stu[n].SSN);
getchar();
printf("Enter sex(M/F): ");
scanf("%c",&stu[n].sex);
printf("Enter assignment average: ");
scanf("%lf",&stu[n].assign);
printf("Enter quiz average: ");
scanf("%lf",&stu[n].quiz);
printf("Enter midterm grade: ");
scanf("%lf",&stu[n].mid);
printf("Enter participation grade: ");
scanf("%lf",&stu[n].part);
printf("Enter final grade: ");
scanf("%lf",&stu[n].assign);
calgrade(stu,n);
}
void sort(struct CLASS s[],int n)
{int i,j;
struct CLASS t;
for(i=0;i<n-1;i++)
for(j=i;j<n;j++)
if(strcmp (s[i].name,s[j].name)>0)
{t=s[i];
s[i]=s[j];s[j]=t;
}
}
void printhead()
{printf("name SSN M/F Assignment Quiz midterm part final grade ");
}
void print(struct CLASS s[],int n)
{int i;
printhead();
for(i=0;i<n;i++)
printf("%s %s %c %.2f %.2f %.2f %.2f %.2f ",s[i].name,s[i].SSN,
s[i].sex,s[i].assign,s[i].quiz,s[i].mid,s[i].part,s[i].final);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.