I need to write a simple C program of student management system using an array of structures or parallel arrays.
I have started the question but i have become lost and I'm having some problem in implementing some functions!
Given the following information:
char sId[10];
char fName[30];
char lName[30];
int m, p, c;
double avg;
The basic output of the program should be as follows:
1. Input student list
2. Output student list
3. Add a new student
4. Search a student by Id or last name
5. Delete a student with a given student Id
6. Update a student with a given student Id
7. Sort on last name or average mark
8. Exit
With regards to option 4 & 7 :
If the user presses the number 4, the program displays the following submenu
1. Search by Id
2. Search by last name
then the program waits for the user to enter a number 1 or 2 to perform the corresponding
task.
• If the user presses the number 7, the program displays the following submenu
1. Sort on last name
2. Sort on average mark
then the program waits for the user to enter a number 1 or 2 to perform the corresponding
task.
Below is the actual code that have been written but as you can see, I have been able to implement only 2 functions, can some one please help me?
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct Student
{
char sId[10];
char fName[30];
char lName[30];
int m, p, c;
double avg;
};
Student input1Student();
void output1Student(const Student &x);
void inputStudentList(Student list[], int &n);
void outputStudentList(const Student list[], const int &n);
int main(void)
{
int op = 0, op2 = 0;
int n = 0;
Student list[10];
while(op != 8)
{
printf("1. Input student list\n");
printf("2. Output student list\n");
printf("3. Add a new student\n");
printf("4. Search a student by Id or last name\n");
printf("5. Delete a student with a given student Id\n");
printf("6. Update a student with a given student Id\n");
printf("7. Sort on last name or average mark\n");
printf("8. Exit\n");
printf("Enter your option (1-8): ");
scanf("%d", &op);
switch(op)
{
case 1:
inputStudentList(list, n);
break;
case 2:
outputStudentList(list, n);
break;
case 3:
break;
case 4:
printf("\t1. Search by Id\n");
printf("\t2. Search by last name\n");
printf("Select an option (1 or 2): ");
scanf("%d", &op2);
break;
case 5:
break;
case 6:
break;
case 7:
printf("\t1. Sort on last name\n");
printf("\t2. Sort on average mark\n");
printf("Select an option (1 or 2): ");
scanf("%d", &op2);
break;
}
}
return 0;
}
Student input1Student()
{
Student x;
printf("Student ID: ");
scanf("%s", x.sId);
fflush(stdin);
printf("First name : ");
fgets(x.fName, 80, stdin);
x.fName[strlen(x.fName) - 1] = '\0';
printf("Last name : ");
fgets(x.lName, 80, stdin);
x.lName[strlen(x.lName) - 1] = '\0';
printf("Maths : ");
scanf("%d", &x.m);
printf("Physics : ");
scanf("%d", &x.p);
printf("Chemistry : ");
scanf("%d", &x.c);
fflush(stdin);
x.avg = (double)(x.m + x.p + x.c) / 3;
printf("------------------------------\n");
return x;
}
void output1Student(const Student &x)
{
printf("Student ID : %s\n", x.sId);
printf("First name : %s\n", x.fName);
printf("Last name : %s\n", x.lName);
printf("Maths : %d\n", x.m);
printf("Physics : %d\n", x.p);
printf("Chemistry : %d\n", x.c);
printf("Average mark : %.2f\n", x.avg);
printf("------------------------------\n");
}
void inputStudentList(Student list[], int &n)
{
int i = 0;
printf("Enter the number of students : ");
scanf("%d", &n);
for (i = 0; i < n; i++)
list[i] = input1Student();
}
void outputStudentList(const Student list[], const int &n)
{
int i = 0;
for (i = 0; i < n; i++)
output1Student(list[i]);
}
//---------------------------------------------------------
THE CODE IS WORKING SO YOU CAN COMPILE & RUN AND ANY HELP WILL BE DEEPLY APPRECIATED.....THANKS!...