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

Write a program that works as a mini Student Registration System. The program wi

ID: 3571263 • Letter: W

Question

Write a program that works as a mini Student Registration System. The program will manipulate a list of students that are registering the course COMP2MM The list, which is stored in a file, contains for each student the student's ID, name, and section number. Thus, the program will perform the following operations on the list: Reads the student list from an input file whose name k provided by the user. The file opening must be checked before proceeding to the menu operations. Continuously displays a menu for the user until the user selects 'Q' (or 'q') to quit the program. The menu provides 3 options: Insert a Student (I or i), Section Count (Core), and Quit (Q or q). When the Insert a Student option is selected, the program should ask the user to provide all the information of the student and then add them to the list after validation The section number must be 10, 20, 30 or 40 only {assume the user will not center a student who is already in the list). When the Section Count option is selected, the program should ask the user to provide the section number that s/he wants to count its students. Again, if the user entered invalid section number then the program will display an error message. Once a valid number is entered, then the program will display the number of students from the specified section. When the Quit option is selected, the program will save the list back to the file and then terminate. Your program must call a function named insert (...) to perform the student insertion task. Also for the Section Count operation, the section number should be read and validated in the main program, then the function count(...) is called to determine the number of students in that section. The following diagrams show a sample input and a run-case that can be generated by the program.

Explanation / Answer

Hii,

Thanks for waiting. I have written the program according to the specifications and tried my best not to miss anything. You can copy/paste the program directly and save it to a file. Also create a .txt file for students data as given in the specification. Give the filename at the starting of the program, suppose if filename is "student_data.txt" in the program enter as "student_data.txt". You can just create an empty .txt file and keep adding datas.

Please do let me know if you don't understand the program. I have used file I/O and pointer manipulations, and also array structures. Those are pretty basic things if you have touch with C.

Program:

#include<stdio.h>

// structure to hold the student details
struct student{
int id;
char name[50];
int section;
};

// insert function declaration
void insert(struct student st_list[], int* c);

int main()
{
char str_filename[30]; // string to hold filename
printf("Enter the name of the input file: ");
scanf("%s",str_filename); // read filename
FILE *fp;
fp = fopen(str_filename,"r"); // open file and check if correct file
if(fp == NULL)
{
printf(" File not found. Aborting..."); // if error then abort
return 1;
}
struct student student_list[100]; // array of struct to hold max 100 items
int count=0; // count to keep track of number of students in list

fseek (fp, 0, SEEK_END);
int size = ftell (fp);
rewind(fp);

if(size!=0){
while(!feof(fp)) // read from file and hold the data in student_list array
{
fscanf(fp,"%d %s %d",&student_list[count].id,student_list[count].name,&student_list[count].section);
count++;
}
}
fclose(fp);
printf("Reading.......Finished");

char option; // char to hold option
do{ // do-while loop, looping continuously until q or Q is selected
printf(" --------Choose an option-------- I -> to insert a new student C -> to count student in a section Q -> to Quit");
printf(" Enter your choice: ");
fflush(stdin); // flush out any remaining character from input stream, used for error prevention
scanf("%c",&option);
int i;
switch(option){
case 'c':
case 'C':
printf(" >>>Section Count is selected<<<");
printf(" Enter the Section number: ");
int s;
scanf("%d",&s);
while(s!=10 && s!=20 && s!= 30 && s!=40) // validation of correct section number
{
printf(" Please enter the correct value: ");
scanf("%d",&s);
}
int sec_count=0; // variable to count students in a section
for(i=0;i<count;i++)
{
if(student_list[i].section==s)
sec_count++;
}
printf(" The number of students in section %d is %d",s,sec_count);
break;
case 'i':
case 'I':
printf(" >>>Insert a student is selected<<<");
insert(student_list,&count); // call the insert and pass parameters by reference to reflect in the main program
break;
case 'q':
case 'Q':
fp = fopen(str_filename,"w"); // open file for writing before exiting to save the student_list to file
for(i=0;i<count;i++)
{
if(i!=0)
fprintf(fp," ");
fprintf(fp,"%d %s %d",student_list[i].id,student_list[i].name,student_list[i].section);
}
fclose(fp);
printf(" >>>Saving to File and exiting from the program<<<");
break;
default:
printf(">>>Please select a valid option<<<"); // invalid option
}
}while((option != 'q') && (option != 'Q'));

return 0;
}

void insert(struct student st_list[], int* c)
{
int section;
printf(" Enter student id: ");
scanf("%d",&st_list[*c].id);
printf(" Enter student name: ");
scanf("%s",st_list[*c].name);
printf(" Enter student section:");
scanf("%d",&section);
while(section!=10 && section!=20 && section!= 30 && section!=40) // error checking of section value
{
printf(" Enter the correct value of section: ");
scanf("%d",&section);
}
st_list[*c].section=section;
(*c)++; // student count updated
printf(" MESSAGE: Student Added....!");
return;
}

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