Question

(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 Hobbs

Completed the course with a final grade of: 72.5 or C

Progressing Complete!!!!!

Specifications

  • Define a namespace to include the CONST and enum for grades.
  • enum scoreLetter {A,B,C,D,F};
  • Move the calculations to value return function
  • You will need a second function to determine the Course Grade.
  • This function should return an enum type
  • You will need to use the following Functional Prototype. This is also the direction your functions should be designed.

//Functional Prototypes

double final_Score(double hwAvg, double mtScore,

double feScore, char &ltrGrade);

myNamespace::scoreLetter score_Letter(int score);

  • Notice the final_Score function is a value return with a reference parameter
  • See Additional Functions below
  • The final_Score function should call the score_Letter
  • #include <fstream>
    #include <iostream>
    #include <iomanip>
    #include <cstring>
    #include <cstdlib>
    #include <ctime>
    #include <vector>
    using namespace std;


    int main() {
    //Declaring variables
    const double HW = 0.55;
    const double MID=0.20;
    const double FINAL=0.25;
    string first,last;
    double homeWork,midTerm,finalExam,finalGrade;

    cout<<"Enter full name :";
    cin>>first>>last;

    while(true)
    {
    cout<<"Enter home work score :";
    cin>>homeWork;
    if(homeWork<0 || homeWork>100)
    {
    cout<<"** Invalid.Must be between 0-100 **"<<endl;
    }
    else
    break;
    }

    while(true)
    {
    cout<<"Enter mid term Score :";
    cin>>midTerm;
    if(midTerm<0 || midTerm>100)
    {
    cout<<"** Invalid.Must be between 0-100 **"<<endl;
    }
    else
    break;
    }

    while(true)
    {
    cout<<"Enter final exam score :";
    cin>>finalExam;
    if(finalExam<0 || finalExam>100)
    {
    cout<<"** Invalid.Must be between 0-100 **"<<endl;
    }
    else
    break;
    }

    finalGrade=(HW*homeWork)+(midTerm*MID)+(FINAL*finalExam);

    cout<<"\nName :"<<first<<" "<<last<<endl;
    cout<<"Home Work score :"<<homeWork<<endl;
    cout<<"Mid Term Score :"<<midTerm<<endl;
    cout<<"Final Exam Score :"<<finalExam<<endl;
    cout<<"Final Grade :"<<finalGrade<<endl;

      
    return 0;
    }

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

Program code to copy:-

#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <vector>
using namespace std;

namespace myNamespace
{
   //Declaring constants
   const double HW = 0.55;
   const double MID=0.20;
   const double FINAL=0.25;
   //Declare enum for grades
   enum scoreLetter{A,B,C,D,F};
}

//Functional Prototypes
double final_Score(double hwAvg,double mtScore,double feScore, char &ltrGrade);
myNamespace::scoreLetter score_Letter(int score);

int main() {

   string first,last;
   double homeWork,midTerm,finalExam,finalGrade;
   char letterGrade;

   cout << "Student Grade Calculation Form" << endl;
   cout<<"First Name : ";
   cin>>first;
   cout<<"Last Name : ";
   cin>>last;

   while(true)
   {
       cout<<"Homework Average: ";
       cin>>homeWork;
       if(homeWork<0 || homeWork>100)
       {
           cout<<"** Invalid.Must be between 0-100 **"<<endl;
       }
       else
           break;
   }  

   while(true)
   {  
       cout<<"Midterm Grade: ";
       cin>>midTerm;
       if(midTerm<0 || midTerm>100)
       {
           cout<<"** Invalid.Must be between 0-100 **"<<endl;
       }
       else
           break;
   }

   while(true)
   {  
       cout<<"Final Exam Grade: ";
       cin>>finalExam;
       if(finalExam<0 || finalExam>100)
       {
           cout<<"** Invalid.Must be between 0-100 **"<<endl;
       }
       else
           break;
   }

   //Calling function to calculate final score and letter grade
   finalGrade = final_Score(homeWork,midTerm,finalExam,letterGrade);

   //Printing result
   cout<<"\nStudent: "<<first<<" "<<last<<endl;
   cout<<"Completed the course with a final grade of: "<<finalGrade<<" or "<<letterGrade << endl;
   cout<<"Progressing Complete!!!!!"<<endl;
  
   return 0;
}

//Function to calculate final score and letter grade
//Function is a value return with a reference parameter
double final_Score(double hwAvg,double mtScore,double feScore, char &ltrGrade)
{
   double finalGrade;
  
   //Calculating final score
   finalGrade = (myNamespace::HW*hwAvg)+(mtScore*myNamespace::MID)+(myNamespace::FINAL*feScore);
   //Calling function to get the score letter
   myNamespace::scoreLetter letter = score_Letter(finalGrade);
   //Converting enum letter grade to char
   for(int i=0; i<5; i++)
   {
       if(letter==i)
           ltrGrade = 'A' + i;
   }
                  
   return finalGrade;
}

//Function to determine the score letter
myNamespace::scoreLetter score_Letter(int score)
{
   myNamespace::scoreLetter letter;
   if(score>=90)
       letter = myNamespace::A;
   else
       if(score>=80)
           letter = myNamespace::B;
       else
           if(score>=70)
               letter = myNamespace::C;
           else
               if(score>=60)
                   letter = myNamespace::D;
               else
                   letter = myNamespace::F;   
                  
   return letter;
}

Screenshot of output:-

Add a comment
Know the answer?
Add Answer to:
(C++) I need to alter the code below to fit the given requirements. You will need...
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
  • C++. I need to alter this code below to the current specifications. Console Progressing Complete!!! Specifications...

    C++. I need to alter this code below to the current specifications. Console Progressing Complete!!! Specifications Included is an input file. Included is a function to aide, if needed Use the functions, enum, and namespace defined in Assignment 6. You will need to use a loop to read each student’s data You will need to load every homework grade into an array Calculate the homework average The homework average can be calculated while the array is loaded Move the printing...

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

  • Today assignment , find the errors in this code and fixed them. Please I need help...

    Today assignment , find the errors in this code and fixed them. Please I need help with find the errors and how ro fixed them. #include <iostream> #include <cstring> #include <iomanip> using namespace std; const int MAX_CHAR = 100; const int MIN_A = 90; const int MIN_B = 80; const int MIN_C = 70; double getAvg(); char determineGrade(double); void printMsg(char grade); int main() { double score; char grade; char msg[MAX_CHAR]; strcpy(msg, "Excellent!"); strcpy(msg, "Good job!"); strcpy(msg, "You've passed!"); strcpy(msg, "Need...

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

  • I am working on this switch program everything seems to be ok but the compiler is...

    I am working on this switch program everything seems to be ok but the compiler is giving me an error on the final closing brace and wanted to know where I am making an error #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { int choice; char repeat; double MidTerm = 0; double FinalExam = 0; double Quiz1 = 0; double Quiz2 = 0; double MidTermGrade = 1, FinalExamGrade = 2, Quiz1Grade = 3, Quiz2Grade = 4,...

  • For the following task, I have written code in C and need help in determining the...

    For the following task, I have written code in C and need help in determining the cause(s) of a segmentation fault which occurs when run. **It prints the message on line 47 "printf("Reading the input file and writing data to output file simultaneously..."); then results in a segmentation fault (core dumped) I am using mobaXterm v11.0 (GNU nano 2.0.9) CSV (comma-separated values) is a popular file format to store tabular kind of data. Each record is in a separate line...

  • How could I separate the following code to where I have a gradebook.cpp and gradebook.h file?...

    How could I separate the following code to where I have a gradebook.cpp and gradebook.h file? #include <iostream> #include <stdio.h> #include <string> using namespace std; class Gradebook { public : int homework[5] = {-1, -1, -1, -1, -1}; int quiz[5] = {-1, -1, -1, -1, -1}; int exam[3] = {-1, -1, -1}; string name; int printMenu() { int selection; cout << "-=| MAIN MENU |=-" << endl; cout << "1. Add a student" << endl; cout << "2. Remove a...

  • 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++ Write a function so that the main() code below can be replaced by the simpler...

    C++ Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original main(): int main() { double milesPerHour; double minutesTraveled; double hoursTraveled; double milesTraveled; cin >> milesPerHour; cin >> minutesTraveled; hoursTraveled = minutesTraveled / 60.0; milesTraveled = hoursTraveled * milesPerHour; cout << "Miles: " << milesTraveled << endl; return 0; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include <iostream> using...

  • I need assistance with the C++ code below to remove the "this" pointers while maintaining the...

    I need assistance with the C++ code below to remove the "this" pointers while maintaining the code's current output and functionality. Also, there should be a private class in the header file, but I'm not sure what I should include there. Any help would be greatly appreciated! ***main.cpp driver file*** #include <iostream> #include "vector.h" using namespace std; int main() {   vectorInfo v1(7, 6);   vectorInfo v2(5, 4);       v1.set(3, 2);   cout << "v1 : ";   v1.print();       cout << "v2 :...

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