Logo 
Search:

C++ Programming Forum

Ask Question   UnAnswered
Home » Forum » C++ Programming       RSS Feeds

HI....CAN SOME1 PLEASE HELP ME!!! PLEASE...

  Asked By: Poonka    Date: Apr 18    Category: C++ Programming    Views: 1027
  

*****THE PROBLEM IS THAT I'M HAVE SOME SERIOUS DIFFICULTIES IN IMPLEMENTING THE FUNCTIONS!******************************

I have to write a simple C program of student management system using an array of structures or parallel arrays. It should also have the following outputs:

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

The program allows a user to select a desired functionality by pressing an integer from 1 to 8.

• 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 what i have done so far,please help me because i have problems in implementing functions 3 to 7

#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]);
}
//---------------------------------------------------------

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on HI....CAN SOME1 PLEASE HELP ME!!! PLEASE... Or get search suggestion and latest updates.




Tagged: