Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem, you will be prompting a student for grades and credits for courses taken. From that, you will calculate a GPA. This site:

In this problem, you will be prompting a student for grades and credits for courses taken. From that, you will calculate a GPA. This site: http://www.back2college.com/gpa.htm shows you how to calculate a GPA. Keep prompting the student if they want to add more courses. IMPORTANT NOTES!

The course name is prompted for, but nothing is done with it.

We are just using the grades A, B, C, D, and F so you won't have to do so much typing!

You will need to use the "set precision" command as shown in the book. Set it to "fixed" and "2".

You will need to use the "cin.ignore()" function as discussed earlier in the course.

#include #include using namespace std;

int main () { string course, grade; string answer = "YES"; int gpa, int point = 0; int credits = 0; int tgpoint = 0; int gpoint = 0; int tcredits = 0; float tgpa; cout << "Enter a course name: "; cin.ignore (-1); getline (cin, course); cout << course << endl; cout << "Enter number of credits: "; cin >> credits; cout << credits << endl; tcredits = tcredits + credits; cout << "Enter your grade (A, B, C, D, F): "; cin >> grade; cout << grade << endl; if (grade == "A") { point = 4; } if (grade == "B") { point = 3; } if (grade == "C") { point = 2; } if (grade == "D") { point = 1; } if (grade == "F") { point = 0; } cout << "Continue ('Yes' or 'No')? "; cin >> answer; cout << answer << endl; while (answer == "Yes") { cout << "Enter a course name: "; cin.ignore (); getline (cin, course); cout << course << endl; cout << "Enter number of credits: "; cin >> credits; cout << credits << endl; tcredits = tcredits + credits; cout << "Enter your grade (A, B, C, D, F): "; cin >> grade; cout << grade << endl; if (grade == "A") { point = 4; } if (grade == "B") { point = 3; } if (grade == "C") { point = 2; } if (grade == "D") { point = 1; } if (grade == "F") { point = 0; }

cout << "Continue ('Yes' or 'No')? "; cin >> answer; cout << answer << endl; } cout << "Total grade points: "; cout << tgpoint << endl;

cout << "Total credits attempted: "; cout << tcredits << endl; tcredits = tcredits + credits; cout << "Your GPA is "; cout << tgpa << endl;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions