Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Problem in C++ -- spitting nonsense

Name: Xero 2006-10-06 6:07

Script started on Fri Oct 06 05:52:56 2006
~ $ cat -n gradebookattempt2.cpp

     1  //CPS 181

     2  //

     3  //Quizbook Assignment

     4  //   The purpose of this assignment is to design a gradebook application, which will take gradebook input from the user, for two quizzes, a midterm, and a final, and will then give the user their semester grade.

     5  //Wish me luck in programming this.

     6 

     7  //Declare libraries...

     8 

     9  #include <iostream>

    10  using namespace std;

    11 

    12  //Declare your class...

    13 

    14  class Grades

    15  {

    16  private:

    17  int q1;

    18  int q2;

    19  int mid;

    20  int final;

    21  double avg;

    22  char lgrade;

    23  public:

    24  Grades()

    25  {

    26  q1 = 0;

    27  q2 = 0;

    28  mid = 0;

    29  final = 0;

    30  }

    31    void setq1(int quiz1);

    32    void setq2(int quiz2);

    33    void setmid(int midterm);

    34    void setfin(int fin);

    35    void setavg();

    36    char setlgrade();

    37    int getq1();

    38    int getq2();

    39    int getmid();

    40    int getfin();

    41    double getavg();

    42    char getlgrade();

    43  };

    44 

    45  //Begin your main prog...

    46 

    47  int main()

    48  {

    49    Grades scores; //Object -- define an instance of the class...

    50 

    51    int rec_q1, rec_q2, rec_mid, rec_fin;

    52 

    53    cout << "What is your grade out of 10 points from Quiz 1?" << endl;

    54    cin >> rec_q1;

    55    cout << "What is your grade out of 10 points from Quiz 2?" << endl;

    56    cin >> rec_q2;

    57    cout << "What is your grade out of 100 points from the Midterm?" << endl;

    58    cin >> rec_mid;

    59    cout << "What is your grade out of 100 points from the Final?" << endl;

    60    cin >> rec_fin;

    61    scores.setq1(rec_q1);

    62    scores.setq2(rec_q2);

    63    scores.setmid(rec_mid);

    64    scores.setfin(rec_fin);

    65    cout << "Here is your data from your work:" << endl;

    66    cout << "Quiz 1: " << scores.getq1() << endl;

    67    cout << "Quiz 2: " << scores.getq2() << endl;

    68    cout << "Midterm: " << scores.getmid() << endl;

    69    cout << "Final: " << scores.getfin() << endl;

    70    cout << "Your semester grade is as follows: " << scores.getavg() << "% which is a(n) " << scores.getlgrade() << endl;

    71  cout << endl;

    72    return 0;

    73  }

    74 

    75  //Now we deal with the member functions...

    76 

    77  void Grades::setq1(int quiz1)

    78  {

    79    q1 = quiz1;

    80  }

    81 

    82  void Grades::setq2(int quiz2)

    83  {

    84    q2 = quiz2;

    85  }

    86 

    87  void Grades::setmid(int midterm)

    88  {

    89    mid = midterm;

    90  }

    91 

    92  void Grades::setfin(int fin)

    93  {

    94    final = fin;

    95  }

    96 

    97  int Grades::getq1()

    98  {

    99    return q1;

   100  }

   101 

   102  int Grades::getq2()

   103  {

   104    return q2;

   105  }

   106 

   107  int Grades::getmid()

   108  {

   109    return mid;

   110  }

   111 

   112  int Grades::getfin()

   113  {

   114    return final;

   115  }

   116 

   117  void Grades::setavg()

   118  {

   119    int qcombine, qdivide;

   120    double qpercent, midpercent, finalpercent;

   121 

   122    qcombine = (q1 + q2);

   123    qdivide = ((qcombine)/(20))*100;

   124    qpercent = ((qdivide)/(4));

   125 

   126    midpercent = ((mid)/(4));

   127 

   128    finalpercent = ((final)/(2));

   129 

   130    avg = (finalpercent + midpercent + qpercent);

   131  }

   132 

   133  double Grades::getavg()

   134  {

   135    return avg;

   136  }

   137 

   138  char Grades::setlgrade()

   139  {

   140    if (avg <= 59)

   141      lgrade = 'F';

   142    else if ((avg >= 60) && (avg <= 69))

   143      lgrade = 'D';

   144    else if ((avg >= 70) && (avg <= 79))

   145      lgrade = 'C';

   146    else if ((avg >= 80) && (avg <= 89))

   147      lgrade = 'B';

   148    else if ((avg >= 90) && (avg <= 100))

   149      lgrade = 'A';

   150  }

   151 

   152  char Grades::getlgrade()

   153  {

   154    return lgrade;

   155  }

- $ g++ gradebookattempt2.cpp

~ $ a.out

What is your grade out of 10 points from Quiz 1?

9

What is your grade out of 10 points from Quiz 2?

8

What is your grade out of 100 points from the Midterm?

98

What is your grade out of 100 points from the Final?

88

Here is your data from your work:

Quiz 1: 9

Quiz 2: 8

Midterm: 98

Final: 88

Your semester grade is as follows: 5.22764e-270% which is a(n) Ì



~ $ exit

exit


script done on Fri Oct 06 05:53:45 2006

------------------------------------------------------------

As you can see, user inputs two quiz grades, a midterm, and a final. Both quizes combine into 20pts, and is worth 25% of the "semester" grade. Midterm = 25% "semester" grade. Final = 50% "semester" grade... and yet, even though I cannot find a single flaw in my code, it's spitting back nonsense at me, instead of a grade. bah. Halp?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List