abraxyz
February 12th, 2011, 02:26 AM
I'm trying to figure out this exercise from the C++ Primer Plus book:
Write a C++ program that requests and displays information as shown in the following
example of output:
What is your first name? Betty Sue
What is your last name? Yew
What letter grade do you deserve? B
What is your age? 22
Name: Yew, Betty Sue
Grade: C
Age: 22
Note that the program should be able to accept first names that comprise more than one
word. Also note that the program adjusts the grade downward—that is, up one letter.
Assume that the user requests an A, a B, or a C so that you don’t have to worry about the
gap between a D and an F.
The thing is, I'm not supposed to use branching statements, so basically I'm having a hard time incrementing the grade value. I know I should use something like:
char grades[4] = {'A', 'B', 'C', 'D'};
char * pt = grades;And eventually:
pt = pt + 1;
cout << pt[element number] << endl;So, how do I read the grade character and later increment it using this method? I was also thinking about using enumerators:
enum grades {A, B, C, D};But, the user would have to input an int type instead of grade letter. I guess...
Well, thanks for your help
Write a C++ program that requests and displays information as shown in the following
example of output:
What is your first name? Betty Sue
What is your last name? Yew
What letter grade do you deserve? B
What is your age? 22
Name: Yew, Betty Sue
Grade: C
Age: 22
Note that the program should be able to accept first names that comprise more than one
word. Also note that the program adjusts the grade downward—that is, up one letter.
Assume that the user requests an A, a B, or a C so that you don’t have to worry about the
gap between a D and an F.
The thing is, I'm not supposed to use branching statements, so basically I'm having a hard time incrementing the grade value. I know I should use something like:
char grades[4] = {'A', 'B', 'C', 'D'};
char * pt = grades;And eventually:
pt = pt + 1;
cout << pt[element number] << endl;So, how do I read the grade character and later increment it using this method? I was also thinking about using enumerators:
enum grades {A, B, C, D};But, the user would have to input an int type instead of grade letter. I guess...
Well, thanks for your help