1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

hi.....programmers!......

Discussion in 'Meet and Greet' started by gamperz1986, Feb 28, 2011.

  1. gamperz1986

    gamperz1986 New Member

    Joined:
    Feb 28, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    STUDENT/ELECTRONIC TECHNICIAN
    Location:
    TRINIDAD & TOBAGO....ARIMA
    hi.....fellow pfogrammers!.....my name is shiva harrinanan and i'm a first year computer science student at uwi....i'm a bit green with respect to this field but its an interesting field and i really want to become part of it.....
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    1
    Trophy Points:
    0
    Hi Shiva and welcome to the forum
     
  3. gamperz1986

    gamperz1986 New Member

    Joined:
    Feb 28, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    STUDENT/ELECTRONIC TECHNICIAN
    Location:
    TRINIDAD & TOBAGO....ARIMA
    Re: hi.....programmers!......need some help below

    Code:
    #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]);
    }
     
  4. gamperz1986

    gamperz1986 New Member

    Joined:
    Feb 28, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    STUDENT/ELECTRONIC TECHNICIAN
    Location:
    TRINIDAD & TOBAGO....ARIMA
    i really need some help....i'm stuck.....
     
  5. gamperz1986

    gamperz1986 New Member

    Joined:
    Feb 28, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    STUDENT/ELECTRONIC TECHNICIAN
    Location:
    TRINIDAD & TOBAGO....ARIMA
    basically i wanna write a simple C program of student management system using an array of structures...it suppose to give the user some options but as you can see, i'm fresh out of ideas...any input will be deeply appreciated...thanks
     

Share This Page