Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you add the following to the provided code? Add a function to get the student name Add a function to assign a letter grade

Can you add the following to the provided code?

  • Add a function to get the student name
  • Add a function to assign a letter grade called from Main.
  • The letter grade is then passed to the displayResults function
  • Hint: This means you will need to add an extra parameter to the displayResults function
  • Ask the user if she wishes to repeat the program for another student and either loop or end the program.

Don't use global variables.Pass data through function parameters.

------------------------------------------------------------------------------------------------------------------------------------------------

#include

#include

using namespace std;

// 2. function prototypes

void displayResults(string name, float avg); // satisfies the compiler

int getTestScore();

float calcAvg(int t1, int t2, int t3);

bool isValid(int num, int min, int max);

int main()

{

string fullName;

int test1, test2, test3;

float average;

// get student full name

cout << "Student Name: ";

getline(cin, fullName);

// get 3 test scores

test1 = getTestScore();// function call to a value returning function

test2 = getTestScore();

test3 = getTestScore();

// calculate average

average = calcAvg(test1, test2, test3);

// assign a letter grade

// display heading, name and average

displayResults(fullName, average); // function call for a void function

system("pause");

return 0;

}

// 1, Function Defenition

//================================================================

// displayResults outputs the heading and the results of the calculations

// ===============================================================

void displayResults(string name, float avg)// function header, scope

{

cout << "--------------------------------------------------- ";

cout << "Norco College ";

cout << "CIS-5: Into to programming with C++ ";

cout << "Student Averages ";

cout << "--------------------------------------------------- ";

cout << name << ": " << avg << endl;

}

// getTestScore prompts user and gets a single test score

int getTestScore()

{

int score; // scope of operator

int min = 0, max = 100;

cout << "Enter a test score:";

cin >> score;

while (!isValid(score, min, max)) // while score is not valid

{

cout << "Try again. Enter a valid test score:";

cin >> score;

}

return score;// returns a valid test score

}

//calcAvg totals scores and calculate the avgerage

float calcAvg(int t1, int t2, int t3)

{

float avg;

avg = (t1 + t2 + t3) / 3.0;

return avg;

}

// isValid test for valid input and returns true or false

bool isValid(int num, int min, int max)

{

if (num < min || num > max) // invalid data

return false;

else// valid data

return true;

}

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions