Question

In: Computer Science

IN C++ ONLY... please do both parts of this task ..1 part- Menu driven program First...

IN C++ ONLY... please do both parts of this task ..1 part- Menu driven program First load an array(lists) with the values 3, 4, 84, 5, 2, 47, and 7 in this order by using a function. Then sort the array(list) Use a function to display the menu. 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) Use a switch statement inside the loop to make your choice of 1, 2, etc. 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. AND 2.part-- Redo this by adding a menu option for standard deviation of a population. You move option 6 down to option 7 and your std dev would be option 6. As an added bonus, send the STD Deviation to a sub/module/function to be printed to the screen. Send to the file in the main module because this is where you have defined all of your file objects, and they would not exist in another module. Basic steps: For the standard deviation you have to create a 2nd array(list). I called mine deviations. This array has to be at least as large as the array for your numbers. Then walk through the first array again and subtract the average(mean) from each value in the first array and put this difference(deviation) in the 2nd array. Some of these values will be positive and some will be negative. Walk through the 2nd array again (deviations) and square them, which will make them all positive. Walk through the 2nd array again and sum the deviations. divide the deviations by the count Take the squareroot of the (deviations/count) and you get the STD Deviation. Remember, you are taking the STD Deviation of a population, so you divide by N, not n-1 where n is the sample size. When I say walk through the array, I mean go through the array from row zero to the last row.

Solutions

Expert Solution

1)

Complete Code:

#include<iostream>
#include<string.h>
using namespace std;


int fact(int num){
   if(num<=0) return 1;
   else return num*fact(num-1);
}

int median(int arr[], int n){
   return arr[n/2];
}

int minimum(int arr[], int n){
   int min = arr[0];
   for(int i=0; i<n; i++){
   if(arr[i]<min)
   min = arr[i];
   }
   return min;
}

int maximum(int arr[], int n){
   int max = arr[0];
   for(int i=0; i<n; i++){
   if(arr[i]>max)
   max = arr[i];
   }
   return max;
}

double average(int arr[], int n){
   double avg = 0.0;
   for(int i=0; i<n; i++){
   avg += arr[i];
   }
   avg /= n;
   return avg;
}

int main(){
   int arr[] = {3, 4, 84, 5, 2, 47, 7};
   unsigned int ans[5] = {0};
   string menu[] = {"Factorial","Median", "Average", "Maximum", "Minimum"};
   int n = 7, choice;
  
   do{
  
       cout<<"\n******* MENU *****"<<endl;
       cout<<"1. Factorial"<<endl;
       cout<<"2. Median"<<endl;
       cout<<"3. Average"<<endl;
       cout<<"4. Maximum"<<endl;
       cout<<"5. Minimum"<<endl;
       cout<<"6. Quit"<<endl;
      
       cout<<"Enter choice: ";
       cin>>choice;
      
       switch(choice){
           case 1:
               ans[0] = fact(20);
               cout<<"Factorial value is: "<<ans[0]<<endl;
               break;
           case 2:
               ans[1] = median(arr, n);
               cout<<"Median value is: "<<ans[1]<<endl;
               break;
           case 3:
               ans[2] = average(arr, n);
               cout<<"Average value is: "<<ans[2]<<endl;
               break;
           case 4:
               ans[3] = maximum(arr, n);
               cout<<"Maximum value is: "<<ans[3]<<endl;  
               break;
           case 5:
               ans[4] = minimum(arr, n);
               cout<<"Minimum is: "<<ans[4]<<endl;
               break;
           case 6:
               cout<<"******* Answers *******"<<endl;
               for(int i=0;i<5;i++)
               {
                   cout<<" "<<menu[i]<<": "<<ans[i]<<endl;
               }
               cout<<"Good bye!"<<endl;
               exit(0);
               break;  
           default:  
               cout<<"Invalid choice!"<<endl;
       }
      
   }while(choice!=n);

   return 0;

}

OUTPUT:

2)

Complete Code:

#include<iostream>
#include<string.h>
using namespace std;


int fact(int num){
   if(num<=0) return 1;
   else return num*fact(num-1);
}

int median(int arr[], int n){
   return arr[n/2];
}

int minimum(int arr[], int n){
   int min = arr[0];
   for(int i=0; i<n; i++){
   if(arr[i]<min)
   min = arr[i];
   }
   return min;
}

int maximum(int arr[], int n){
   int max = arr[0];
   for(int i=0; i<n; i++){
   if(arr[i]>max)
   max = arr[i];
   }
   return max;
}

double average(int arr[], int n){
   double avg = 0.0;
   for(int i=0; i<n; i++){
   avg += arr[i];
   }
   avg /= n;
   return avg;
}

int stdd(int arr[], int n){
   int avg = average(arr, n);
   int d2[n] = {0};
   for(int i=0; i<n; i++){
       d2[i] = arr[i]-avg;
   }
   for(int i=0; i<n; i++){
       d2[i] = d2[i]*d2[i];
   }
   int sum=0;
   for(int i=0; i<n; i++){
       sum += d2[i];
   }
  
   return sum/n;
}

int main(){
   int arr[] = {3, 4, 84, 5, 2, 47, 7};
   unsigned int ans[6] = {0};
   string menu[] = {"Factorial","Median", "Average", "Maximum", "Minimum", "Standard Deviation"};
   int n = 7, choice;
  
   do{
  
       cout<<"\n******* MENU *****"<<endl;
       cout<<"1. Factorial"<<endl;
       cout<<"2. Median"<<endl;
       cout<<"3. Average"<<endl;
       cout<<"4. Maximum"<<endl;
       cout<<"5. Minimum"<<endl;
       cout<<"6. Standard deviation"<<endl;
       cout<<"7. Quit"<<endl;
      
       cout<<"Enter choice: ";
       cin>>choice;
      
       switch(choice){
           case 1:
               ans[0] = fact(20);
               cout<<"Factorial value is: "<<ans[0]<<endl;
               break;
           case 2:
               ans[1] = median(arr, n);
               cout<<"Median value is: "<<ans[1]<<endl;
               break;
           case 3:
               ans[2] = average(arr, n);
               cout<<"Average value is: "<<ans[2]<<endl;
               break;
           case 4:
               ans[3] = maximum(arr, n);
               cout<<"Maximum value is: "<<ans[3]<<endl;  
               break;
           case 5:
               ans[4] = minimum(arr, n);
               cout<<"Minimum is: "<<ans[4]<<endl;
               break;
           case 6:
               ans[5] = stdd(arr, n);
               cout<<"Minimum is: "<<ans[5]<<endl;
               break;
           case 7:
               cout<<"******* Answers *******"<<endl;
               for(int i=0;i<6;i++)
               {
                   cout<<" "<<menu[i]<<": "<<ans[i]<<endl;
               }
               cout<<"Good bye!"<<endl;
               exit(0);
               break;  
           default:  
               cout<<"Invalid choice!"<<endl;
       }
      
   }while(choice!=n);

   return 0;

}

OUTPUT:


Related Solutions

Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End...
Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End Program.The user can only input a positive integer (0 does not count) and if the input is not a positive integer the program must state "Invalid Input." The program must determine whether the input is even or odd. The program must use functions and can only use the iostream and iomanip libraries. Note: The program must loop until the 2nd menu option is chosen.
Write a menu driven C++ program that prints the day number of the year , given...
Write a menu driven C++ program that prints the day number of the year , given the date in the form of month-day-year. For example , if the input is 1-1-2006 , then the day number is 1. If the input is 12-25- 2006 , the day number is 359. The program should check for a leap year. A year is leap if it is divisible by 4 but not divisible by 100. For example , 1992 , and 2008...
In C++ Language English/Spanish Translation Program. Create a menu driven program that translates English to Spanish...
In C++ Language English/Spanish Translation Program. Create a menu driven program that translates English to Spanish and Spanish to English. Your translation program should use arrays for this program. You will need to populate the arrays with the contents of the English and Spanish data files provided. The two files are ordered such that each word in the one file corresponds to the respective translation in the other (i.e.: the first word in the ENG.txt file corresponds to the first...
C++ Programming Develop and submit an original implementation of a menu-driven program performing a number of...
C++ Programming Develop and submit an original implementation of a menu-driven program performing a number of tasks relating to student marks scored in a number of assessments including: displaying all marks, adding new student marks, calculating the mean score, median score, finding the minimum and maximum scores as well as displaying the average mark of a given student. The problem: Student marks are kept in a text file as a single column. Each student may have a different number of...
C++ ^ ^ Write a menu driven program to perform following operations using a map container...
C++ ^ ^ Write a menu driven program to perform following operations using a map container that stores the information about USA Population (In Million). @@@Menu@@@ 1. Add Information 2. Display Information 3. Update Information 4. Erase Information 5. Clear Information For example, Suppose the map initially contains following information (Use emplace() function to store the information) 2010, 309.33 2011, 311.58 2012, 313.87 2015, 320.74 2016, 323.07 The program should produce the desired output when a valid input is provided,...
Please C++ create a program that will do one of two functions using a menu, like...
Please C++ create a program that will do one of two functions using a menu, like so: 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 1 Enter Catalan number to calculate: 3 Catalan number at 3 is 5 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 2 Enter Fibonacci number to calculate: 6 Fibonacci number 6 is 8 Create a function of catalan that will take a parameter and return...
Programing lanugaue is C++ Purpose of code: Plan and code a menu-driven modular program utilizing an...
Programing lanugaue is C++ Purpose of code: Plan and code a menu-driven modular program utilizing an array An input file has an unknown number of numeric values(could be empty too).Read the numbers from the input fileand store even numbers in one arrayand odd numbers in another array.Create menu options to Display count of even numbers, count of odd numbersand the sum values in each array Determine the average of each array Determine the median of each array Sort each array...
No Global variables No goto statement No break outside switch Write a menu driven C program...
No Global variables No goto statement No break outside switch Write a menu driven C program using functions and switch. Feel free to use “Empty Outlines” template from Canvas to design the functions as needed to build the code. Make sure to submit your work through Canvas. You can show me your code running in class when you are done. The program shows following menu to the user repetitively until user selects option 3 to exit. Circle Triangle Exit Based...
This is an exercise for a menu-driven program. Program should use shell functions. Write a program...
This is an exercise for a menu-driven program. Program should use shell functions. Write a program that displays the following menu: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a rectangle 3. Calculate the area of a triangle 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for the radius of the circle and then display the area. Use the following formula to calculate the circle’s area: ?...
Original C code please. Part 1: You can do A, B, and C in one program...
Original C code please. Part 1: You can do A, B, and C in one program with multiple loops (not nested) or each one in a small program, it doesn’t matter. A. Create a loop that will output all the positive multiples of 9 that are less than 99. 9 18 27 36 45        …. B. Create a loop that will output all the positive numbers less than 200 that are evenly divisible by both 2 and 7. 14        28       ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT