I apologize if this does not sound clear. I will show the assignment and what the output is supposed to look like along with the code that I have so far.....My problem is pretty much
typing this xxx to exit....I have always used numbers for this so a string would be new to me....we are not allowed to exit(1) and was just seeing if anyone had any ideas for this
By the way I know it has quite a few errors right now but what I am really wanting to fix is the "type xxx to exit"....I have always used numbers for statement to exit such as while (x>=0) for it being type a negative to exit (just an example) so I know what I am doing for the most part but really didn't find a whole lot of help in the book....I hope this makes more sense
Instructions.........
Write a program to compute a student’s GPA for one semester. It should ask the user for the student’s last name, and how many classes were taken during the semester. It will then ask the user to type in the letter grade for each class and print the GPA to the screen.
The program should continue doing this until the user types an xxx for the last name.
Program Requirements
• To make the program easier, assume all classes are 3 credits.
• There should be two digits of precision
• You should have the following functions:
• Get_Name_and_Num_Classes - This function asks the user to type in their name and the number of classes taken
• Calculate_GPA - This function computes GPA. It does this by looping. It call Get_Letter_Grade to allow the user to enter a valid letter grade and then it calls Convert_Let_to_Num. It uses this information to compute the GPA. It returns the GPA. (you should be able to determine the formal parameters)
• Get_Letter_Grade – This function is a void function. It asks the user to type in a letter grade, and then makes sure that the letter grade is valid. It must be an A, B, C, D, or F. You should be able to determine the formal parameters.
• Convert_Let_to_Num – Takes in a letter grade and converts it to its number equivalent (A–4, B–3, C–2, D–1, F–0) It should return the number equivalent.
• Print_Results - This prints all results to the screen. It should not return a value.
The output should say:
Programmed by <your name>
Type xxx for the name to exit
Enter the student's last name: Mickey
How many classes taken: 3
Enter letter grade 1: a
Enter letter grade 2: B
Enter letter grade 3: b
Student Mickey has a semester GPA of 3.33
Enter the student's last name: Goofy
How many classes taken: 5
Enter letter grade 1: c
Enter letter grade 2: C
Enter letter grade 3: d
Enter letter grade 4: b
Enter letter grade 5: a
Student Goofy has a semester GPA of 2.40
Enter the student's last name: Donald
How many classes taken: 2
Enter letter grade 1: c
Enter letter grade 2: B
Student Donald has a semester GPA of 2.50
Enter the student's last name: Minnie
How many classes taken: 4
Enter letter grade 1: A
Enter letter grade 2: A
Enter letter grade 3: B
Enter letter grade 4: A
Student Mickey has a semester GPA of 3.75
Enter the student's last name: xxx
Here is my code....
#include <iostream>
using namespace std;
string Get_Name_and_Num_Classes(string name, int classes);
double Calculate_GPA();
char Get_Letter_Grade(char grade);
double Convert_Let_to_Num();
void Print_Results(string name, double gpa);
int main()
{
string name;
int count = 1;
int classes;
char grade;
double gpa;
cout << "Programmed by Jim Johnson";
cout << endl << endl << "Type xxx for the name to Exit";
do
{
cout << endl << endl << "Enter the student's last name: ";
name = Get_Name_and_Num_Classes(classes, name);
if (name != "xxx")
{
cout << endl << "How many classes taken: ";
classes = Get_Name_and_Num_Classes(classes, name);
}while (count <= classes)
cout << endl << endl << "Enter letter grade " << count << ": ";
grade = Get_Letter_Grade("grade");
count ++;
Print_Results(name, gpa);
}while (name != "xxx");
return 0;
}
char Get_Letter_Grade(char grade)
{
cin >> grade;
return grade;
}
double Calculate_GPA()
{
double gpa;
return (gpa);
}
string Convert_Let_to_Num(char grade)
{
int number;
if ((char == 'a') || (char == 'A'))
{
number == 4;
}
else if ((char == 'b') || (char == 'B'))
{
number == 3;
}
else if ((char == 'c') || (char == 'C'))
{
number == 2;
}
else if ((char == 'd') || (char == 'D'))
{
number == 1;
}
else
number == 0;
return (number);
}
void Print_Results(string name, double gpa)
{
cout << "Student " << name << " has a semester GPA of " << gpa;
}