944,145 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 22517
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 28th, 2005
0

c++ Grade program

Expand Post »
I need help with this program. here is what we are supposed to do.
The program should prompt the user to 'Please enter numeric grade: '.

The program will then pass the numeric grade to a function that will convert to a letter grade. This function should have the following prototype:

char get_letter_grade (int grade_num);

100-90 A

89-80 B

79-70 C

69-60 D

below 60 F

4. The character that is returned will then be sent to a function to determine if the letter grade is passing (grades higher than 59 are passing). This function should have the following prototype:

bool is_passing(char grade_letter);

5. Your program should then display the results. For example:

Please enter numeric grade: 83

The letter grade is: B.
The grade is passing.

Here is what i have so far.

#include <fstream>
#include <iostream>

using namespace std;

int main()
{
int grade_num;

cout<< "Please enter numeric grade:"<< endl;
cin>> grade_num;
return 0;
}

char get_letter_grade (int grade_num)

{
if (grade_num<=60);
cout<< "The letter grade is F"<< endl;
else if ( grade_num<=69);
cout<< "The letter grade is D"<< endl;
else if (grade_num<=79);
cout<< "The letter grade is C"<< endl;
else if (grade_num<=89);
cout<< "The letter grade is B"<< endl;
else (grade_num<=100);
cout<< "The letter grade is A"<< endl;
return (grade_num);
}

bool is_passing(char grade_letter)

{
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sutty8303 is offline Offline
4 posts
since Feb 2005
Feb 28th, 2005
0

Re: c++ Grade program

Please use code tags
Remeber you are working with a specific range so you are going to need to use the && in your get letter grade function. Also that function needs some other adjustments. You also need to call it from main. Did you even go to class?
Reputation Points: 14
Solved Threads: 4
Junior Poster
prog-bman is offline Offline
108 posts
since Nov 2004
Feb 28th, 2005
0

Re: c++ Grade program

the answer to this is in my old C++ book, it has the same questions as an example

i don't have to book with me, but i'll try to put it up tomorrow
Reputation Points: 11
Solved Threads: 0
Junior Poster
Fasola is offline Offline
188 posts
since Jan 2005
Feb 28th, 2005
0

Re: c++ Grade program

This solution won't work for you, but it should give you a push in the right direction:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. char letter_grade(int grade_num)
  6. {
  7. char limit[][4] = {90,80,70,60,'A','B','C','D'};
  8.  
  9. for (int i = 0; i < 4; i++) {
  10. if (grade_num >= limit[0][i])
  11. return limit[1][i];
  12. }
  13.  
  14. return 'F';
  15. }
  16.  
  17. bool is_passing(char grade_letter)
  18. {
  19. return grade_letter < 'F'; // Portability is for wusses
  20. }
  21.  
  22. int main()
  23. {
  24. for (int i = 0; i < 101; i++) {
  25. cout<< i <<" = "<< letter_grade(i) <<": ";
  26. cout<< boolalpha << is_passing(letter_grade(i)) <<endl;
  27. }
  28. }
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Mar 1st, 2005
0

Re: c++ Grade program

I'd like to point out that these solutions are no better or worse than anyone elses, but rather a demonstration of different ways to solve the problem and still get the same result.

C++ Syntax (Toggle Plain Text)
  1. char get_letter_grade (int grade_num)
  2. {
  3. char Result;
  4.  
  5. switch (grade_num / 10)
  6. {
  7. case 10:
  8. case 9:
  9. Result = 'A';
  10. break;
  11.  
  12. case 8:
  13. Result = 'B';
  14. break;
  15.  
  16. case 7:
  17. Result = 'C';
  18. break;
  19.  
  20. case 6:
  21. Result = 'D';
  22. break;
  23.  
  24. default:
  25. Result = 'F';
  26. }
  27.  
  28. return Result;
  29. }


or Needs tweeking if grade is 100 or less then 60
C++ Syntax (Toggle Plain Text)
  1. char get_letter_grade (int grade_num)
  2.  
  3. {
  4. return ((10 - (Grade / 10)) + 64);
  5. }

Reputation Points: 47
Solved Threads: 17
Posting Whiz in Training
Tight_Coder_Ex is offline Offline
215 posts
since Feb 2005
Mar 1st, 2005
0

Re: c++ Grade program

Thanks for all of the help. We get little to no help from the TA's in our classes and yes i do go to class, it's hard to learn when they do not teach what you need to know.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sutty8303 is offline Offline
4 posts
since Feb 2005
Mar 1st, 2005
0

Re: c++ Grade program

You realize you're paying to be taught, right? Don't just sit there and whine about the instructors not doing their part, make them do it.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Mar 1st, 2005
0

Re: c++ Grade program

Quote originally posted by Narue ...
You realize you're paying to be taught, right? Don't just sit there and whine about the instructors not doing their part, make them do it.
ONE HELL OF A POINT...i'll have to remember that "intensely" if i get accepted to grad school
Reputation Points: 11
Solved Threads: 0
Junior Poster
Fasola is offline Offline
188 posts
since Jan 2005
Mar 2nd, 2005
0

Re: c++ Grade program

Quote originally posted by sutty8303 ...
Thanks for all of the help. We get little to no help from the TA's in our classes and yes i do go to class, it's hard to learn when they do not teach what you need to know.
int main(){

int grade;

grade = 0;

cout << "Enter grade: ";
cin >> grade;

{
if (grade >= 90)
cout << "A";
else if (grade >= 80)
cout << "B";
else if (grade >=70)
cout << "C";
else if (grade >= 60)
cout << "D";
else
cout << "F";
}
return 0;
}

i don't know if that will work, its been way to long since writing code
Reputation Points: 11
Solved Threads: 0
Junior Poster
Fasola is offline Offline
188 posts
since Jan 2005
Mar 2nd, 2005
0

Re: c++ Grade program

>i don't know if that will work
So run it and see. If you aren't confident that your code is 100% correct, don't write directly to the thread. Write the code in an editor, compile it, run it, debug it, and make sure it's working like you expect before posting it.

To this day, I still test my code before posting it 9 times out of 10. I'm confident that it's flawless (though part of that is ego), but I still would rather double and triple check myself than have somebody else correct a stupid mistake.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Need help on Factorial in C++
Next Thread in C++ Forum Timeline: C++ Checkbook balancing program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC