Question

DO NOT USE ARRAYS IF YOU KNOW ABOUT ARRAYS, I WANT YOU TO USE 3 VARIABLES,...

DO NOT USE ARRAYS IF YOU KNOW ABOUT ARRAYS, I WANT YOU TO USE 3 VARIABLES, IT WILL FORCE YOU TO USE COMPOUND LOGICAL STATEMENTS FOR THE IF STATEMENTS.

Create a program that will display a menu to the user. The choices should be as follows:

  1. Enter 3 grades
  2. Show average (with the 3 grades) and letter grade
  3. Show highest grade
  4. Show lowest grade
  5. Exit

If you want to put the menu into a function you may. The program should use a switch statement for using the appropriate function based on the user's choice. Each option should be implemented in its own function (I use the word function 1, function 2, I want you to come up with appropriate names for the functions). Initialize the variables for grades randomly between 50-100 so if the user select show average as their first choice, there will be some random grades in the variables already.

You should have the following functions:

Function 1: This function will ask the user for a single grade that will be passed back to the main function. The function should validate that the grade is in the range between 0-100 otherwise ask the user to enter another grade. This function should be called 3 times from the main to place the appropriate values into the grade variables.

Function 2: This function will calculate the average of the 3 grades passed in and display the average with 1 decimal place and display the letter grade based on the following scale:

Average Letter Grade
90 - 100 A
80 - 90 B
70 - 79 C
60 - 69 D
Below 60 F

Function 3: This function will receive 3 grades as parameters and returns the highest grade to the main. The main will use that value to display the highest grade. Do not display the highest grade in this function.

Function 4: This function will receive 3 grades as parameters and returns the lowest grade to the main. The main will use that value to display the lowest grade. Do not display the highest grade in this function.

Use a loop to repeat the entire program until the users hits 5 to exit.

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

#include<iostream>
#include<iomanip>
using namespace std;
float fun1()
{
   float f;
  
   do//validating input
   {cout<<"Enter a grade(1-100):";
   cin>>f;
   if(f<1 ||100<f)cout<<"Invalid grade Enter again\n";
   }while(f<1 ||100<f);//if not in th range
  
return f;  
}
void fun2(float a,float b,float cc)
{
   //finding average
   float av = (a+b+cc)/3;
   cout<<"Average :"<<setprecision(3)<<av<<endl;//displaying upto 1 decimal place
   char c;
   if(90<=av)
   c='A';
   else if(80<=av)
   c='B';
   else if(70<=av)
   c='C';
   else if(60<=av)
   c='D';
   else
   c='F';
   cout<<"Letter grade: "<<c<<endl;
}  

float fun3(float a,float b,float c)
{
   int h=a;
   if(h<b)h=b;
   if(h<c)h=c;
   return h;//returning highest grade
  
}
float fun4(float a,float b,float c)
{
   int h=a;
   if(h>b)h=b;
   if(h>c)h=c;
   return h;//returning smallest grade
  
}
int main()
{
   int cc=0;
   float a=1,b=1,c=1;
   while(1)
   {
       cout<<"Menu :\n";
       cout<<"1:Enter 3 grades\n2:Show average (with the 3 grades) and letter grade\n3:Show highest grade\n4:Show lowest grade\n5:Exit\nEnter:";
       cin>>cc;
       switch(cc)
       {
           case 1://callling function1 3 times
               a=fun1();
               b=fun1();
               c=fun1();
               break;
           case 2:
               fun2(a,b,c);
               break;
           case 3:
               cout<<"Highest grade is :"<<fun3(a,b,c)<<endl;
               break;
           case 4:
               cout<<"Smallest grade is :"<<fun4(a,b,c)<<endl;
               break;
           case 5:
               break;  
       }
       if(cc==5)break;  
   }
  
   return 0;
}

output:

Menu :
1:Enter 3 grades
2:Show average (with the 3 grades) and letter grade
3:Show highest grade
4:Show lowest grade
5:Exit
Enter:1
Enter a grade(1-100):20
Enter a grade(1-100):40
Enter a grade(1-100):7
Menu :
1:Enter 3 grades
2:Show average (with the 3 grades) and letter grade
3:Show highest grade
4:Show lowest grade
5:Exit
Enter:2
Average :22.3
Letter grade: F
Menu :
1:Enter 3 grades
2:Show average (with the 3 grades) and letter grade
3:Show highest grade
4:Show lowest grade
5:Exit
Enter:3
Highest grade is :40
Menu :
1:Enter 3 grades
2:Show average (with the 3 grades) and letter grade
3:Show highest grade
4:Show lowest grade
5:Exit
Enter:4
Smallest grade is :7
Menu :
1:Enter 3 grades
2:Show average (with the 3 grades) and letter grade
3:Show highest grade
4:Show lowest grade
5:Exit
Enter:5


Process exited normally.
Press any key to continue . . .

Add a comment
Know the answer?
Add Answer to:
DO NOT USE ARRAYS IF YOU KNOW ABOUT ARRAYS, I WANT YOU TO USE 3 VARIABLES,...
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
  • You will create a Grade Program that will calculate students’ weighted averages. You are going to...

    You will create a Grade Program that will calculate students’ weighted averages. You are going to have the user enter lab grades, test grades, and project grades. You will then display a grade report of each individual average along with their overall average and letter grade. Ask the user to enter their lab grades. Call the averageGrade function that will allow the user to enter their grades and calculate their average. averageGrade Function: This will pass the average back to...

  • I have to use java programs using netbeans. this course is introduction to java programming so...

    I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...

  • Arrays in Functions 2. Arrays in Functions You can use both the array index variables and...

    Arrays in Functions 2. Arrays in Functions You can use both the array index variables and the entire array itself as arguments to functions. The following program updates the elements of the array grades, one-by-one. Thus, we have used a call-by-reference-ish mechanism to update the values (although no & was used). Note that there is a major difference between the grade in the function call and the one in the function definition. In the statement get_grade (grades[i]); "grades" is the...

  • This should be programmed in C LANGUAGE! This lab requires you to use arrays, loop structures...

    This should be programmed in C LANGUAGE! This lab requires you to use arrays, loop structures and if statements/switch statements. You must use functions where indicated. Test your program often - make sure each bit of functionality works before you continue. In this problem, we want to create a song and play it as we build it. The way we do this is by using arrays to store different notes. Notes are just tones that run for a specific amount...

  • Using the following parallel array and array of vectors: // may be declared outside the main...

    Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS =3; // may only be declared within the main function string Students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Write a C++ program to run a menu-driven program with the following choices: 1) Display the grades 2) Add grade 3) Remove grade for all students for a selected assignment 4) Display Average for each student 5) Display the name of...

  • using java Program: Please read the complete prompt before going into coding. Write a program that...

    using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...

  • Lowest Score Drop In Functions, there can only be one return statement. You can not use...

    Lowest Score Drop In Functions, there can only be one return statement. You can not use an exit or break function. Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions: void getScore() should ask the user for a test score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of...

  • Write a C++ Program. you were required to first create a function called average. The return...

    Write a C++ Program. you were required to first create a function called average. The return type is double and it takes in two parameters, one of type string the other of type double. In the average function write a for loop that PROMPT THE USER to enter in a grade 5 times, keep a sum of all the different grades then return the average of the grades. (sum / 5) Next write a function of type double called lowest...

  • In this project, you will use functions and dictionaries to track basketball players and their respective...

    In this project, you will use functions and dictionaries to track basketball players and their respective points, then display statistics of points made. You will need three functions as follows: def freeThrowMade(playerDictionary, playerName) - this function will add 1 point to the player's total score def twoPointMade(playerDictionary, playerName) - this function will add 2 points to the player's total score def threePointMade(playerDictionary, playerName) - this function will add 3 points to the player's total score Each of these functions has...

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

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