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...

  • 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;   ...

  • 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...

  • 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;...

  • Please help fix my code C++, I get 2 errors when running. The code should be...

    Please help fix my code C++, I get 2 errors when running. The code should be able to open this file: labdata.txt Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW Here is my code: #include <iostream> #include <string> #include <fstream> #include <vector> #include <cstdlib> #include <iomanip> using namespace std; const int MAXLOAD737 = 46000; const int MAXLOAD767 = 116000; class Cargo { protected: string uldtype; string abbreviation; string uldid; int...

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • C++ programming I need at least three test cases for the program and at least one...

    C++ programming I need at least three test cases for the program and at least one test has to pass #include <iostream> #include <string> #include <cmath> #include <iomanip> using namespace std; void temperatureCoverter(float cel){ float f = ((cel*9.0)/5.0)+32; cout <<cel<<"C is equivalent to "<<round(f)<<"F"<<endl; } void distanceConverter(float km){ float miles = km * 0.6; cout<<km<<" km is equivalent to "<<fixed<<setprecision(2)<<miles<<" miles"<<endl; } void weightConverter(float kg){ float pounds=kg*2.2; cout<<kg<<" kg is equivalent to "<<fixed<<setprecision(1)<<pounds<<" pounds"<<endl; } int main() { string country;...

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
ADVERTISEMENT