Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (6 votes)
See more:
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]; // student ID
char fName[30]; // student's first name
char lName[30]; // student's last name
int m, p, c; // m = maths, p = physics, c = chemistry
// m, p, and c belong to the range [0..10]
double avg; //average mark with 1 digit after decimal point


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];   // student ID
   char   fName[30]; // student's first name
   char   lName[30]; // student's last name
   int    m, p, c;   // m = maths, p = physics, c = chemistry
   // m, p, and c belong to the range [0..10]
   double avg; //average mark with 1 digit after decimal point
};
//---------------------------------------------------------
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;     
      }
   } // while(op != 8)
   //system("pause");
   return 0;
}
//---------------------------------------------------------
Student input1Student()
{
   Student x;
   printf("Student ID: ");
   scanf("%s", x.sId);
   fflush(stdin); // clear '\n' in buffer
   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); // clear '\n' in buffer
   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!...
Posted
Updated 19-Apr-11 1:06am
v2
Comments
E.F. Nijboer 19-Apr-11 7:16am    
About your question. First, the title isn't the best since it doesn't really says what the problem is about. Second, it looks like homework and nobody will do that for you. Also, people are willing to help you (even if it is homework) but you must have a specific problem when trying something and you get stuck. Simply asking for complete solutions won't get you anything unless you are willing to pay or hire people, but then again this ain't the right place for that either. So, try yourself and when you run into trouble you can ask about it here and you just might get the help you need.
Ashish Tyagi 40 19-Apr-11 13:52pm    
Good advice, Let them (at-least)try ;)
Then I did not get what you want now?You want us to complete the remaining?

1 solution

This question was posted with a different user ID yesterday.
 
Share this answer
 
Comments
Hans Dietrich 19-Apr-11 9:39am    
Maybe two people in the same class? :)
Albert Holguin 19-Apr-11 9:49am    
noticed this as well... with the same exact code
Sergey Alexandrovich Kryukov 19-Apr-11 16:34pm    
It happens all the time!
I can imagine the school where they get assignments like that.
And all those people will try to works with us when they graduate!
--SA
Sergey Alexandrovich Kryukov 19-Apr-11 16:34pm    
(My 5)
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900