Question

In: Computer Science

Declare local variables under main() program Prompts the user to enter 5 test scores Define a...

Declare local variables under main() program

Prompts the user to enter 5 test scores

Define a function to calculate the average score: this should accept 5 test scores as argument and return the avg

Define a function to determine the letter grade: this should accept a test score as argument and return a letter grade based on the following grading scale.

Score         Letter Grades

90-100                A

80-89                   B

70-79                   C

60-69                   D

Below 60            F

Solutions

Expert Solution

I'm writing the code in C++:

Program:

#include <iostream>

using namespace std;

float calc_avg(int x1, int x2, int x3, int x4, int x5)//function to calculate average
{
float avg;
avg=(x1+x2+x3+x4+x5)/5;//calculating average
return avg;
}
char assign_grade(int y1)//function to assign grade
{
char grade;
if(y1>=90 && y1<=100)//assigning grades according to conditions
grade='A';
else if(y1>=80 && y1<=89)
grade='B';
else if(y1>=70 && y1<=79)
grade='C';
else if(y1>=60 && y1<=69)
grade='D';
else
grade='F';
return grade;
}
int main(){
int n1,n2,n3,n4,n5,a;
char g;
cout<<"Enter 5 test scores:\n";
cin>>n1>>n2>>n3>>n4>>n5;//taking 5 user test scores input

cout<<"\ngrades assigned:\n";
g=assign_grade(n1);//calling function for assigning grade
cout<<"n1\t"<<g<<"\n";
g=assign_grade(n2);
cout<<"n2\t"<<g<<"\n";
g=assign_grade(n3);
cout<<"n3\t"<<g<<"\n";
g=assign_grade(n4);
cout<<"n4\t"<<g<<"\n";
g=assign_grade(n5);
cout<<"n5\t"<<g<<"\n";

cout<<"\naverage value:\n";
a=calc_avg(n1,n2,n3,n4,n5);//calling function to calculate average
cout<<a;
  
return 0;
}

Output:


Related Solutions

USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program...
USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program should display a letter grade for each score and the average test score. Hint: Declare local variables under main() program Prompts the user to enter 5 test scores Define a function to calculate the average score: this should accept 5 test scores as argument and return the avg Define a function to determine the letter grade: this should accept a test score as argument...
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
Write a test program that prompts the user to enter a sequence of numbers ending with...
Write a test program that prompts the user to enter a sequence of numbers ending with 0, and invokes this method to return the largest number in the input. Use inheritance and polymorphism approach. in java please
JAVA Write a test program that prompts the user to enter a series of integers and...
JAVA Write a test program that prompts the user to enter a series of integers and displays whether the series contains runLength consecutive same-valued elements. Your program’s main() must prompt the user to enter the input size - i.e., the number of values in the series, the number of consecutive same-valued elements to match, and the sequence of integer values to check. The return value indicates whether at least one run of runLength elements exists in values. Implement the test...
JAVA Write a test program that prompts the user to enter a list and displays whether...
JAVA Write a test program that prompts the user to enter a list and displays whether the list is sorted or not. Here is a sample run. Note that the program first prompts the user to enter the size of the list. Using Array My output should look like this Enter the size of the list: 8 Enter the contents of the list: 10 1 5 16 61 9 11 1 The list has 8 integers 10 1 5 16...
Write a program that asks the user to enter five test scores. The program should display...
Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: calcAverage: This method should accept five test scores as arguments and return the average of the scores. determineGrade: This method should accept a test score as an argument and return a letter grade for the score, based on the following grading scale: Score Letter Grade 90-100...
( USE C++ ) The program prompts the user to enter a word. The program then...
( USE C++ ) The program prompts the user to enter a word. The program then prints out the word with letters in backward order. For example, if the user enter "hello" then the program would print "olleh" show that it works .
Instructions Write a Java program that asks the user t enter five test scores. The program...
Instructions Write a Java program that asks the user t enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: * calcAverage -- This method should accept five test scores as arguments and return the average of the scores. * determineGrade -- This method should accept a test score as an argument and return a letter grade for the score, based on the following...
JAVA 5- Write a program that prompts the user to enter two (2) numbers and compute...
JAVA 5- Write a program that prompts the user to enter two (2) numbers and compute the sum of the numbers between these two numbers (including the numbers entered). If the user Enters 2 and 6. The program will calculate the sum of the numbers: 2+3+4+5+6 and will display the result. Enter First number> 2 Enter second number> 6 The sum is 20
In C++ 2. Test Scores #2 Modify the program #1 to allow the user to enter...
In C++ 2. Test Scores #2 Modify the program #1 to allow the user to enter name-score pairs. For each student taking a test, the user types a string representing the name of the student, followed by an integer representing the student's score. (use a structure) Modify the average-calculating function so they take arrays of structures, with each structure containing the name and score of a single student. In traversing the arrays, use pointers notation rather than array indices. (myArray->name...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT