Thread: Student Grade Program

  1. #1
    Registered User
    Join Date
    May 2004

    Student Grade Program

    I have created a student grading program that should allow me to enter gades ansd also sort according to date, oldest first. The code supplied is a different version compared to the earlier one.

    /* Question 3. It describes a student using structures and arrays to
    store and print data */
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <string.h>
    #define N_student 4
    int i,n;
    struct student
     char id[5];
     char name[50];
     double Bday,Bmonth,Byear;
     double mark1, mark2, mark3;
     double av_marks;
     char grade;
    } students [N_student];
    void assigngrade();
    void printavg();
       char buffer[50];
       double total;
       for (i=0; i<N_student; i++)
    	printf("Enter Student ID no: \n");
    	printf("Enter Student name: \n");
    	 gets (students[n].name);
    	printf("Enter Date Of Birth (dd):");
    	gets (buffer);
        students[n].Bday = atof (buffer);
    	printf("Enter Month Of Birth (mm):");
    	gets (buffer);
        students[n].Bmonth = atof (buffer);
    	printf("Enter Year Of Birth (yyyy):");
    	gets (buffer);
        students[n].Byear = atof (buffer);
    	printf("Enter marks obtained for test1(0-4): \n");
    	 gets (buffer);
             students[n].mark1 = atof (buffer);
    	printf("Enter marks obtained for test2(0-4): \n");
    	 gets (buffer);
             students[n].mark2 = atof (buffer);
    	printf("Enter marks obtained for test3(0-4): \n");
    	gets (buffer);
            students[n].mark3 = atof (buffer);
        total = (double)students[n].mark3 + (double)students[n].mark2 + (double)students[n].mark1;
    	students[n].av_marks = (double)total/3;
    	printf("You've entered the students details. \n");
    return 0;
    void assigngrade()
        if ((students[n].av_marks<=4) && (students[i].av_marks>3))
        else if ((students[i].av_marks<=3) && (students[i].av_marks>2))
        else if ((students[i].av_marks<=2) && (students[i].av_marks>1))
        else if ((students[i].av_marks<=1)	 && (students[i].av_marks>=0))
    void printavg()        /* prints the average grade for a student */
    for (i=0; i<N_student; i++)
    	printf ("Student Id=");
    	printf ("%s\n",students[i].id);
    	printf ("Student Name=");
    	printf ("%s\n",students[i].name);
    	printf ("Student Average marks=");
    	printf ("%.2f\n",students[i].av_marks);
    	printf ("Student Grade=");
    	printf ("%c\n",students[i].grade);
    Right now the question is how do i sort according to date, oldest first?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    There must be hundreds of examples of sorting on the board - try a search
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. grade program code
    By jd7joe in forum C++ Programming
    Replies: 8
    Last Post: 11-18-2005, 04:48 PM
  3. sorting output on student info program
    By indigo0086 in forum C++ Programming
    Replies: 2
    Last Post: 11-05-2002, 11:29 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM