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
( 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 .
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...
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
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...
Write a program that prompts the user to enter a positive integer and then computes the...
Write a program that prompts the user to enter a positive integer and then computes the equivalent binary number and outputs it. The program should consist of 3 files. dec2bin.c that has function dec2bin() implementation to return char array corresponding to binary number. dec2bin.h header file that has function prototype for dec2bin() function dec2binconv.c file with main function that calls dec2bin and print results. This is what i have so far. Im doing this in unix. All the files compiled...
Problem 4 : Write a program that prompts the user to enter in an integer and...
Problem 4 : Write a program that prompts the user to enter in an integer and then prints as shown in the example below Enter an integer 5 // User enters 5 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 Bye
IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT