Question

***C++ Program ONLY*** Menu driven program First load an array(lists) with the values 3, 4, 84,...

***C++ Program ONLY***

Menu driven program

First load an array(lists) with the values 3, 4, 84, 5, 2, 47, and 7 in this order

Then sort the array(list)

Create a program with a menu, with choices 1 for factorial (single value, which everyone will use 20!), 2 for median value , 3 for average, 4 for maximum, 5 for minimum, and 6 to end the program.

Use a do loop (not while)

Python does not have a Do loop, so instead use

while True:

where for quit you can issue the break command

Use a switch statement inside the loop to make your choice of 1, 2, etc. for Java and C++ and an if/elif in Python

You also need to to include a screen shot of your menu on the screen in your submission.

To make for a better looking output, store the function (Factorial, Median, Maximum, etc.) in a string array(list) and your answer in a numeric array(list). (two arrays) Then in the exit module (choice 6) print out your answers. Note this involves running choices 1-6 in order.

***C++ Program ONLY***

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

Solution:

Code:

Output:

Copyable code:

/*Include necessary headers*/

#include<iostream>

#include<list>

#include<vector>

using namespace std;

/*Function definition for factorial*/

void factorial()

{

/*Declaration and initialization*/

int n,number=1;

/*Prompt and get the value*/

cout<<"Enter a value:";

cin>>n;

//Loop

for(int i=2;i<=n;i++)

{

//calculation

number*=i;

}

//Print the result

cout<<"Factorial of "<<n<<" is "<<number<<endl;

}

/*Function definition for total value of list*/

int tot(list<int> list1)

{

/*Declaration and initialization*/

int ini=0;

//Loop

for (list<int>::iterator i=list1.begin(); i!=list1.end(); i++)

ini+= *i;

return(ini) ;

}

/*Function definition for median value*/

int median(list<int> list1)

{

/*Declaration and initialization*/

int ini=0;

//Loop

for (list<int>::iterator i=list1.begin(); i!=list1.end(); i++)

{

if(ini==list1.size()/2)

return(*i);

ini++;

}

return(ini) ;

}

/*Function definition for main*/

int main()

{

/*Declaration and initialization*/

int temp=1,ch;

list<int> arraylist;

arraylist.push_back(3);

arraylist.push_back(4);

arraylist.push_back(84);

arraylist.push_back(5);

arraylist.push_back(2);

arraylist.push_back(47);

arraylist.push_back(7);

arraylist.sort();

/*do...while loop*/

do

{

/*Prompt and get the value*/

cout<<"Enter 1 for factorial"<<endl;

cout<<"Enter 2 for median"<<endl;

cout<<"Enter 3 for average"<<endl;

cout<<"Enter 4 for maximum"<<endl;

cout<<"Enter 5 for minimum"<<endl;

cout<<"Enter 6 to end program"<<endl;

cin>>ch;

//Switch case

switch(ch)

{

case 1: factorial(); break;

case 2: cout<<"Median:"<<median(arraylist)<<endl;break;

case 3:cout<<"Average:"<<tot(arraylist)/arraylist.size()<<endl;break;

case 4: cout<<"Maximum item in list:"<<arraylist.back()<<endl;break;

case 5: cout<<"Minimum item in list:"<<arraylist.front()<<endl;break;

case 6: temp=0;break;

}

}

while(temp);

}

Add a comment
Know the answer?
Add Answer to:
***C++ Program ONLY*** Menu driven program First load an array(lists) with the values 3, 4, 84,...
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++ ONLY*** Menu driven program First load an array(lists) with the values 3, 4, 84, 5,...

    ***C++ ONLY*** Menu driven program First load an array(lists) with the values 3, 4, 84, 5, 2, 47, and 7 in this order Then sort the array(list) Create a program with a menu, with choices 1 for factorial (single value, which everyone will use 20!), 2 for median value , 3 for average, 4 for maximum, 5 for minimum, and 6 to end the program. Use a do loop (not while) Python does not have a Do loop, so instead...

  • Write a menu driven program to demonstrate the use of array and switch. It must be...

    Write a menu driven program to demonstrate the use of array and switch. It must be written in C language . Here is the menu - Press 1 to add a number to the array. Press 2 to display the numbers entered in the array so far Press 3 to find the average of the numbers entered. Press 4 to exit. Option 1 - The user should be able to enter 20 numbers only. If all twenty numbers are entered...

  • Python 3.7 to be used. Just a simple design a program that depends on its own. You should also not need to import anythi...

    Python 3.7 to be used. Just a simple design a program that depends on its own. You should also not need to import anything. No code outside of a function! Median List Traversal and Exception Handling Create a menu-driven program that will accept a collection of non-negative integers from the keyboard, calculate the mean and median values and display those values on the screen. Your menu should have 6 options 50% below 50% above Add a number to the list/array...

  • CSC 130 Lab Assignment 8 – Program Menu Create a C source code file named lab8.c...

    CSC 130 Lab Assignment 8 – Program Menu Create a C source code file named lab8.c that implements the following features. Implement this program in stages using stepwise refinement to ensure that it will compile and run as you go. This makes it much easier to debug and understand. This program presents the user a menu of operations that it can perform. The choices are listed and a prompt waits for the user to select a choice by entering a...

  • Assignment Write a menu-driven C++ program to manage a class roster of student names that can...

    Assignment Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students...

  • Write a menu-driven C++ program to manage a class roster of student names that can grow...

    Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students Q...

  • Objectives: Integer arithmetic, Functions, menus. Write a C++ program that displays the following menu of choices....

    Objectives: Integer arithmetic, Functions, menus. Write a C++ program that displays the following menu of choices. 1. Find the number of digits in an integer. 2. Find the nth digit in an integer. 3. Find the sum of all digits of an integer. 4. Is the integer a palindrome? 5. Quit Enter a choice: Page 1 of 4 For each of the choices (1, 3, 4), Read a positive integer number and call a function that processes the menu choice...

  • Develop a system flowchart and then write a menu-driven C++ program that uses user-defined functions arrays,...

    Develop a system flowchart and then write a menu-driven C++ program that uses user-defined functions arrays, and a random number generator. Upon program execution, the screen will be cleared and the menu shown below will appear at the top of the screen and centered. The menu items are explained below. Help Smallest Quit H or h ( for Help ) option will invoke a function named help() which will display a help screen. The help screen(s) should guide the user...

  • Write a C++ program to run a menu-driven program with the following choices: Count number of...

    Write a C++ program to run a menu-driven program with the following choices: Count number of even digits in a number Compute the factorial of a number Quit Make sure your program conforms to the following requirements: 1. This program should be called playingWithNumbers.cpp 2. Write a function called getValidUserInputPosNumGT0 that allows a user to enter an integer and validated that the number is > 0. It must have a pass by reference parameter that will store the value selected...

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