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

Problem 1- Write an application, mainl.c create a student structure read in stud

ID: 3839647 • Letter: P

Question

Problem 1- Write an application, mainl.c create a student structure read in student data from "student.txt", which is provided the data include student name, student id, student major and student grade level create a loop in which the user is prompted for the following options: a. print out all the student's data (this task shall be a function) b. print out all Seniors student information. c. print out all Computer major student information. d. Exit program use a switch statement to perform the options tasks #include

Explanation / Answer

/* Include necessary header files */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

/* Define required symbolic constants */
#define MAXCHR 40
#define MAXSTUDENT 15

/* Student structure */
struct student
{
   char name[MAXCHR];
   long id;
   char major[MAXCHR];
   char level[MAXCHR];
};

/* Function to print the details of all the students */
int printStudents(struct student students[],int numStudents)
{
   int i;
   for(i=0;i<numStudents;i++)
   {
       printf("%-15s%-15ld%-15s%-15s ",students[i].name,students[i].id,students[i].major,students[i].level);
   }
   return 1;
}


int main()
{
   FILE *fpIN;
   /* Array of students */
   struct student students[MAXSTUDENT];

   /* To hold first name */
   char fName[MAXCHR];

   /* To hold last name */
   char lName[MAXCHR];
   int i = 0;
   int numStudents = 9;
   int choice = 0;

   clrscr();

   /* Open the student.txt file in read mode */
   fpIN = fopen("student.txt","r");

   /* Read the details of all students from student.txt file */
   for(i=0;i<9;i++)
   {
       fscanf(fpIN,"%s%s%ld%s%s ",fName,lName,&students[i].id,students[i].major,students[i].level);

       /* Concatenate the first and the last name of each student to get name */
       strcpy(students[i].name,strcat(strcat(fName," "),lName));
   }

   do
   {
       /* Display Menu */
       printf(" ****************Menu****************** ");
       printf(" 1.All Students Data. 2.All Senior studentinformation. 3.All computer major Students. 4.Exit ");
       printf(" ************************************** ");

       /* Prompt the user for a choice */
       printf("Enter your choice:(1-4) ");

       /* Read the choice from the user */
       scanf("%d",&choice);

       /* Display details as per the user's choice */
       switch(choice)
       {
                   /* Display all details of all the students */
           case 1:   printStudents(students,numStudents);
                   break;

                   /* Display the details of all Senior students */
           case 2: for(i=0;i<numStudents;i++)
                   {
                       if(!strcmp(students[i].level,"Senior"))
                       {
                           printf("%-15s%-15ld%-15s%-15s ",students[i].name,students[i].id,students[i].major,students[i].level);
                       }
                   }
                   break;

                   /* Display the details of Computer students */
           case 3: for(i=0;i<numStudents;i++)
                   {
                       if(!strcmp(students[i].major,"Computer"))
                       {
                           printf("%-15s%-15ld%-15s%-15s ",students[i].name,students[i].id,students[i].major,students[i].level);
                       }
                   }
                   break;

                   /* Exit out of the porogram */
           case 4: exit(0);
       }

   }while(choice!=4);
   return 1;
}

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