Student Roster & Grade Average

This is a discussion on Student Roster & Grade Average within the C Programming forums, part of the General Programming Boards category; This is my final project for my C class. I am suppose to make a program that inputs first names ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Location
    Rockdale, IL
    Posts
    11

    Student Roster & Grade Average

    This is my final project for my C class.

    I am suppose to make a program that inputs first names and last names followed by the grades of recent tests. The output will come out as the first and last name in one word, with the last name first. And the grades will be calculated on an average. I'm not asking for a giveaway; I just need some sources.

    I would like to helped on these three concerns:
    - How to set up an Array
    - How to put together a Structure
    - What is a binary tree and how does it work?

    It will help me out a lot if you guys provide URLs to help me understand better. I just need these favors to get a good idea of how to start my project.

    Thank you.

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    1 & 2: Look on this site.
    3: Clicky.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    1 & 2: Look on this site.
    Arrays
    Struct
    One more link on Binary Tree

    ssharish2005

  4. #4
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Since I can't use your arrays link: arrays.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  5. #5
    Registered User
    Join Date
    Nov 2006
    Location
    Rockdale, IL
    Posts
    11
    Thank you guys.

    I went to my last C class before it was all done. Luckily, I was the only one that showed up to class on time. So the teacher and I got to talk face to face and here is what I understand: I need to work out my program in these steps.

    1. Create a structure that is made up of students and scores along with pointers such as leftp, rightp, and rootp. Each student has ten scores and the sum will be divided by ten to calculate the scores.

    2. Put together a printf and scanf section of code that lets the user input first name and last name along with grades in one line.

    3. Use the binary tree with the three pointers from #1 to list the names, putting last names in alpha order with their proper first name and average grade.

    I'll check the references out and work out my magic. Hopefully, I can turn in this project with no bugs before Wednesday, December 13th. I'll return if I have any accidents.

  6. #6
    Registered User
    Join Date
    Nov 2006
    Location
    Rockdale, IL
    Posts
    11
    I apologize for double-posting, but the interface won't allow me to edit my message. Sorry.

    Houston, we have a big problem on our hands.

    My program will not compile no matter how many methods I apply to declare my prototypes, strings, arrays, and structure. For some reason, the compiler will not accept studentone as a structure. To make manners even worse, this is my first time using a binary tree and this may make my program a complete mess.

    Code:
    /* Student Roster by MATT NICOLA */
    /* Final Project for Mike Fagan's Class */
    
    /* INTRODUCTION:
       The program was designed to input a number of students and sort them
       into an alphabetical list. Ten grades will be assigned to each student
       and the average will be found to complete a list of students and grades. */
       
    /* REFERENCE:
       Pg. 746 - Example of a Binary Tree
       Pg. 460 - How to make a list */
    
    #include <stdio.h>
    #include <stdlib.h>
    #define Allotype(type) (type *)malloc(sizeof (type))
    
    /* Set up a structure to work with the students and binary tree. */
    
       typedef struct student {     char Lastname[30];
                                    char Firstname[20];
                                    int Grade[10];
                                    struct student *rootp;
                                    struct student *leftp;
                                    struct student *rightp;
                                    struct student *tree_insert;
       } studentone;
    			            
    studentone *tree_insert(studentone *rootp, int new_pupil);
    void listall(studentone *rootp);
    
    /* The arrays will contain your students' first name, last name,
       and grades. These must be alphabetical by finish. */
    
    int
    main(void) {
    
    double student_limit,
           student_count,
           average;
    
    student_limit = 0;
    student_count = 0;
    average = 0;
       
       printf("Hello. Welcome to the student roster organizer.\n");
       printf("This program is designed to input your students and\n");
       printf("average their ten grades. Grades will be assigned\n");
       printf("with their proper students.\n\n");
       
       printf("Enter the number of students you wish to enter:");
       scanf("%lf", &student_limit);
       
       printf("\n\nNow for this part, enter the last name, enter the\n");
       printf("first name, and then enter 10 seperate numbers that\n");
       printf("determine the student's score.\n\n");
       printf("REMEMBER: Enter one student at a time and continue until\n");
       printf("the student limit has been reached.\n\n\n");
    
       while (student_count <= student_limit) {
             
             scanf("%c", studentone.Lastname);
             printf(" ");
             scanf("%c", studentone.Firstname);
             printf(" ");
             scanf("%d", studentone.Grade[0]);
             printf(" ");
             scanf("%d", studentone.Grade[1]);
             printf(" ");
             scanf("%d", studentone.Grade[2]);
             printf(" ");
             scanf("%d", studentone.Grade[3]);
             printf(" ");
             scanf("%d", studentone.Grade[4]);
             printf(" ");
             scanf("%d", studentone.Grade[5]);
             printf(" ");
             scanf("%d", studentone.Grade[6]);
             printf(" ");
             scanf("%d", studentone.Grade[7]);
             printf(" ");
             scanf("%d", studentone.Grade[8]);
             printf(" ");
             scanf("%d", studentone.Grade[9]);
       
    /* Each student will have 10 grades and they will present an average. */
    
             studentone.Grade[0-9] = average;
             average = average / 10;
             
             student_count = student_count + 1; }
    
       return(0); }
       
       
    /* The binary tree will soon follow and it will place the entries into
       alphabetical order. You might want to use an IF statement. */
    
    studentone *
    tree_insert (studentone *rootp,
                 int        new_pupil)
       
    {
       (if strcmp == -1)
             { rootp->leftp = tree_insert
               (rootp->rightp, new_student); }
       (else if strcmp == 0)
             {/* Nothing happens */}
       (else if strcmp == 1)
             { rootp->rightp = tree_insert
               (rootp->leftp, new_pupil); }
       (else)
             {rootp = Allotype(student);
              rootp = new_pupil
              rootp->leftp = NULL;
              rootp->rightp = NULL; }
              
       return (rootp);
       
    }
    Does anyone know why it won't compile or what would be a better way to access my structure?

  7. #7
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    studenttone is a type
    studentone.Lastname is illegal
    declare variable of the type
    studentone myStudent;
    and access memebr of the declared object
    myStudent.Lastnae
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,849
    > My program will not compile no matter how many methods I apply to declare my prototypes
    While you're still learning, type in just a few lines and then press compile.

    At each ; your program should be syntactically valid, and can be compiled. If you get more warnings and errors from just typing in 1 line, then you know what to look at.

    > scanf("%c", studentone.Lastname);
    These are strings, so %s is the conversion to use

    > scanf("%d", studentone.Grade[0]);
    Remember, everything except string input using scanf means you need & on all the values, like
    scanf("%d", &studentone.Grade[0]);
    Also, why not use a loop here?

    > studentone.Grade[0-9] = average;
    This isn't short-cut notation for a range of index values (use a loop).
    Also, you probably want average = ....

    > (if strcmp == -1)
    What's this - LISP ?
    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.

  9. #9
    Registered User
    Join Date
    Nov 2006
    Location
    Rockdale, IL
    Posts
    11
    With help of you guys, and a tutor, I have changed my code to the result of this so far. My tutor advised me that if I add in a section of code that helps process the binary tree, my alphabetical sorting will be easier.

    I shall try to shrik the font size so the code isn't too long.

    Code:
    /* Student Roster by MATT NICOLA */
    /* Final Project for Mike Fagan's Class */
    
    /* INTRODUCTION:
       The program was designed to input a number of students and sort them
       into an alphabetical list. Ten grades will be assigned to each student
       and the average will be found to complete a list of students and grades. */
       
    /* REFERENCE:
       Pg. 746 - Example of a Binary Tree
       Pg. 460 - How to make a list */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #define Allotype(type) (type *)malloc(sizeof (type))
    
    /* Set up a structure to work with the students and binary tree. */
    
       typedef struct student {     char Lastname[30];
                                    char Firstname[20];
                                    int Grade[10];
                                    struct student *rootp;
                                    struct student *leftp;
                                    struct student *rightp;
                                    struct student *tree_insert;
       } MyStudent;
    			            
    MyStudent *tree_insert(MyStudent *rootp, int new_pupil);
    void listall(MyStudent *rootp);
    
    /* The arrays will contain your students' first name, last name,
       and grades. These must be alphabetical by finish. */
    
    int
    main(void) {
    
    double student_limit,
           student_count,
           average;
    
    int    avgcnt;
    
    student_limit = 0;
    student_count = 0;
    average = 0;
       
       printf("Hello. Welcome to the student roster organizer.\n");
       printf("This program is designed to input your students and\n");
       printf("average their ten grades. Grades will be assigned\n");
       printf("with their proper students.\n\n");
       
       printf("Enter the number of students you wish to enter:");
       scanf("%lf", &student_limit);
       
       printf("\n\nNow for this part, enter the last name, enter the\n");
       printf("first name, and then enter 10 seperate numbers that\n");
       printf("determine the student's score.\n\n");
       printf("REMEMBER: Enter one student at a time and continue until\n");
       printf("the student limit has been reached.\n\n\n");
    
       /* The while loop doesn't stop until all students are covered. */
    
       while (student_count <= student_limit) {
             
             scanf("%s", MyStudent Lastname);
             printf(" ");
             scanf("%s", MyStudent Firstname);
             printf(" ");
             scanf("%d", MyStudent Grade[0]);
             printf(" ");
             scanf("%d", MyStudent Grade[1]);
             printf(" ");
             scanf("%d", MyStudent Grade[2]);
             printf(" ");
             scanf("%d", MyStudent Grade[3]);
             printf(" ");
             scanf("%d", MyStudent Grade[4]);
             printf(" ");
             scanf("%d", MyStudent Grade[5]);
             printf(" ");
             scanf("%d", MyStudent Grade[6]);
             printf(" ");
             scanf("%d", MyStudent Grade[7]);
             printf(" ");
             scanf("%d", MyStudent Grade[8]);
             printf(" ");
             scanf("%d", MyStudent Grade[9]);
       
    /* Each student will have 10 grades and they will present an average. */
    
             for (avgcnt = 0; avgcnt < 10; ++avgcnt){
    
             average = average + MyStudent Grade[avgcnt]; }
    
             average = average / 10;
             
             student_count = student_count + 1; }
    
    /* The next passage processes the binary functions. */
    
            MyStudent       *no_pupil;
            int             keyinput;
            int             status;
    
            no_pupil = NULL
    
            for (status = MyStudent;
                 status == 1;
                 status = MyStudent) {
            no_pupil = tree_insert(no_pupil, keyinput);
            listall(no_pupil); }
    
            if (status == 0)
                    {printf("Invalid! >>%c\n", getchar()); }
            else
                    {listall(no_pupil); }
    
       return(0); }
       
       
    /* The binary tree will soon follow and it will place the entries into
       alphabetical order. You might want to use an IF statement. */
    
    MyStudent *
    tree_insert (MyStudent *rootp,
                 int        new_pupil)
       
    {
        /* If student has higher letter */
       (if strcmp == -1)
             { rootp->leftp = tree_insert
               (rootp->rightp, new_student); }
    
        /* If student matches current student */
       (else if strcmp == 0)
             {/* Nothing happens */}
    
        /* If student has lower letter */
       (else if strcmp == 1)
             { rootp->rightp = tree_insert
               (rootp->leftp, new_pupil); }
    
        /* If student is NULL */
       (else)
             {rootp = Allotype(student);
              rootp = new_pupil
              rootp->leftp = NULL;
              rootp->rightp = NULL; }
              
       return (rootp);
       
    }
    Thank you for your concern Salem, but I am using the strcmp to compare the strings of students. Thus they will be sorted based upon a positive or negative answer from string compare.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,849
    > scanf("%d", MyStudent Grade[0]);
    I'm pretty sure I said "add an &", not "remove the dot"

    Are you even trying to compile this before posting?

    > (if strcmp == -1)
    1. The if goes outside the (
    2. What are you comparing with -1 ?
    At the moment, it's just the address of the function called strcmp

    Perhaps something like
    if ( strcmp( s1->Lastname, s2->Lastname ) < 0 ) // note, not specifically -1

    Plenty of other problems as well.

    Like I said, save this file away somewhere, then start a new file and copy in a few lines at a time, then press compile. Repeat until the whole program compiles.
    Then the fun starts when you try and run it.

    Don't expect to just be able to write any old pseudo-C, post it on a message board and hope someone is going to go through it all to fix all the problems.
    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.

  11. #11
    Registered User
    Join Date
    Nov 2006
    Posts
    65
    Not to sound like a snood but why did you not use a loop. Instead of writing
    Code:
      scanf("%d", MyStudent Grade[0]);
             printf(" ");
             scanf("%d", MyStudent Grade[1]);
             printf(" ");
             scanf("%d", MyStudent Grade[2]);
             printf(" ");
             scanf("%d", MyStudent Grade[3]);
             printf(" ");
             scanf("%d", MyStudent Grade[4]);
             printf(" ");
             scanf("%d", MyStudent Grade[5]);
             printf(" ");
             scanf("%d", MyStudent Grade[6]);
             printf(" ");
             scanf("%d", MyStudent Grade[7]);
             printf(" ");
             scanf("%d", MyStudent Grade[8]);
             printf(" ");
             scanf("%d", MyStudent Grade[9]);
    how about
    Code:
    for(i=0,i<10,i++)
    {
      scanf("%d", Mystudent Grade[i]);
      printf(" ");
    }
    I am not trying to one up you but just that in the future you don’t have write out so much code. It’s a lot easer to use loops because lets say you wanted to create a more of a black box set up on you code. If everything you write is case clause it will get the job done, but for just that job. But if you write you code for a "user" then you write around the users own personal input. Some programs you really can't become 100% dependent on it but if you attempt to centralize you code it will be better for future manipulation. Like what’s say you wanted to have an array of just nine, in your code you would have to delete a part of you work but in my example on the fly you can add or remove apart of the array.


    Also I notice that you use 10 alot in your program, maybe a constant called "grade" or something that describes why you have used 10 so much. That way like I stated before you will be able to manipulate your code. You could spend a half an hour combing through your code to replace 10's with 9's or you can use #define GRADE 10 and change that in one place.
    Last edited by KoG Metalgod; 12-12-2006 at 07:35 AM.
    You rant and rave about it, but at the end of the day, it doesn't matter if people use it as long as you don't see.
    People are free to read the arguments, but if the only way for you to discover gravity is by jumping off a cliff, then that is what you're going to have to experience for yourself.
    Eventually, this "fast and loose" approach of yours will bite you one too many times, then you'll figure out the correct way to do things. - Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C program using structs to calculate grades
    By TampaTrinDM88 in forum C Programming
    Replies: 4
    Last Post: 07-06-2009, 01:33 PM
  2. Updating in a sequential file?
    By Ronnyv1 in forum C Programming
    Replies: 1
    Last Post: 03-24-2009, 05:41 PM
  3. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-24-2007, 12:05 AM
  4. I have a function and I need multiple averages returned
    By tommy69 in forum C++ Programming
    Replies: 20
    Last Post: 04-13-2004, 12:45 PM
  5. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 09:43 PM

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