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

Instruction: You must use pointers for this lab. No arrays, no structures. For e

ID: 654639 • Letter: I

Question

Instruction: You must use pointers for this lab. No arrays, no structures. For example, if you need an array of floats to hold the scores, do not use float score[15]. Rather use float *score, then use dynamic memory allocation to hold required memory. You must use memory optimally, that is if you have only 6 scores, you must point to a memory chunk of sizeof(float)*6 bytes. Similarly, to hold a name, instead of doing it with 2D char arrays, use 2D pointers (char firstName[15][20] _ char **firstName).

Problem:

Write a menu based program to maintain student records. Your program should take the following inputs:

1. Student first name (max. 20 characters)

2. Student last name, (max. 20 characters)

3. Student scores (float/double), eg. 85.4

Your program should be able to take records of a minimum of 5 students. After taking the records,

you should provide 8 functionalities to the user.

1. Print records

Explanation / Answer

# define ID_LEN=20;
int main()
{
int ch,n=5;
char *s;
int i=0;
char **first name,**lastname;
float **score;
int variableNumberOfElements=15;
firstname = malloc(variableNumberOfElements * sizeof(char*));
lastname = malloc(variableNumberOfElements * sizeof(char*));
score = malloc(variableNumberOfElements * sizeof(float *));
for (int i = 0; i < variableNumberOfElements; i++)
firstname[i] = malloc((ID_LEN+1) * sizeof(char));
lastname[i]= malloc((ID_LEN+1) * sizeof(char));
score[i]= malloc((ID_LEN+1) * sizeof(float));
for (int i = 0; i < n; i++)
scanf("%s",firstname[i] );
for (int i = 0; i < n; i++)
scanf("%s",lastname[i] );
for (int i = 0; i < n; i++)
scanf("%f",&score[i] );
printf("1.print records ";
printf("2.Add a record ";
printf("3.Delete a record ";
printf("4 search a record by last name ";
printf("5.sort by scores ";
printf("6.sort by last name ";
printf("7.median score ";
printf("8.exit ";
printf("enter the choice ";
scanf("%d"&ch);
switch(ch)
{
case 1: {

for(i=0;i<n;i++)
printf("student first name%s ", firstname[i]);
printf("student last name%s ", lastname[i]);
printf("student score %f ", score[i]);


Break;
]
case 2 :

{
printf{"add student first name");
scanf("%s",firstname[++n]);
printf{"add student last name");
scanf("%s",lastname[++n);
printf{"add student score");
scanf("%f",&score[++n]);
break;
}

case 3 :
{
printf{"enter the name u want to delete ");
scanf("%s",s);
for(i=o;i<n;i++)
{if(!strcmp(lastname[i],s))
free(lastname[i]);}
}
break;

}


case 4: {
printf{"enter the name u want to search ");
scanf("%s",s);
for(i=o;i<n;i++)

{if(!strcmp(lastname[i],s))
prinf{"serch succesfull,found");}

Break;
}

case 5: sort(lastname);
Break;
case 6: sort(score);
Break;
case 7:median(score);
Break;
case 8:exit(0);
default:Break;
}
getch();}
}