Grade.cpp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • C Learner
    New Member
    • Nov 2007
    • 5

    Grade.cpp

    I really need help I have got this program all screwed and cant figure out why I cant access my char grades pleade help C learner

    Grade.cpp
    [CODE=c]
    int main(int argc, char *argv[])
    {



    void inputRecord (StudentRecord record);
    //postcondition
    void computeAverage (StudentRecord& record);
    //precondition
    char letterGrade (double numericGrade);
    //precondition
    void outputRecord (StudentRecord record);
    //precondition
    //stream insertion operators were reversed for cout and cin functions

    StudentRecord record;
    cout << "Please Enter Your Grades Below" << endl << "Quiz One: ";
    cin >> record.quiz1;
    cout << "Quiz Two: ";
    cin >> record.quiz2;
    cout << endl;
    cout << "Midterm Exam Score: ";
    cin >> record.midtermE xam;
    cout << endl;
    cout << "Final Exam Score: ";
    cin >> record.finalExa m;
    cout << endl;



    }

    void computeAverage (StudentRecord& record)
    {
    const double EXAM_WT = 0.5;
    const double MIDTERM_WT = 0.25;
    const double QUIZ_WT = 0.25;
    double quiz1Percent, quiz2Percent;

    //
    // Convert the 10 point quizzes to a percent, then find the average
    //
    quiz1Percent = 100 * record.quiz1 / 10.0;
    quiz2Percent = 100 * record.quiz2 / 10.0;
    double quizAvg = (quiz1Percent + quiz2Percent) / 2;

    //
    // Compute the weighted average to get the numeric course grade
    //
    record.courseAv erage = quizAvg * QUIZ_WT + record.midtermE xam * MIDTERM_WT +
    record.finalExa m * EXAM_WT;

    //
    // Call the letterGrade function to find the corresponding letter grade
    record.letterGr ade = letterGrade (record.courseA verage);

    exit(1);
    }[/CODE]
    Last edited by sicarie; Nov 7 '07, 03:50 PM. Reason: Snipping from full code
  • scruggsy
    New Member
    • Mar 2007
    • 147

    #2
    Your functions look fine for the most part.
    Weird that you have your function prototypes in main, though.
    Can you explain the problem more clearly?
    You go to all the trouble of inputting the grades in main, but you never call any of your functions to calculate the average and determine the letter grade.

    Comment

    • C Learner
      New Member
      • Nov 2007
      • 5

      #3
      The problem I have is getting the char grades
      heres what i came with after I posted

      It seems like none of the previous fuctions if initialized I dont get I am getting really frustrated


      removed full code
      Last edited by sicarie; Nov 7 '07, 03:50 PM. Reason: removed full code

      Comment

      • Studlyami
        Recognized Expert Contributor
        • Sep 2007
        • 464

        #4
        Originally posted by scruggsy
        You go to all the trouble of inputting the grades in main, but you never call any of your functions to calculate the average and determine the letter grade.
        First PLEASE use the code tags when posting code. Second you never call your functions! Also, your letter grade function prototype says it takes receives an int, but the actual function definition you say it receives a double.

        Comment

        • C Learner
          New Member
          • Nov 2007
          • 5

          #5
          Originally posted by Studlyami
          First PLEASE use the code tags when posting code. Second you never call your functions! Also, your letter grade function prototype says it takes receives an int, but the actual function definition you say it receives a double.


          Yea I see the int char but the problem I am having is calling the grades or the letter grade I know i am missing something but I cant get it eventually I will after i tear it completely up and try again[/CODE]

          Comment

          • C Learner
            New Member
            • Nov 2007
            • 5

            #6
            grade.cpp revised still dont wotk

            well so far I have gotten this far I have the input and output working but my char function still doesnt please help I am pulling my hair out here

            #include "stdafx.h"
            #include <iostream>
            #include <math.h>
            using namespace std;


            //
            // Structure for a student record
            //


            struct StudentRecord
            {
            double quiz1;
            double quiz2;
            double midtermExam;
            double finalExam;
            double courseAverage;
            char letterGrade;

            };

            int main()
            {


            StudentRecord record;
            cout << "Please Enter Your Grades Below" << endl << "Quiz One: ";
            cin >> record.quiz1;
            cout << "Quiz Two: ";
            cin >> record.quiz2;
            cout << endl;
            cout << "Midterm Exam Score: ";
            cin >> record.midtermE xam;
            cout << endl;
            cout << "Final Exam Score: ";
            cin >> record.finalExa m;
            cout << endl;
            cout << "Quiz Scores: " << record.quiz1 << " " << record.quiz2 << endl;
            cout << "Midterm Exam Score: " << record.midtermE xam << endl;
            cout << "Final Exam Score: " << record.finalExa m << endl;
            cout << endl;
            cout << "Course Average: " << record.courseAv erage << endl;
            cout << "Final Letter Grade: " << record.letterGr ade << endl;
            cout << endl;
            }

            char letterGrade (double numericGrade)
            {
            char letter;

            if (numericGrade < 60)
            letter = 'F';
            else if (numericGrade < 70)
            letter = 'D';
            else if (numericGrade < 80)
            letter = 'C';
            else if (numericGrade < 90)
            letter = 'B';
            else
            letter = 'A';

            return letter;
            }


            void computeAverage (StudentRecord& record)
            {
            const double EXAM_WT = 0.5;
            const double MIDTERM_WT = 0.25;
            const double QUIZ_WT = 0.25;
            double quiz1Percent, quiz2Percent;

            //
            // Convert the 10 point quizzes to a percent, then find the average
            //
            quiz1Percent = 100 * record.quiz1 / 10.0;
            quiz2Percent = 100 * record.quiz2 / 10.0;
            double quizAvg = (quiz1Percent + quiz2Percent) / 2;

            //
            // Compute the weighted average to get the numeric course grade
            //
            record.courseAv erage = quizAvg * QUIZ_WT + record.midtermE xam * MIDTERM_WT +
            record.finalExa m * EXAM_WT;

            //
            // Call the letterGrade function to find the corresponding letter grade
            record.letterGr ade = letterGrade (record.courseA verage);

            exit(1);

            }

            Comment

            • scruggsy
              New Member
              • Mar 2007
              • 147

              #7
              Originally posted by C Learner
              the problem I am having is calling the grades or the letter grade I know i am missing something but I cant get it
              You don't call letterGrade(). There's a call to it in computeAverage( ), but you never call that function.
              Are you unsure how to call that function, or is there some compiler error, or what?
              BTW, why the exit(1) at the end of computeAverage( )? Surely you don't want to terminate your program at the end of that function...

              Comment

              • oler1s
                Recognized Expert Contributor
                • Aug 2007
                • 671

                #8
                After 4 posts, you should have somehow found about the CODE tags. We'll wait until you fix your post to use these CODE tags. If somehow, you are not familiar with CODE tags, then it's simply putting [CODE ] and [/ CODE] tags around your code.

                Because unformatted code is unreadable, and attempting to read poorly formatted code leads to mistakes on our part, we'll wait until you make the appropriate correction.

                I notice a few points right away, but only because they stand out so much. <math.h> should be <cmath> . If you do not know why, ask.

                You're use of exit(1) in computeAverage is puzzling. I'd like you to explain why it's there.

                In main(), there are no calls to your function computeAverage. Obviously, computeAverage won't run unless it is called. Therefore, call the function appropriately.. .

                EDIT: You have another ongoing thread dealing with this question. Starting multiple threads is more than rude. It means that you start multiple threads of advice, with people not knowing what the other threads have discovered. You are wasting people's time this way. Perhaps a mod will merge your thread. I hope you have more concern for internet etiquette in the future.

                Comment

                • scruggsy
                  New Member
                  • Mar 2007
                  • 147

                  #9
                  I won't berate you further, although everything oler1s pointed out is valid.
                  I think you're not understanding how functions work on a basic level.
                  A program terminates as soon as it hits the closing brace of main().
                  The way your code is laid out, it almost seems that you think execution will continue past main(), into letterGrade() and finally ending up in computeAverage( ), terminating with exit(1) in that function.
                  That is not how it works.

                  Example of calling functions:
                  Code:
                  void doSomething()
                  {
                    //do stuff
                  }
                  
                  int main(){     // <- Execution begins here
                    doSomething();
                    doSomethingElse();
                    return 0;   // or exit(1) if you must
                  }                 // <- Execution ends here
                  
                  void doSomethingElse()
                  {
                    //do other stuff
                  }
                  Notice that although doSomething() is defined above main, and doSomethingElse () below it, neither function runs until it is called by main(). After the program reaches the closing brace of either function (or hits a return in that function), execution passes back to main().
                  Sorry if this is old news to you; I'm just trying to help in the absence of a better explanation of the problem.

                  Comment

                  • jpenguin
                    New Member
                    • Aug 2007
                    • 41

                    #10
                    Originally posted by scruggsy
                    I won't berate you further, although everything oler1s pointed out is valid.
                    I think you're not understanding how functions work on a basic level.
                    A program terminates as soon as it hits the closing brace of main().
                    The way your code is laid out, it almost seems that you think execution will continue past main(), into letterGrade() and finally ending up in computeAverage( ), terminating with exit(1) in that function.
                    That is not how it works.

                    Example of calling functions:
                    Code:
                    void doSomething()
                    {
                      //do stuff
                    }
                    
                    int main(){     // <- Execution begins here
                      doSomething();
                      doSomethingElse();
                      return 0;   // or exit(1) if you must
                    }                 // <- Execution ends here
                    
                    void doSomethingElse()
                    {
                      //do other stuff
                    }
                    Notice that although doSomething() is defined above main, and doSomethingElse () below it, neither function runs until it is called by main(). After the program reaches the closing brace of either function (or hits a return in that function), execution passes back to main().
                    Sorry if this is old news to you; I'm just trying to help in the absence of a better explanation of the problem.
                    isn't it against the rules to post complete code from a student assignment? Your in CSCI7 at COS, rigt?

                    Comment

                    • C Learner
                      New Member
                      • Nov 2007
                      • 5

                      #11
                      Originally posted by jpenguin
                      isn't it against the rules to post complete code from a student assignment? Your in CSCI7 at COS, rigt?

                      2rong! And No Im not part of a student assignment if i was part of an assignment and I had an instructor I wouldn't be asking another newbe for help on a fuction call, You know when people come to these forums its for help on topics they ask about but instead of help they get its just plain put downs and oh my God he's an idiot cause he's calling a function the wrong way.
                      If the person who is replying to the forum doesnt want to help the person asking then why reply in the first place?

                      Comment

                      • sicarie
                        Recognized Expert Specialist
                        • Nov 2006
                        • 4677

                        #12
                        C Learner-

                        We get a surprising amount of requests for help with homework on topics much more simple than the one you are working on. I do believe jpenguin was referencing this site's Posting Guidelines - that we are not supposed to allow full code to be posted - and he recognized the assignment (which happens to be a common one throughout universities).

                        jpenguin & C Learner -
                        As I don't believe jpenguin said anything about C Learner's coding ability, due to the direction this thread is going, I will ask the both of you to read the Posting Guidelines because if any flames (disparaging comments) are found in this thread (or in any thread in any forum), those who have posted inappropriately will be reprimanded, possibly even banned.

                        PS - C Learner, please check your Private Messages accessible through the PM link in the top right corner of this page. Thanks.

                        Comment

                        Working...