Question

//What's wrong with my code?

Letter grades are A B C D and F, possibly followed by + or - Their nu- meric values are 4, 3, 2, 1 and O. In our scheme, ther

int run()
{
   // Don't change anything inside this function
   printTitle();
   string letterGrade = getInput();
   double points = letterToPoints(letterGrade);
   printReport(points);

return 0;
}

// Implement your functions here

void printTitle()
{
    cout << STUDENT << "-H02-Grade Calculator" << endl;
   cout << "-----------------------------------------" << endl;
}
string getInput()
{
   cout << "Enter your letter grade: ";
   string gradeIn;
   getline(cin, gradeIn);
   cin >> gradeIn;

   return gradeIn;
}
double letterToPoints(stringIn letterGrade)
{
   double gradePoints = -1;

   if (gradeIn == "A") gradePoints = 4.0;
   else if (gradeIn == "A-") gradePoints = 3.7;
   else if (gradeIn == "B+") gradePoints = 3.3;
   else if (gradeIn == "B") gradePoints = 3.0;
   else if (gradeIn == "B-") gradePoints = 2.7;
   else if (gradeIn == "C+") gradePoints = 2.3;
   else if (gradeIn == "C") gradePoints = 2.0;
   else if (gradeIn == "C-") gradePoints = 1.7;
   else if (gradeIn == "D+") gradePoints = 1.3;
   else if (gradeIn == "D") gradePoints = 1.0;
   else if (gradeIn == "D-") gradePoints = 0.7;
   else if (gradeIn == "F") gradePoints = 0.0;
   return 0.0;
}
void printReport(double points)
{
   cout << fixed << showpoint << setprecision(1);
   if (gradePoints >= 0)
   {
       cout << "Grade value is [" << points << "]" << endl;
   }
   else
   {
       string errorMessage;
       if (gradeIn == "A+" || gradeIn == "F+" || gradeIn == "F-")
       {
           errorMessage = "INVALID GRADE COMBINATION";
       }
       cout << "Grade value is [" << errorMessage << "]" << endl;
       else if (gradeIn.size() >= 1 && gradeIn.at(0) != 'A' && gradeIn.at(0) != 'B' && gradeIn.at(0) != 'C' && gradeIn.at(0) != 'D' && gradeIn.at(0) != 'F')
       {
           errorMessage = "INVALID LETTER GRADE";
       }
       else
       {
           errorMessage= "Invalid Input" ;
       }
   }
int run() { // Dont change anything inside this function printTitle(); string letterGrade = getInput(); double points - lettif (grade In == A) gradePoints = 4.0; else if (gradeIn == A-) gradePoints = 3.7; else if (grade In == B+) gradePoints =

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is corrected code:

#include<bits/stdc++.h>
using namespace std;
void printTitle()
{
cout << "STUDENT" << "-H02-Grade Calculator" << endl;
cout << "-----------------------------------------" << endl;
}
string getInput()
{
cout << "Enter your letter grade: ";
string gradeIn;
getline(cin, gradeIn);
cin >> gradeIn;

return gradeIn;
}
double letterToPoints(string gradeIn)
{
double gradePoints = -1;

if (gradeIn == "A") gradePoints = 4.0;
else if (gradeIn == "A-") gradePoints = 3.7;
else if (gradeIn == "B+") gradePoints = 3.3;
else if (gradeIn == "B") gradePoints = 3.0;
else if (gradeIn == "B-") gradePoints = 2.7;
else if (gradeIn == "C+") gradePoints = 2.3;
else if (gradeIn == "C") gradePoints = 2.0;
else if (gradeIn == "C-") gradePoints = 1.7;
else if (gradeIn == "D+") gradePoints = 1.3;
else if (gradeIn == "D") gradePoints = 1.0;
else if (gradeIn == "D-") gradePoints = 0.7;
else if (gradeIn == "F") gradePoints = 0.0;
return 0.0;
}
void printReport(double gradePoints,string gradeIn)
{
cout << fixed << showpoint << setprecision(1);
if (gradePoints >= 0)
{
cout << "Grade value is [" << gradePoints << "]" << endl;
}
else
{
string errorMessage;
if (gradeIn == "A+" || gradeIn == "F+" || gradeIn == "F-")
{
errorMessage = "INVALID GRADE COMBINATION";
}
else if (gradeIn.size() >= 1 && gradeIn.at(0) != 'A' && gradeIn.at(0) != 'B' && gradeIn.at(0) != 'C' && gradeIn.at(0) != 'D' && gradeIn.at(0) != 'F')
{
errorMessage = "INVALID LETTER GRADE";
}
else
{
errorMessage= "Invalid Input" ;
}
cout << "Grade value is [" << errorMessage << "]" << endl;
}
}
int run()
{
// Don't change anything inside this function
printTitle();
string letterGrade = getInput();
double points = letterToPoints(letterGrade);
printReport(points,letterGrade);

return 0;
}

// Implement your functions here

note:functions must be declared before its used there were many such instances in your program also some variables were mistyped kindly see your code and corrected code for more information.

Kindly upvote if it was helpful.

Add a comment
Know the answer?
Add Answer to:
//What's wrong with my code? int run() {    // Don't change anything inside this function...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is my code for a final GPA calculator. For this assignment, I'm not supposed to...

    This is my code for a final GPA calculator. For this assignment, I'm not supposed to use global variables. My question is: does my code contain a global variable/ global function, and if so how can I re-write it to not contain one? /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * Title: Final GPA Calculator * Course Computational Problem Solving CPET-121 * Developer: Elliot Tindall * Date: Feb 3, 2020 * Description: This code takes grades that are input by the student and displays * their...

  • please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName();...

    please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...

  • Why is this not giving me a letter grade when run? #include <iostream> #include <iomanip> using...

    Why is this not giving me a letter grade when run? #include <iostream> #include <iomanip> using namespace std; int main() { double grade1, grade2, grade3, grade4, total; cout << "please enter the first grade : "; cin >> grade1; cout << "Please enter the second grade : "; cin >> grade2; cout << "Please enter the third grade : "; cin >> grade3; cout << "Please enter the fourth grade : "; cin >> grade4; total = (grade1 + grade2...

  • Am I getting this error because i declared 'n' as an int, and then asking it...

    Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() {    int n;    double avg, sum = 0;;    string in_file, out_file;    cout << "Please enter the name of the input file: ";    cin >> in_file;   ...

  • (C++) I need to alter the code below to fit the given requirements. You will need...

    (C++) I need to alter the code below to fit the given requirements. You will need to move the calculations to a function. A second function to return the Letter Grade. You will need to define a namespace to contain the CONST. Also, need to define an enum for letter grades: A, B, C, D, and F. Console Student Grade Calculation Form First Name: Larry Last Name: Hobbs Homework Average: 65 Midterm Grade: 90 Final Exam Grade: 75 Student: Larry...

  • I want to change this code and need help. I want the code to not use...

    I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...

  • Professor Dolittle has asked some computer science students to write a program that will help him...

    Professor Dolittle has asked some computer science students to write a program that will help him calculate his final grades. Professor Dolittle gives two midterms and a final exam. Each of these is worth 100 points. In addition, he gives a number of homework assignments during the semester. Each homework assignment is worth 100 points. At the end of the semester, Professor Dolittle wants to calculate the median score on the homework assignments for the semester. He believes that the...

  • Can someone please edit my current code to accept a user input for the text file...

    Can someone please edit my current code to accept a user input for the text file name in lieu of how it currently will read data1.txt. Also if the user enters a data file that isn't ready to be used, cout a statement "cout << "Could not open file " << userInputforData.txt << endl; Another condition that I need to add is if there is a special character anywhere in the word it cannot be an acceptable variable name. could...

  • Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string;...

    Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string; class Account { public: Account(); Account(string, double); void deposit(double); bool withdraw(double); string getName() const; double getBalance() const; private: string name; double balance; }; #endif ////////////////////////////////////////////// //AccountManager.hpp #ifndef _ACCOUNT_MANAGER_HPP_ #define _ACCOUNT_MANAGER_HPP_ #include "Account.hpp" #include <string> using std::string; class AccountManager { public: AccountManager(); AccountManager(const AccountManager&); //copy constructor void open(string); void close(string); void depositByName(string,double); bool withdrawByName(string,double); double getBalanceByName(string); Account getAccountByName(string); void openSuperVipAccount(Account&); void closeSuperVipAccount(); bool getBalanceOfSuperVipAccount(double&) const;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT