Student Grade Program

This is a discussion on Student Grade Program within the C Programming forums, part of the General Programming Boards category; I have created a student grading program that should allow me to enter gades ansd also sort according to date, ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    8

    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.

    Code:
    /* 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();
    
    main()
    {
       char buffer[50];
       double total;
       for (i=0; i<N_student; i++)
       {
    	printf("Enter Student ID no: \n");
     	 gets(students[n].id);
    	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;
    	assigngrade();
       }
    	printf("You've entered the students details. \n");
    
    	printavg();
        system("PAUSE");
    return 0;
    }
    
    void assigngrade()
    {
        if ((students[n].av_marks<=4) && (students[i].av_marks>3))
    		{
    		students[i].grade='A';
    		}
        else if ((students[i].av_marks<=3) && (students[i].av_marks>2))
    		{
    		students[i].grade='B';
    		}
        else if ((students[i].av_marks<=2) && (students[i].av_marks>1))
    		{
    		students[i].grade='C';
    		}
        else if ((students[i].av_marks<=1)	 && (students[i].av_marks>=0))
    		{
    		students[i].grade='D';
    		}
    }
    
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 03:48 PM
  3. sorting output on student info program
    By indigo0086 in forum C++ Programming
    Replies: 2
    Last Post: 11-05-2002, 10:29 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21