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

Write a program in c Write a menu based program to maintain student records. You

ID: 3682920 • Letter: W

Question

Write a program in c

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) After user chooses a functionality, your program performs that and provides this menu again to select another functionality. This goes on until user presses 0.

Explanation / Answer

Example1-Sample code to store student information

#include <stdio.h>

struct student{

    char name[50];

    int roll;

    float marks;

};

int main(){

    struct student s[10];

    int i;

    printf("Enter information of students: ");

    for(i=0;i<10;++i)

    {

        s[i].roll=i+1;

        printf(" For roll number %d ",s[i].roll);

        printf("Enter name: ");

        scanf("%s",s[i].name);

        printf("Enter marks: ");

        scanf("%f",&s[i].marks);

        printf(" ");

    }

    printf("Displaying information of students: ");

    for(i=0;i<10;++i)

    {

     printf(" Information for roll number %d: ",i+1);

     printf("Name: ");

     puts(s[i].name);

     printf("Marks: %.1f",s[i].marks);

   }

   return 0;

}

Example2-program to create student structure having field roll_no, stud_name, mark1, mark2, mark3 calculate the total and average of marks and arrange the records in descending order of marks.

#include<stdio.h>

#include<conio.h>

void main()

{

struct student

{

int rollno;

char name[20];

int m1,m2,m3;

float percent;

};

struct student s[20],t;

int i,j,n;

clrscr();

printf(" enter the limit");

scanf("%d",&n);

for(i=0;i<n;i++)

{

printf(" enter the roll no ");

scanf("%d",&s[i].rollno);

printf(" enter the name ");

scanf("%s",s[i].name);

printf(" enter the mark=");

scanf("%d",&s[i].m1);

printf(" enter the mark=");

scanf("%d",&s[i].m2);

printf(" enter the mark=");

scanf("%d",&s[i].m3);

s[i].percent=(s[i].m1+s[i].m2+s[i].m3)/3;

}

for(i=0;i<n-1;i++)

{

for(j=i+1;j<n;j++)

{

if(s[i].percent<s[j].percent)

{

t=s[i];

s[i]=s[j];

s[j]=t;

}

}

}

printf(" display in desending order ");

for(i=0;i<n;i++)

{

printf(" rollno=%d",s[i].rollno);

printf(" name=%s",s[i].name);

printf(" mark1=%d",s[i].m1);

printf(" mark2=%d",s[i].m2);

printf(" mark3=%d",s[i].m3);

printf(" percent=%f",s[i].percent);

}

getch();

}

Example3-program for Student Database using Single linked list and perform search, Insert and delete operation for a particular register number.

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

struct student{

char name[100];

char roll[10];

struct student *next;

};

struct student *first=NULL,*last=NULL,*k;

void create(int n)

{

int i;

first=(struct student*)malloc(sizeof(struct student));

printf(" Enter the first name of the student:");

scanf("%s",first->name);

printf(" Enter the roll number of the student:");

scanf("%s",first->roll);

first->next=NULL;

last=first;

for(i=1;i {

k=(struct student*)malloc(sizeof(struct student));

printf(" Enter the first name of the student:");

scanf("%s",k->name);

printf(" Enter the roll number of the student:");

scanf("%s",k->roll);

k->next=NULL;

last->next=k;

last=k;

}

}

void display()

{

struct student *t;

t=first;

while(t!=NULL)

{

printf(" The roll number of the student:%s",t->roll);

printf(" First name of the student:%s",t->name);

t=t->next;

}

}

void insertafter()

{

char r[10];

int flag=0;

printf(" Enter the roll number u wanna insert after that:");

scanf("%s",r);

struct student *t;

t=first;

while(t!=NULL)

{

if(strcmpi(r,t->roll)==0)

{

k=(struct student*)malloc(sizeof(struct student));

printf(" Enter the first name of the student:");

scanf("%s",k->name);

printf(" Enter the roll number of the student:");

scanf("%s",k->roll);

k->next=t->next;

t->next=k;

flag=1;

break;

}

t=t->next;

}

if(flag==0)

printf(" The element not found!!!");

}

void del()

{

struct student *back,*t,*k;

char r[10];

int flag=0;

printf(" Enter the roll number u wanna delete:");

scanf("%s",r);

if(strcmpi(r,first->roll)==0)

{

first=first->next;

flag=1;

}

else

{

back=first;

k=first->next;

while(k!=NULL)

{

if(strcmpi(r,k->roll)==0)

{

back->next=k->next;

flag=1;

break;

}

}

}

if(flag==0)

printf(" The element not found!!!");

}

void search()

{

char r[10];

int flag=0;

printf(" Enter the roll number u wanna search:");

scanf("%s",r);

struct student *t;

t=first;

while(t!=NULL)

{

if(strcmpi(r,t->roll)==0)

{

printf(" The roll number found in the list!!! His name is %s",t->name);

flag=1;

break;

}t=t->next;

}

if(flag==0)

printf(" The roll number not in database!!");

}

int main()

{

int n,o;

while(o!=0)

{

printf(" MENU ");

printf(" Enter 1 for creating database");

printf(" Enter 2 for displaying database");

printf(" Enter 3 for inserting an record after another");

printf(" Enter 4 for deleting a record");

printf(" Enter 5 for searching a record");

printf(" Enter 0 for exit!");

printf(" Enter the choice:");

scanf("%d",&o);

switch(o)

{

case 1:printf(" Enter the maximum size of the database:");

scanf("%d",&n);

create(n);

break;

case 2:display();break;

case 3:insertafter();break;

case 4:del();break;

case 5:search();break;

case 0:exit(0);break;

default:printf(" You have entered a wrong choice!!!");

}

}

getch();

}

Example4-Student record management using files to write,sort,print and calculate.

#include<stdio.h>

int bubble(int*,int);

void filewrite();

void avgmarks();

void fileprint();

void filesort();

void rollin();

/*********************** SORTING FUNCTION ***************************/

int bubble(int x[],int n)

{

int hold,j,pass,i,switched = 1;

for(pass = 0; pass < n-1 && switched == 1;pass++)

{

switched=0;

for (j=0;j<n-pass-1;j++)

   if (x[j]>x[j+1])

   {

    switched=1;

    hold = x[j];

    x[j] = x[j+1];

    x[j+1]=hold;

    }

   }

return(0);

}

/*********************** FILE WRITING FUNCTION ******************************/

void filewrite()

{

int roll,ch,mark;

char nam[50];

   FILE *fp;

   clrscr();

fp = fopen("student.txt","a");

   printf("ENTER ROLL NUMBER, NAME , MARKS ");

ch =1;

while(ch)

{

scanf("%d%s%d",&roll,&nam,&mark);

fprintf(fp,"%d %s %d ",roll,nam,mark);

printf(" press 1 to continue,0 to stop");

scanf("%d",&ch);

}

   fclose(fp) ;

}

/******************** OUTPUTING DATA ON SCREEN***************/

void fileprint()

{

int marks[100],rollno[100],x[100],i;

char name[100][50];

FILE *fp;

clrscr();

fp = fopen("student.txt","r");

   i=0;

   printf("ROLLNO       NAME        MARK ");

   while(!feof(fp))

{

     fscanf(fp,"%d %s %d ",&rollno[i],&name[i],&marks[i]);

     printf(" %d          %s          %d ",rollno[i],name[i],marks[i]);

     i=i+1;

   }

   fclose(fp);

   printf(" PRESS ANY KEY");

   getch();

}

/******************* SORTING FILE ************************/

void filesort()

{ int marks[100],rollno[100],x[100],n,i,j;

    char name[100][50];

    FILE *fp,*fm;

    fp = fopen("student.txt","r");

    fm = fopen("marks.txt","w");

    i=0;

   while(! feof(fp))

    {

     fscanf(fp,"%d %s %d ",&rollno[i],&name[i],&marks[i]);

     x[i]= marks[i];

     i=i+1;

      }

       n=i;

       bubble(x,n);

    for(i=0;i<n;i++)

    {

    printf(" %d ",x[i]);

    }

for(i=0;i<n;i++)

{

   for (j=0;j<n;j++)

   {

   if(x[i]==marks[j])

   {

      fprintf(fm,"%d %s %d ",rollno[j],name[j],marks[j]);

     }

   }

}

fclose(fm);

fclose(fp);

printf(" PRESS ANY KEY");

getch();

}

/************************* DATA USING ROLLNO***************************/

void rollin()

{   int i,roll,ch,mark,roll1;

    char nam[50];

    FILE *fm;

    ch=1;

while(ch)

{ clrscr();

    fm = fopen("marks.txt","r");

    printf(" ENTER ROLL NUMBER - ");

    scanf("%d",&roll1);

      i=0;

   while(! feof(fm))

    {

     fscanf(fm,"%d %s %d ",&roll,&nam,&mark);

     if(roll1==roll)

    {printf(" ROLLNO.     NAME        MARKS ");

     printf(" %d          %s          %d ",roll,nam,mark);

     break;

     }

     else

     i=i+1;

      }

printf(" press 1 to see student info, 0 to return to main menu ");

scanf("%d",&ch);

fclose(fm);

}

}

void avgmarks()

{

    int marks[100],rollno[100],n,i;

    float avg,x;

    char name[100][50];

    FILE *fm;

    fm = fopen("marks.txt","r");

    i=0;

   while(! feof(fm))

    {

fscanf(fm,"%d %s %d ",&rollno[i],&name[i],&marks[i]);

     x = x + marks[i];

     i=i+1;

      }

     n = i;

   avg = x/n;

printf("AVERAGE MARKS OF %d STUDENTS ARE - %f ",n,avg);

fclose(fm);

printf(" PRESS ANY KEY");

   getch();

}

/**************** FUNC. ENDS************************/

void main()

{

int marks[100],rollno[100],x[100],n,i,j,roll,c,mark,roll1;

char name[100][10],nam[50];

while(c!=6)

   {

     clrscr();

     printf("GIVE CHOICE-- ");

     printf("   1 TO ENTER STUDENT INFO. ");

     printf("   2 TO SEE STUDENT.TXT FILE ");

     printf("   3 TO SORT FILE ON BASIS OF MARKS ");

     printf("   4 TO PRINT STUDENT INFO. USING ROLL NO ");

     printf("   5 TO FIND AVERAGE OF MARKS ");

     printf("   6 TO EXIT --");

     scanf("%d",&c);

     clrscr();

     switch(c)

     {

     case 1:

          filewrite();

          break;

     case 2:

          fileprint();

         break;

     case 3:

         filesort();

         break;

     case 4: rollin();

          break;

     case 5: avgmarks();

          break;

     case 6:

          break;

     default:

          break;

     }

    }

}

Note-the above code samples can help to solve the given question.

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