Question

Write a set of C++ programs to implement the following operations listed in the menu function...

Write a set of C++ programs to implement the following operations listed in the menu function below.

a. File: main.cpp - contains the main function

b. File: arrayhw.cpp – contains the 1D array function implementations

c. File: arrayhw.h – contains the 1D array function prototyped declarations

d. May create other files to implement any other needed function

The main menu function should display the following: Main Menu, 1D Array Functions Enter a number to choose one of the following actions: 1. Fill the array with random values 2. Calculate the sum of all array values 3. Calculate the average value of array elements 4. Find maximum value in array 5. Find minimum value in array 6. Display the array values 7. Quit the program.

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

The Code has been posted here:

1. Main.cpp

#include<iostream>
#include "arrayhw.h"
using namespace std;

int main(){

   cout<<"Main Menu, 1D Array Functions Enter a number to choose one of the following actions: \n1. Fill the array with random values \n2. Calculate the sum of all array values \n3. Calculate the average value of array elements \n4. Find maximum value in array \n5. Find minimum value in array \n6. Display the array values \n7. Quit the program.\n";
   int ch = 0, arr[5] = {10,20,30, 40, 50};

   cin>>ch;
  
   switch(ch){
       case 1:
           fillarraywithrandomvalues(arr);          
       break;
       case 2:
           sumofarray(arr);
       break;
       case 3:
           averageofarray(arr);
       break;
       case 4:
           findmax(arr);
       break;
       case 5:
           findmin(arr);
       break;
       case 6:{
           display(arr);
       }
       break;
       case 7:
           quitprog;
       break;
              
   }
  
  
   return 0;
}

2. arrayhw.cpp

#include<iostream>
#include"arrayhw.h"
#include <stdlib.h>
using namespace std;

//Functions inplementation
void fillarraywithrandomvalues(int array[]){
   int val;
   for(int i=0;i<5;i++){
       val = 1 + rand() % 101;
       array[i] = val;
   }
   cout<<"Random Array\n";
   display(array); //Displaying random array

}

void sumofarray(int arr[]){
   float sum = 0.0f;
   for(int i=0;i<5;i++){
       sum += arr[i];
   }
  
   cout<<"Sum of the array = "<<sum<<"\n";
}

void averageofarray(int arr[]){
   float sum = 0.0f;
   for(int i=0;i<5;i++){
       sum += arr[i];
   }
  
   cout<<"Average of the array = "<<sum/5<<"\n";
}

void findmax(int arr[]){
   int max = 0;
   max = arr[0];
   for(int i=0;i<5;i++){
       if(arr[i] > max)
           max = arr[i];
   }
  
   cout<<"Maximum element in the array = "<<max<<"\n";
  
}
void findmin(int arr[]){
   int min = 0;
   min = arr[0];
   for(int i=0;i<5;i++){
       if(arr[i] < min)
           min = arr[i];
   }
  
   cout<<"mininum element in the array = "<<min<<"\n";
  
}
void display(int arr[]){
   for(int i = 0;i<5;i++){
       cout<<"arr[" <<i<<"] --> "<<arr[i]<<"\n";
   }
}

void quitprog(){
   cout<<"quitting...\n";
   exit(0);
}

3. arrayhw.h

//function prototype declarations
void fillarraywithrandomvalues(int []);
void sumofarray(int []);
void averageofarray(int []);
void findmax(int []);
void findmin(int []);
void display(int []);
void quitprog();

output screenshot:

Code screenshot:

main.cpp

Arryahw.cpp

arrayhw.h

Add a comment
Know the answer?
Add Answer to:
Write a set of C++ programs to implement the following operations listed in the menu function...
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
  • Please design, write the code and create the requisite submission files in C++ for the following...

    Please design, write the code and create the requisite submission files in C++ for the following problem: A menu-driven program that offers the user 5 options as follows: Menu: 1. Display array 2. Add up all elements in the array and display that number. 3. Add 1 to each element in the array. 4. Swap the values in row one with the values in row three. 5. Exit In main(), declare and initialize a 2-dimensional array that contains 5 x...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • 2. Write a C++ program, that generates a set of random integers and places them in...

    2. Write a C++ program, that generates a set of random integers and places them in an array. The number of values generated and their range are entered by the user. The program then continually prompts the user for one of the following character commands: a: display all the values I: display the values less than a given value g display the values greater than a given value e: display all odd values o: display all even values q: quit...

  • Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839....

    Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review pointers and dynamic memory allocation posted here under Pages. For sorting, you can refer to the textbook for Co Sci 839 or google "C++ sort functions". I've also included under files, a sample C++ source file named sort_binsearch.cpp which gives an example of both sorting and binary search. The Bubble sort is the simplest. For binary search too, you can refer to...

  • ** C++ LANGUAGE ** Write a function that will implement each Fibonacci number with the help...

    ** C++ LANGUAGE ** Write a function that will implement each Fibonacci number with the help of an integer array of size 100 (elements of this array will be digits of the Fibonacci number). When the function is called to find , it will calculate all Fibonacci numbers from to using the basic formula . To add two Fibonacci numbers, the function will add elements of two arrays corresponding to and and store their sums in the array corresponding to...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • Implement the following in c++ (use "iostream" and "nsmespace std" please.)

    Implement the following: a. A template class named MyArray. 1) MyArray is a dynamic partially filled array for primitive types. 2) data members: - a pointer for the array - any associated variables needed to manage the array. 3) Constructor must insure that specified capacity is possible. Exit the program if an illegal value is specified. 4) “The Big Three” are required to insure deep copy. 5) Private grow function is used to automatically increase the size of the array...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

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
ADVERTISEMENT