Thread: Simple Program for grades. Little help please.

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    28

    Simple Program for grades. Little help please.

    So what i have to do is
    Write a grading program for a class of students that has the following grading policies:
    1. There are two quizzes, each with a maximum of 25 points;
    2. There is one midterm exam, each with a maximum of 50 points;
    3. There is one final exam, each with a maximum of 100 points.
    Define and use a C++ structurefor the student record: Heres what i did
    Code:
    struct studentRecord
    {
        int studentID;
        string first_name;
        string last_name;
        int quiz1;
        int quiz2;
        int midTerm;
        int finalExam;
        double totalPoints;
        double percentTotal;
        char letterGrade;
    };
    Okay, now User will enter values for following data items:
    1)Student’s ID number
    2)Student’s first name
    3)Student’s last name
    4)Quiz #1 score
    5)Quiz #2 score
    6)Midterm exam score
    7)Final exam score

    So i did this,
    Code:
    void get_data(studentRecord& the_student)    
    { 
        //Check student ID
        cout << "\nEnter Student Id\n";
        cin >> the_student.studentID;
        //Check for mistakes
        // Correct Value does this
        if ((the_student.studentID> 1) || (the_student.studentID < 99999))
        {
        }
        // Incorrect does this
        // A loop To validate the Student ID
        while ((the_student.studentID < 1) || (the_student.studentID > 99999)) 
        {
              cout <<"\nMust enter an Student ID between 1 and 99999.\n";
              cout <<"Re Enter Student ID:\n";
              cin >> the_student.studentID;
              cout <<"\n";
        } 
        
        //Get First and last names
        cout << "\nEnter First name\n";
        cin >> the_student.first_name;
        
        cout << "\nEnter last name\n";
        cin >> the_student.last_name;
        
     
        //Check Quiz 1 score
        cout << "\nEnter quiz 1 score\n";
        cin >> the_student.quiz1;
        //Check for mistakes
        // Correct Value does this
        if ((the_student.quiz1> 0) || (the_student.quiz1 < 25))
        {
        }
        // Incorrect does this
        // A loop To validate the quiz1
        while ((the_student.quiz1 < 0) || (the_student.quiz1 > 25)) 
        {
              cout <<"\nMust enter an quiz1 score between 0 and 25.\n";
              cout <<"Re Enter quiz1 score:\n";
              cin >> the_student.quiz1;
              cout <<"\n";
        } 
    
        //Check Quiz 2 score
        cout << "\nEnter quiz 2 score\n";
        cin >> the_student.quiz2;
        //Check for mistakes
        // Correct Value does this
        if ((the_student.quiz2> 0) || (the_student.quiz2 < 25))
        {
        }
        // Incorrect does this
        // A loop To validate the quiz2
        while ((the_student.quiz2 < 0) || (the_student.quiz2 > 25)) 
        {
              cout <<"\nMust enter an quiz2 score between 0 and 25.\n";
              cout <<"Re Enter quiz2 score:\n";
              cin >> the_student.quiz2;
              cout <<"\n";
        } 
    
        //Check Midterm
        cout << "\nEnter Mid Term score\n";
        cin >> the_student.midTerm;
        //Check for mistakes
        // Correct Value does this
        if ((the_student.midTerm> 0) || (the_student.midTerm < 50))
        {
        }
        // Incorrect does this
        // A loop To validate the midTerm
        while ((the_student.midTerm < 0) || (the_student.midTerm > 50)) 
        {
              cout <<"\nMust enter an midTerm score between 0 and 50.\n";
              cout <<"Re Enter a midTerm score:\n";
              cin >> the_student.midTerm;
              cout <<"\n";
        }
    
        //Check Final
        cout << "\nEnter Final Exam score\n";
        cin >> the_student.finalExam;
        //Check for mistakes
        // Correct Value does this
        if ((the_student.finalExam> 0) || (the_student.finalExam < 100))
        {
        }
        // Incorrect does this
        // A loop To validate the finalExam
        while ((the_student.finalExam < 0) || (the_student.finalExam > 100)) 
        {
              cout <<"\nMust enter an finalExam score between 0 and 100.\n";
              cout <<"Re Enter a finalExam score:\n";
              cin >> the_student.finalExam;
              cout <<"\n";
        }
            
        //Calculate Total Points
        // This adds together all quizes and exams
        the_student.totalPoints = the_student.quiz1 + the_student.quiz2 + the_student.midTerm + the_student.finalExam;
        
        //Calulate Percentage in class
        the_student.percentTotal = ((the_student.totalPoints * 100) / 200);
        
        //Figure out letter grade
        if (the_student.percentTotal>= 90)
        {
            the_student.letterGrade = 'A';                           
        }
        else if ((the_student.percentTotal>= 80) || (the_student.percentTotal < 90))
        {
             the_student.letterGrade = 'B';
        }
        else if ((the_student.percentTotal>= 70) || (the_student.percentTotal < 80))
        {
             the_student.letterGrade = 'C';
        }
        else if ((the_student.percentTotal>= 60) || (the_student.percentTotal < 70))
        {
             the_student.letterGrade = 'D';
        }
        else if (the_student.percentTotal<60)
        {
             the_student.letterGrade = 'F';
        }
    }
    For Processing this i have to
    1)Use loops to check for a valid value for ID number and scores. (Which i think i did correctly)
    2) Your program must continue to prompt the user until user enters a valid value for the data item being checked. (Which i also think i did.)
    3) After a student’s input data has been validated, assign the data to appropriate member variables in the student record structure. (Which once again i think i did correctly.)
    4) Process multiple records: There are several students in the class. Therefore, your program must prompt keyboard operator to determine whether there is another student to be processed, if not, display results (see output section below) and terminate program; otherwise, prompt user and accept input data for next student. The keyboard entry character “y” or “Y” indicates that there is another student to be processed; any other character indicates that there are no additional students to be processed. (I really need help with this one.)
    5) For each student processed, calculate the following values, and assign the results to the appropriate member variable in the student record structure:
    Student’s total points
    Code:
        //Calculate Total Points
        // This adds together all quizes and exams
        the_student.totalPoints = the_student.quiz1 + the_student.quiz2 + the_student.midTerm + the_student.finalExam;
    Student’s percentage of total possible points (rounded to one decimal place)
    Code:
    int main()
    {
        studentRecord student;
        get_data(student);
        
        //Show to first decimal place.
        cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(1);
    Now for the output, after each student their info is displayed.
    I have this under: int main()
    Code:
        //Display Student Info
        cout << "\nStudent ID =  " << student.studentID <<"";
        cout << "\nFirst Name =  " << student.first_name <<"";
        cout << "\nLast Name =  " << student.last_name <<"";
        cout << "\nQuiz 1 Score =  " << student.quiz1 <<"";
        cout << "\nQuiz 2 Score =  " << student.quiz2 <<"";
        cout << "\nMid Term Score =  " << student.midTerm <<"";
        cout << "\nFinal Exam Score =  " << student.finalExam <<"";
        cout << "\nTotal Points =  " << student.totalPoints <<"";
        cout << "\nPercent Total =  " << student.percentTotal <<"%";
        cout << "\nLetter Grade =  " << student.letterGrade <<"\n";
    Now here is where i really had trouble; After all students have been processed, display the following information:
    Total number of students processed
    Highest total points achieved
    Lowest total points achieved
    Average total points achieved
    Average letter grade achieved

    Now heres my thinking on these, but i dont know how to implment
    1) For the total numbers of students, just have a variable inside a loop increment every time the loop restarts.
    2) For the highest and lowest points, use an if statement to determine whether or not the total points is higher or lower than the previous one and store the new value it if it is.
    3) For the average, just keep adding the total points every loop then divide it by the number of students.

    Any help would be greatly appreciated! I'm just a few weeks into coding, so im not all that good yet! But im certainly trying to learn.

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    Kinda weird design, but why don't you try it and see if it works. Then ask questions about whatever doesn't work right?

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    28
    What i have so far works, but im not sure if this will be compatible will what i need to add, i was asking for help, on what to change to incorporate the things i could not figure out on my own.


    4) Process multiple records: There are several students in the class. Therefore, your program must prompt keyboard operator to determine whether there is another student to be processed, if not, display results (see output section below) and terminate program; otherwise, prompt user and accept input data for next student. The keyboard entry character “y” or “Y” indicates that there is another student to be processed; any other character indicates that there are no additional students to be processed. (I really need help with this one.)
    Now here is where i really had trouble; After all students have been processed, display the following information:
    Total number of students processed
    Highest total points achieved
    Lowest total points achieved
    Average total points achieved
    Average letter grade achieved
    This is all ive done so far for this, but this part wont compile, because it shadows a parameter, which i not sure i understand fully.
    Code:
    void get_allData (allstudentRecord& allthe_student)
    {
          int *allthe_student.score = (int*)malloc(sizeof(struct) *allthe_student.totalStudents)
    I included the other info to try and make more sense of what i was doing.

    Thank for the response!
    Last edited by kordric; 03-28-2008 at 09:34 AM.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    sizeof(struct) - size of what do you expect to get here?
    malloc - the is C++? malloc is used generally in C...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    28
    for the size it will vary each use, so i was trying to make it unlimited.

    What should i use instead of malloc ?

  6. #6
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    so i was trying to make it unlimited.
    there is no such thing as unlimited memory request - you should provide some number - known at run-time

    What should i use instead of malloc ?
    new
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  7. #7
    Registered User
    Join Date
    Mar 2008
    Posts
    28
    Is there a way to have it auto grab how many entries have been added, for each student?

  8. #8
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by kordric View Post
    Is there a way to have it auto grab how many entries have been added, for each student?
    I do not understand your question.
    If you have problems managing dynamic memory - use vectors that will do it for you
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. [Help] Simple Array/Pointer Program
    By sandwater in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 02:42 PM
  3. simple silly program
    By verbity in forum C Programming
    Replies: 5
    Last Post: 12-19-2006, 06:06 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM