Thread: rank

  1. #1
    Registered User
    Join Date
    Apr 2012
    Location
    Kingston, Jamaica, Jamaica
    Posts
    9

    rank

    How do i store students data in 6 different files. show the time they arrive for school. rank them by there grades. student's data must be store using a structure

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    #include<stdhomework.h>
    That's pretty much all you need for this. Isn't C great?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Apr 2012
    Location
    Kingston, Jamaica, Jamaica
    Posts
    9
    so what else u need to do

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    We try to help people with actual code. If you REALLY have no idea, then you need to review your chapters in the book, along with your class notes, and other programs you've written. The C tutorial link near the top of the forum, may be a big help, as well.

    It's disconcerting to have someone ask for help to overhaul their car's engine, when you find out they barely know a screwdriver from a socket.

    In any case, if you want help with pseudo code, post what you have, and ask specific questions about what you need help with. If you want help with a program, post your code, and ask specific questions so we know what you're stuck on.

    But we don't take an assignment and start writing up code for people.

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Read the Homework announcement.

    > so what else u need to do
    Dumbass.

  6. #6
    Registered User
    Join Date
    Apr 2012
    Location
    Kingston, Jamaica, Jamaica
    Posts
    9
    clam down memcpy

  7. #7
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    Do you want the data stored in one Structure, then distributed to 6 different files?

  8. #8
    Registered User
    Join Date
    Apr 2012
    Location
    Kingston, Jamaica, Jamaica
    Posts
    9
    yep i do

  9. #9
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    Where is the data coming from, is the user supposed to enter in all the data and then you store it?

  10. #10
    Registered User
    Join Date
    Apr 2012
    Location
    Kingston, Jamaica, Jamaica
    Posts
    9

    check this out tell me wat u think

    Code:
    #include<stdio.h>
    #include<time.h>
    #include<math.h>
    int avg(int x, int y, int a);//Funcation prototype to find average
    int oavg(int x, int y, int b, int a);// Function prototype to the overall grade average
        /*student data Structure definition*/
    struct studentdata{   
          float egrade;//Students english grade for term 1
          float mgrade;//Students math grade for term 1
          float egrade1;//Students english grade for term 2
          float mgrade1;//Students math grade for term 2
          float egrade2;//Students english grade term 3
          float mgrade2;//Students math grade  term 3
          char sex[9];//Gender
          char fname[30];//first name
          char lname[30];//last name
          int age;//Age
          int schfee;//School fee payment
          char pa[2];//To show pm or am
          int late;//The amount time student was late
          int abs;//Amount time student was abscent
          float z;//Use to hold the values of the averages when calculating the averages
          float a1;//Term 1 average grade
          float a2;//Term 2 average grade
          float a3;//Final term average grade
          float oga;//Overll grade averAge 
          int id;//Identification Number
          };
    
     int main(void)
    {
         
        FILE *gradeI;
        FILE *gradeII;
        FILE *gradeIII;
        FILE *gradeIV;
        FILE *gradeV;
        FILE *gradeVI;
      
      int i=0;  
     struct studentdata student;//Declaration of structure student data as student
     char pa;
     
     int m;   
     int hours;
     int minutes; 
        
        if ((gradeI=fopen("Grade 1 Students.dat","w"))==NULL){
            printf("File could not be opened\n");
            }
        if((gradeII=fopen("Grade 2 Students.dat","w"))==NULL){
            printf("File could not be opened\n");
            }
        if((gradeIII=fopen("Grade 3 Students.dat","w"))==NULL){
            printf("File could not be opened\n");
            }
        if((gradeIV=fopen("Grade 4 Students.dat","w"))==NULL){
            printf("File could not be opened\n");
            } 
        if((gradeV=fopen("Grade 5 Students.dat","w"))==NULL){
            printf("File could not be opened\n");
            }                 
        if((gradeVI=fopen("Grade 6 Students.dat","w"))==NULL){
            printf("File could not be opened\n");
            }
            else{
                 student.id=1000;
                 fprintf(gradeI,"\t\t##################################\n"
                               "\t\t####   Grade I STUDENTS DATA   ###\n"
                               "\t\t##################################\n");
                fprintf(gradeII,"\t\t##################################\n"
                               "\t\t####   Grade II STUDENTS DATA  ###\n"
                               "\t\t##################################\n");
                fprintf(gradeIII,"\t\t#################################\n"
                                 "\t\t#### Grade III STUDENTS DATA  ###\n"
                                 "\t\t#################################\n");
                fprintf(gradeIV,"\t\t##################################\n"
                                "\t\t#### Grade IV STUDENTS DATA   ####\n"
                                "\t\t##################################\n"); 
                fprintf(gradeV,"\t\t##################################\n"
                               "\t\t####  Grade V STUDENTS DATA    ###\n"
                               "\t\t##################################\n");
                fprintf(gradeVI,"\t\t##################################\n"
                                "\t\t#### Grade VI STUDENTS DATA  #####\n"
                                "\t\t##################################\n");
                 printf("enter the amount of students data you are entring into the progam:");
                 scanf("%d",&m);
      while(m!= 0){
                i++;
                  
      m--;
      system("color a3");
                 printf("\nEnter first and last name:");
                 scanf("%s %s",student.fname,student.lname);
                 printf("Enter age:");
                 scanf("%d",&student.age);
                 printf("Enter Gender:");
                 scanf("%s",student.sex);
                         
                 printf("\n*****Term One*****\n");
                 printf("Enter student average English Grade:");
                 scanf("%f",&student.egrade);
                 printf("Enter Student average Math Grade:");
                 scanf("%f",&student.mgrade);
                         
                 printf("\n*****Term two*****\n");
                 printf("Enter student average English Grade:");
                 scanf("%f",&student.egrade1);
                 printf("Enter Student average Math Grade:");
                 scanf("%f",&student.mgrade1);
                         
                 printf("\n*****Final Term*****\n");
                 printf("Enter student average English Grade:");
                 scanf("%f",&student.egrade2);
                 printf("Enter Student average Math Grade:");
                 scanf("%f",&student.mgrade2);
                         
                 printf("Enter amount paid for school:");
                 scanf("%d",&student.schfee);
                /* printf("Enter the times student arrives at in standard time:");
                 scanf("%d",&hours,&minutes,pa);*/
                 printf("How many times student was late for school?:");
                 scanf("%d",&student.late);
                 printf("How many time student was absecnt for school?:");
                 scanf("%d",&student.abs);
                 
                        
    student.a1=avg(student.egrade,student.mgrade,student.z);
    student.a2=avg(student.egrade1,student.mgrade1,student.z);
    student.a3=avg(student.egrade2,student.mgrade2,student.z);
    student.oga=oavg(student.a1, student.a2, student.a3,student.z);            
     
                
                 system("cls"); 
                       
                                      
                                          
                        switch(student.age){                                                       
            case 6: 
            fprintf(gradeI,"***************************************************************\n");                
            fprintf(gradeI,"****ID#:%d\n"
                           "****First Name:%s\n"
                           "****Last Name:%s \n"
                           "****Age:%d\n"
                           "****Gender:%s\n",student.id+i,student.fname,student.lname,student.age,student.sex);
                    //scanf("%d%s%s%d",&i,student.fname,student.lname,&student.age);
            fprintf(gradeI,"****           Student school grade information\n"); 
            fprintf(gradeI,"****Term 1 average grade is %.2f\n"
                           "****Term 2 average grade is %.2f\n"
                           "****Final term Average is %.2f\n"
                           "****Overall grade avergae for the school year is %.2f\n",student.a1,student.a2,student.a3, student.oga);
            fprintf(gradeI,"****\n****           Information on the arrival time for the day\n"
                           "****Time:%d:%d%s\n",hours,minutes,pa);
                            if(student.oga>=80){
            fprintf(gradeI,"****\n****Student Receives Cash Prize becauuse for High End Year Grade average\n");
                                                       }
                            if (student.schfee!=7500){
            fprintf(gradeI,"****\n****Parent/s or guardian/s need to be call in concerning the school fee\n");
                                                       }
            fprintf(gradeI,"***************************************************************\n\n");
                    break;
             case 7:
            fprintf(gradeII,"\n\n***************************************************************\n");                          
            fprintf(gradeII,"****ID#:%d\n"
                            "****First Name:%s\n"
                            "****Last Name:%s\n"
                            "****Age:%d\n"
                            "****Gender:%s\n",student.id+i,student.fname,student.lname,student.age,student.sex);
            fprintf(gradeII,"****              Student school grade information\n"); 
            fprintf(gradeII,"****Term 1 average grade is %.2f\n"
                            "****Term 2 average grade is %.2f\n"
                            "****Final term Average is %.2f\n"
                            "****Overall grade avergae for the school year is %.2f\n",student.a1,student.a2,student.a3, student.oga);
             fprintf(gradeII,"****\n****           Information on the arrival time for the day\n"
                             "****Time:%d:%d%s\n",hours,minutes,pa);  
                             if(student.oga>=80){
            fprintf(gradeII,"****\n****Student Receives Cash Prize becauuse for High End Year Grade average\n");
                                                       }
                            if (student.schfee!=7500){
            fprintf(gradeII,"****\n****Parent/s or guardian/s need to be call in concerning the school fee\n");
                                                       }                             
            fprintf(gradeII,"***************************************************************\n\n");                  
                    break;
            case 8:  
            fprintf(gradeIII,"\n\n**************************************************************\n");                      
            fprintf(gradeIII,"****ID#:%d\n"
                             "****First Name:%s\n"
                             "****Last Name:%s\n"
                             "****Age:%d\n"
                             "****Gender:%s\n",student.id+1,student.fname,student.lname,student.age,student.sex);
            fprintf(gradeIII,"****              Student school grade information\n");
            fprintf(gradeIII,"****Term 1 average grade is %.2f\n"
                             "****Term 2 average grade is %.2f\n"
                             "****Final term Average is %.2f\n"
                             "****Overall grade avergae for the school year is %.2f\n",student.a1,student.a2,student.a3, student.oga);
            fprintf(gradeIII,"****           Information on the arrival time for the day\n"
                             "****Time:%d:%d%s\n",hours,minutes,pa);  
                            if(student.oga>=80){
            fprintf(gradeIII,"****\n****Student Receives Cash Prize becauuse for High End Year Grade average\n");
                                                       }
                            if (student.schfee!=7500){
            fprintf(gradeIII,"****\n****Parent/s or guardian/s need to be call in concerning the school fee\n");
                                                       }                                
            fprintf(gradeIII,"**************************************************************\n\n");                 
                    break;
             case 9:   
            fprintf(gradeIV,"**************************************************************\n");                       
            fprintf(gradeIV,"****ID#:%d\n"
                            "****First Name:%s\n"
                            "****Last Name:%s\n"
                            "****Age:%d\n"
                            "****Gender:%s\n",student.id+i,student.fname,student.lname,student.age,student.sex);               
            fprintf(gradeIV,"****                Student school grade information\n"); 
            fprintf(gradeIV,"****Term 1 average grade is %.2f\n"
                            "****Term 2 average grade is %.2f\n"
                            "****Final term Average is %.2f\n"
                            "****Overall grade avergae for the school year is %.2f\n",student.a1,student.a2,student.a3, student.oga);
            fprintf(gradeIV,"****\n****          Information on the arrival time for the day\n"
                            "****Time:%d:%d%s\n",hours,minutes,pa);
                            if(student.oga>=80){
            fprintf(gradeIV,"****\n****Student Receives Cash Prize becauuse for High End Year Grade average\n");
                                                       }
                            if (student.schfee!=7500){
            fprintf(gradeIV,"****\n****Parent/s or guardian/s need to be call in concerning the school fee\n");
                                                       }                                 
            fprintf(gradeIV,"**************************************************************\n\n"); 
                    break;
            case 10:   
            fprintf(gradeV,"***************************************************************\n");                       
            fprintf(gradeV,"****ID#:%d\n"
                           "****First Name:%s\n"
                           "****Last Name:%s\n"
                           "****Age:%d\n"
                           "****Gender:%s\n",student.id+i,student.fname,student.lname,student.age,student.sex);               
            fprintf(gradeV,"****                 Student school grade information\n"); 
            fprintf(gradeV,"****Term 1 average grade is %.2f\n"
                           "****Term 2 average grade is %.2f\n"
                           "****Final term Average is %.2f\n"
                           "****Overall grade avergae for the school year is %.2f\n",student.a1,student.a2,student.a3, student.oga);
            fprintf(gradeV,"****\n****          Information on the arrival time for the day\n"
                           "****Time:%d:%d%s\n",hours,minutes,pa);    
                            if(student.oga>=80){
            fprintf(gradeV,"****\n****Student Receives Cash Prize becauuse for High End Year Grade average\n");
                                                       }
                            if (student.schfee!=7500){
            fprintf(gradeV,"***\n****Parent/s or guardian/s need to be call in concerning the school fee\n");
                                                       }                    
            fprintf(gradeV,"***************************************************************\n\n"); 
                    break;
            case 11:
            case 12:
            fprintf(gradeVI,"\n\n***************************************************************\n");                         
            fprintf(gradeVI,"****ID#:%d\n"                                                     
                            "****First Name:%s\n"
                            "****Last Name:%s\n"
                            "****Age:%d\n"
                            "****Gender:%s\n",student.id+i,student.fname,student.lname,student.age,student.sex);
            fprintf(gradeVI,"****                 Student school grade information\n"); 
            fprintf(gradeVI,"****Term 1 average grade is %.2f\n"
                            "****Term 2 average grade is %.2f\n"
                            "****Final term Average is %.2f\n"
                            "****Overall grade avergae for the school year is %.2f\n",student.a1,student.a2,student.a3, student.oga);
            fprintf(gradeVI,"****\n****        Information on the arrival time for the day\n"
                             "****Time:%d:%d%s\n",hours,minutes,pa); 
                            if(student.oga>=80){
            fprintf(gradeVI,"****\n****Student Receives Cash Prize becauuse for High End Year Grade average\n");
                                                       }
                            if (student.schfee!=7500){
            fprintf(gradeVI,"****\n****Parent/s or guardian/s need to be call in concerning the school fee\n");
                                                       }                  
            fprintf(gradeVI,"***************************************************************\n\n");                 
                    break;
                 
                    default:
                        printf("Age is not suitable for the primary  school.");
                        break;
             system("cls");            
                        }           
                        }
                         fclose(gradeI);
                         fclose(gradeII);
                         fclose(gradeIII);
                         fclose(gradeIV);
                         fclose(gradeV);
                         fclose(gradeVI);
                         }
                         
                          getch();
                          return 0;
        }
        
    int avg(int x, int y, int a){
          
          a=(x+y)/2;
           }
    int oavg(int x, int y, int b, int a){
          
          a=(x+y+b)/3;
           }
    Last edited by Salem; 04-25-2012 at 09:48 PM. Reason: Removed the php pointless tag

  11. #11
    Registered User
    Join Date
    Apr 2012
    Location
    Kingston, Jamaica, Jamaica
    Posts
    9
    yes thats the plan

  12. #12
    Registered User
    Join Date
    Apr 2012
    Location
    Kingston, Jamaica, Jamaica
    Posts
    9
    yes it is comming from the user

  13. #13
    Registered User
    Join Date
    Apr 2012
    Location
    Kingston, Jamaica, Jamaica
    Posts
    9
    How do i put a function prototype and definition within this program to rank the students base on there grades

  14. #14
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    Where did you get that code from?

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Did you copy/paste the code from case 6 to case 7 ?

    Was the only edit to change gradeI into gradeII ?

    If so, then make it a function where you pass say
    outputRecord( gradeI, student );

    and make the code a hell of a lot shorter into the process.
    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. position vs rank in adt?
    By c_weed in forum Tech Board
    Replies: 2
    Last Post: 02-21-2012, 05:58 PM
  2. Calculate the rank of poker game
    By Salemaccess in forum C Programming
    Replies: 3
    Last Post: 12-21-2011, 12:30 AM
  3. Help with my Taxi Rank Code
    By DP1990 in forum C Programming
    Replies: 6
    Last Post: 03-06-2011, 10:14 AM
  4. How can i rank grades?
    By Lopen007 in forum C++ Programming
    Replies: 3
    Last Post: 03-08-2008, 08:29 AM
  5. My book recommendations for rank beginners ...
    By snakum in forum C++ Programming
    Replies: 4
    Last Post: 08-21-2002, 10:38 AM