c++ Grade program

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2005
Posts: 4
Reputation: sutty8303 is an unknown quantity at this point 
Solved Threads: 0
sutty8303 sutty8303 is offline Offline
Newbie Poster

c++ Grade program

 
0
  #1
Feb 28th, 2005
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)

{
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 108
Reputation: prog-bman is an unknown quantity at this point 
Solved Threads: 3
prog-bman prog-bman is offline Offline
Junior Poster

Re: c++ Grade program

 
0
  #2
Feb 28th, 2005
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?
Join me on IRC:
Server: irc.daniweb.com
Channel: #C++

Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 188
Reputation: Fasola is an unknown quantity at this point 
Solved Threads: 0
Fasola Fasola is offline Offline
Junior Poster

Re: c++ Grade program

 
0
  #3
Feb 28th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,867
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: c++ Grade program

 
0
  #4
Feb 28th, 2005
This solution won't work for you, but it should give you a push in the right direction:
  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. }
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 199
Reputation: Tight_Coder_Ex is an unknown quantity at this point 
Solved Threads: 14
Tight_Coder_Ex's Avatar
Tight_Coder_Ex Tight_Coder_Ex is offline Offline
Junior Poster

Re: c++ Grade program

 
0
  #5
Mar 1st, 2005
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.

  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
  1. char get_letter_grade (int grade_num)
  2.  
  3. {
  4. return ((10 - (Grade / 10)) + 64);
  5. }

Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 4
Reputation: sutty8303 is an unknown quantity at this point 
Solved Threads: 0
sutty8303 sutty8303 is offline Offline
Newbie Poster

Re: c++ Grade program

 
0
  #6
Mar 1st, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,867
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: c++ Grade program

 
0
  #7
Mar 1st, 2005
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.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 188
Reputation: Fasola is an unknown quantity at this point 
Solved Threads: 0
Fasola Fasola is offline Offline
Junior Poster

Re: c++ Grade program

 
0
  #8
Mar 1st, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 188
Reputation: Fasola is an unknown quantity at this point 
Solved Threads: 0
Fasola Fasola is offline Offline
Junior Poster

Re: c++ Grade program

 
0
  #9
Mar 2nd, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,867
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: c++ Grade program

 
0
  #10
Mar 2nd, 2005
>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.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 11654 | Replies: 18
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC