In: Computer Science
*Answer must be in C*
Write a program as follows:
a- Define a structure type named "student" capable of storing the name of a student (string less than 15 characters long),
homework grade as float, and exam grade as a float.
b- Create an array of students named "cats" to store the info for 50 students.
c- Create a menu (and repeatedly display the menu) with three options:
option 1: enter the info for a student.
option 2: print the info of all students, do not print structures that have no hurricane data in them
option 3: exit program
d. write code to carry out each menu option
#include <stdio.h>
#include <string.h>
//student structure
struct student
{
char name[15];
float grade;
float examGrade;
};
int main()
{
//create an array of structure
struct student cats[50];
int choice, k;
k = 0;
while(1)
{
//display menu
printf("\noption 1: enter the info for a student.");
printf("\noption 2: print the info of all students.");
printf("\noption 3: exit program");
//get choice from the user
printf("\n\nEnter your choice: ");
scanf("%d", &choice);
if(choice==1)
{
printf("\n\nEnter the name of the student: ");
scanf("%s",cats[k].name);
printf("Enter the grade: ");
scanf("%f", &cats[k].grade);
printf("Enter the exam grade: ");
scanf("%f", &cats[k].examGrade);
k++;
}
else if(choice ==2)
{
printf("\nThe student record are: ");
for(int i=0; i<k; i++)
{
//display student record
printf("\n\nName: %s", cats[i].name);
printf("\nGrade: %.2f", cats[i].grade);
printf("\nExam grade: %.2f\n", cats[i].examGrade);
}
}
else if(choice == 3)
{
break;
}
else
{
printf("\nInvalid input!");
}
}
return 0;
}
OUTPUT:
