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

Write a menu based program to maintain student records. Your program should take

ID: 3681716 • Letter: W

Question

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 and maximum of 15 students. After taking the records, you should provide 6 functionalities to the user. 1. Print records – prints records of all students 2. Search by first name – prints record of the student with a given first name. If there are multiple students with the same first name, print records for all of them. 3. Search by last name – prints record of the student with a given last name. If there are multiple students with the same last name, print records for all of them. 4. Sort by score – sort the records of students according to their scores, and then print the sorted records. 5. Sort by last name – sort the records of students according to their names alphabetically, and then print the sorted records. 6. Exit the program – terminate on a specific input from the user. Let that specific input be an integer of value 0. You should print the record in the following format: First Name: firstname 1, Last Name: lastname 1, Score: score 1 First Name: firstname 2, Last Name: lastname 2, Score: score 2 You should write each functionality from 1-5 in separate functions. You should provide a menu to the user as following: For inputs: Please indicate number of records you want to enter (min 5, max 15): #of records After user gives the number of records, you should inform the user how to enter the records: Please input records of students (enter a new line after each record), with following format first name last name score After user gives the inputs for the records, inform the user about the functionalities: Print records (press 1) Search by first name (press 2) Search by last name (press 3) Sort by score (press 4) Sort by last name (press 5) Exit the program (press 0)

Explanation / Answer

#define EPSILON pow (10.0 ,-6)
#include< math.h >
#include"readLine.h"

/* firstly define ... */

typedef struct stdRecord
{
char * firstNames ;
char * lastNames ;
float myScores ;
} Record ;
void freeVrec ( Record * rec )
{
free (rec -> lastNames) ;
free (rec -> firstNames) ;
}

/* NOW ok 2 include*/

#include"Cvec.h"
#include"Cvec_func's.h"

void showRec (const Record * rec)
{
printf (" First name : %-20s Last name : %-20s myScores : %5.1f " ,rec -> firstNames ,rec -> lastNames ,rec -> myScores) ;
}
void dispC_vec (const Cvec * cv)
{
int i ;
for (i =0 ;i <cv -> size ;++ i) showRec (&cv -> arr[i]) ;
}

/* next two fun's r used in sorting d Cvec*/
int cmpMyScores (const Record * x ,const Record * y)
{
float temp = x -> myScores - y -> myScores ;
if (fabs (temp ) <EPSILON) return 0 ;
if (temp <0 ) return -1 ;
return 1 ;
}

int cmpL_Names (const Record * x ,const Record * y)
{
return strcmp (x -> lname ,y -> lastNames) ;
}

/*two handy util's 4r many C student programming prob's*/
int takingIntChar (const char * mesag)
{
char alph ;
printf ( mesag ) ; fflush ( stdout ) ;
alph =getchar ( ) ;
if ( alph !=' ' ) while (getchar ( ) !=' ' ) ; /*flush stdin*/
return alph ;
}

int additional ( )
{
int a = takingIntChar (" additional ( yes / no ) ?" ) ;
if ( a =='n' || a =='N' ) return 0 ;
  
return 1 ;
}

int takingIntIntgr (const char * mesag ,int my_Min ,int my_Max )
{
int fine =0 ,val =0 ;
while (!fine )
{
printf ( mesag ) ; fflush (stdout ) ;
if (scanf (" %d " ,&val ) ==1 &&getchar ( ) ==' ') fine =1 ;
else
{
printf (" Integer I/P only here please ") ;
while (getchar ( ) !=' ');
}
if ( fine && (val < my_Min ||val > my_Max))
{
fine =0 ;
printf (" Valid I/P only in range %d .. %d " ,my_Min ,my_Max) ;
}
}
return val ;
}

float takingIntFlot (const char * mesag ,float my_Min ,float my_Max)
{
int fine =0 ;
float val =0 ;
while (!fine )
{
printf ( mesag ) ; fflush (stdout) ;
if (scanf (" %f " ,&val) ==1 && getchar ( ) ==' ') fine =1 ;
else
{
printf (" Numbers only here please ") ;
while (getchar ( ) !=' ' );
}
if (fine &&(val <my_Min ||val >my_Max))
{
fine =0 ;
printf (" Valid I/P only in range %.1f .. %.1f " ,my_Min ,my_Max) ;
}
}
return val ;
}

char * takingInStrMaxLngth (const char * mesag ,unsigned max_Length )
{
char * p =NULL ;
for ( ; ; )
{
fputs ( mesag , stdout) ; fflush ( stdout) ;
p = readLine( stdin ) ;
if (p[0] &&strlen (p) <=max_Length)
break ;
else if (!p[0]) printf (" Blank line NOT valid input here ") ;
else printf (" For'%s' ,max len of %u char's was exceeded " ,p ,max_Length) ;
free (p) ;
}
return p ;
}

void takingInRecord ( Record * rec ,int i)
{
char buffe[132] ;
sprintf (buffe ," Enter first Names of student %d : " ,i + 1) ;
rec -> firstNames = takingInStrMaxLngth (buffe , 20) ;
sprintf (buffe ," Enter last Names of student %d : " ,i + 1 ) ;
rec -> lastNames = takingInStrMaxLngth (buffe ,20) ;
sprintf (buffe ," Enter myScores for student %d : " ,i + 1) ;
rec -> myScores = takingIntFlot (buffe ,0 ,100) ;
}

int showMenuChoice ( )
{
putchar (' ') ;
printf (" <1>Print all records ") ;
printf (" <2> Add new records ") ;
printf (" <3> Delete all records with a specified last name ") ;
printf (" <4> Find all records with a specified last name ") ;
printf (" <5> Sort by myScores ") ;
printf (" <6> Sort by last name ") ;
printf (" <7> Find median myScores ") ;
printf (" <0> Exit the program ") ;
return takingIntIntgr (" Pleasee enter choice in range 0 .. 7: " ,0 ,7) ;
}

int findL_Name (const Cvec * cv ,const char * name ,int lastIndx)
{
int i =lastIndx ;
for ( ;i >=0 ;-- i)
{
if (strcmp (cv -> arr[i].lastNames ,name) ==0 )return i ;
}
return -1 ;
}

int findmyScores (const Cvec * cv ,float myScores)
{
int i =0 ;
for (;i <cv -> size ;++i)
{
if (fabs (cv -> arr[i].myScores -myScores ) <EPSILON )return i ;
}
return -1 ;
}

int deleteIndx (Cvec * cv ,int index)
{
eraseCvec (cv ,index) ;
return cv -> size ;
}

float median (const Cvec * cv)
{
int i =cv -> size ;
if (i)
{
if (i ==1 )return cv -> arr[0].myScores ;
if (( i %2) ==0)
{
i/ =2 ;
return (cv -> arr[i].myScores +cv -> arr[ i - 1 ].myScores) /2.0 ;
}
i/ =2 ;
return cv -> arr[i].myScores;
}
printf (" No median since no myScores ") ;
return 0 ;
}

int main ( )
{
int i ,quit =0 ;
Record rec ;
Cvec cv ;
initCvec (&cv) ;
printf (" Welcome to the Student Records Information Sytem ") ;
  
for (i =0 ;;)
{
takingInRecord (&rec ,i ) ;
push_backCvec (&cv ,&rec ) ;
++i ;
if (!additional ( )) break ;
}
do
{
int choice =showMenuChoice ( ) ;
switch ( choice )
{
case 1 :
dispC_vec (&cv ) ;
break ;
case 2 :
for (;;)
{
takingInRecord (&rec ,i) ;
push_backCvec (&cv ,&rec) ;
++i ;
if (!additional( )) break ;
}
break ;
case 3 :
{
char * ln= takingInStrMaxLngth (" Enter last Names to find : " ,20 ) ;
int k =findL_Name (&cv ,ln ,cv.size - 1) ;
int found =( k !=-1) ;
while (k !=-1 )
{
printf (" Found name :%s at index %d " ,ln ,k) ;
  
if (tolower ( takingIntChar(" Delete( yes / no )?" ) ) =='y')
{
i =deleteIndx (&cv ,k) ;
printf (" Deleted ok ") ;
}
else printf (" Ok. NOT deleted ");
k =findL_Name (&cv ,ln ,k - 1) ;
}
if (!found)
printf ( " Name %s was NOT found " ,ln) ;
free (ln) ;
}
break ;
case 4 :
{
char * ln =takingInStrMaxLngth (" Enter last name to find : " ,20) ;
int k =findL_Name (&cv ,ln ,cv.size - 1) ;
int found=( k !=-1 ) ;
while (k !=-1)
{
printf (" Found name %s at index %d " ,ln ,k) ;
k =findL_Name (&cv ,ln ,k - 1) ;
}
if (!found)
printf (" Name %s was NOT found" ,ln) ;
putchar (' ') ;
free (ln) ;
}
break ;
case 5 :
msortCvec (&cv ,cmpMyScores) ;
dispC_vec (&cv) ;
break ;
case 6:
msortCvec (&cv ,cmpL_Names) ;
dispC_vec (&cv) ;
break ;
case 7:
  
msortCvec (&cv ,cmpMyScores) ;
dispC_vec (&cv) ;
printf (" Median myScores was %.1f " ,median (&cv)) ;
printf ( " There are %d student(s) above this myScores. " ,cv.size / 2) ;
break;
case 0:
printf (" Quiting " ) ;
quit =1 ;
break ;
default:
printf (" Invalid choice ") ;
}
}
while ( !quit ) ;
clearCvec (&cv) ;
return 0 ;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote