Question

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 5 elements. Initialize the elements to:

2,8,6,16,10

-1, -2, -3, -4, -5

9,6,9,20,27

49, 63, 89, 12, 17

-900, -800, 800, 600, 200

Display the menu and then execute the user's choice. Keep displaying the menu (and executing the user's choice) until the user chooses Option 5. (See pseudocode in this lesson for design help.)

Execute the chosen menu option by passing the array to a specific function which will do the work (in other words, there will be 4 array processing functions and one exit function).

No global variables, although global constants are fine. Remember, you MUST pass the array to the functions and not do the work in main().

Pseudocode for driving a menu (see how the default part of the switch statement catches the bad menu input?)

choice = 0;

while (choice != 3) //assume 3 is the exit out

choice = functionDisplayMenu()

switch on choice

case 1:

functionOption1(myArray);

break;

case 2:

functionOption2(myArray);

break;

case 3:

functionExitCode()

default:

displayError("wrong menu choice")

end switch

end while

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

Dear Student,

Here is the complete C++ program which fullfill the requirement of the given question.

Plese note that the below program is tested on ubuntu 14.04 sytem and compiled under g++ compiler.

Program:

----------------------------------------------------------------------------------------------------------------------------------

//Inclusion of header files

#include<iostream>

#include<stdlib.h>

#include<string.h>

#include<iomanip>

// Name Space Declaration

using namespace std;

//Starting of Main Function

int main()

{

//Data Type Declaration

char option;

int i, j;

int sum =0;

int temp[5][5];

// Array Initialization

int array[5][5] = {{2,8,6,16,10},{-1,-2,-3,-4,-5},{9,6,9,20,27},{49,63,89,12,17},{-900,-800,800,600,200}};

// Display Menu on the Screen

do

{

cout <<"\n1.Display array"<<endl;

cout <<"2.Add up all elements in the array and display that number"<<endl;

cout <<"3.Add 1 to each element in the array"<<endl;

cout <<"4.Swap the values in row on with the values in row three"<<endl;

cout <<"5.Exit"<<endl;

cout << "\nPlease select the option to perform from the above given menu: ";

cin >>option;


//Switching to case as choice selected by the user

switch(option)

{

case '1':

        for(i=0;i<5;i++)

        {

        for(j=0;j<5;j++)

        {

        cout<<array[i][j]<<"\t";

        }

        cout<<endl;

        }

        break;

case '2':

        for(i=0;i<5;i++)

        {

        for(j=0;j<5;j++)

        {

        sum = sum + array[i][j];

        }

        }

        cout<<"\nSum of all the array element is: "<<sum<<endl;

        break;

case '3':

        for(i=0;i<5;i++)

        {

        for(j=0;j<5;j++)

        {

        array[i][j] = array[i][j]+1;

        cout<<array[i][j]<<"\t";

        }

        cout<<endl;

        }

break;

case '4':

       cout<<"After Swaping the elements of array are: ";

       for(i=0;i<5;i++)

        {

        for(j=0;j<5;j++)

        {

        temp[0][j] = array[0][j];

        array[0][j] = array[2][j];

        array[2][j] = temp[0][j];

        cout<<array[i][j]<<"\t";

        }

        cout<<endl;

        }

        break;

case '5':

        cout<<"Exiting from the program. Thank you..!!!"<<endl;

        return 1;

        break;

default:

        cout<<"Wrong Menu Choice"<<endl;

}

}while(option!=5);


return 0;

}

// End of the main function

                                   

------------------------------------------------------------------------------------------------------------------------------------

Here i have attached the output as a screen shot which shows all the operations...

Output:

------------------------------------------------------------------------------------------------------------------------------------

nirmalsharma@ubuntu:-/HomeworkLib_solutionss g++ menu_driven.cpp nirmalsharma@ubuntu:-/HomeworkLib_solutions$ ./a.out 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 on with the values in row three 5. Exit Please select the option to perform from the above given nenu: 1 2 8 6 16 10 9 49 -900 6 63 -800 9 89 800 20 27 17 200 600 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 on with the values in row three 5. Exit Please select the option to perform from the above given nenu: 2 Sum of all the array elenent is: 228 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 on with the values in row three 5. Exit Please select the option to perform from the above given nenu: 3 9 17 10 50 899 64 799 10 90 801 28 18 201 601 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 on with the values in row three 5. Exit Please select the optio

Kindly Check and Verify Thanks.....!!!

Add a comment
Know the answer?
Add Answer to:
Please design, write the code and create the requisite submission files in C++ for the following...
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
  • 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...

  • // Group Names: // Date: // Program Description: //   Import required packages //--> //   Declare class...

    // Group Names: // Date: // Program Description: //   Import required packages //--> //   Declare class (SwitchDoLab) //--> {    //   Declare the main method    //-->    {        //   Declare Constant integers SUM = 1, FACTORIAL = 2, QUIT = 3.        //-->        //-->        //-->        //   Create an integer variable named choice to store user's option.        //-->        //   Create a Scanner object        //   Create...

  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • Write MIPS code, please. Following: Write a program to be used by the Wisconsin DNR to...

    Write MIPS code, please. Following: Write a program to be used by the Wisconsin DNR to track the number of Deer Hunting Licenses issued in a county and the state. It will display a menu with 5 choices numbered 1-5. They are (1) update the count, (2) display the number of licenses already issued to a county whose number is input, (3) display the county number and the number of licenses already issued to a range of counties whose starting...

  • Java Programing Code only Ragged Array Assignment Outcome: Student will demonstrate the ability to create and...

    Java Programing Code only Ragged Array Assignment Outcome: Student will demonstrate the ability to create and use a 2D array Student will demonstrate the ability to create and use a jagged array Student will demonstrate the ability to design a menu system Student will demonstrate the ability to think Program Specifications: Write a program that does the following: Uses a menu system Creates an array with less than 25 rows and greater than 5 rows and an unknown number of...

  • please help fill out the class menu create a prototype that will display information about housing...

    please help fill out the class menu create a prototype that will display information about housing data1. In this prototype you will use dynamic array data structures to store the data and compute metrics. For the requirements of the prototype, your client has given you a list of metrics and operations. The user interface will be a menu that displays this list and prompts the user to choose which option to execute.You will create two classes. First you will create...

  • C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include ...

    C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include <stdio.h> int main() { int fries; // A flag denoting whether they want fries or not. char bacon; // A character for storing their bacon preference. double cost = 0.0; // The total cost of their meal, initialized to start at 0.0 int choice; // A variable new to version 2, choice is an int that will store the // user's menu choice. It will also serve as our loop control...

  • dont use switch E) 120 pts.] Write another function int main ) in C++(and comment the...

    dont use switch E) 120 pts.] Write another function int main ) in C++(and comment the main in Q1.D) that displays the following menu using a do while loop: please choose from the following Menu: I: Populate array with 5 elements 2: Print Array 3: Reverse Array 0: Exit Based, on the user choice, you should call the appropriate function. For example, if the user: - chooses 1, then in function main you should call function populateArray (A, 5); -...

  • THIS IS MY CODE ALL I NEED IS THE SECTIONS TO BE FILLED IN AND CODE...

    THIS IS MY CODE ALL I NEED IS THE SECTIONS TO BE FILLED IN AND CODE SHOULD RUN. FILL IN THE CODE PLEASE. package p02; import static java.lang.System.*; import java.io.*; import java.util.*; public class P02 {    public static Vector<Double> wallet=new Vector<Double>();    public static void addMoneyToWallet(){    }    public static void removeMoneyFromWallet(){    }    public static void displayMoneyInWallet(){    }    public static void emptyWallet(){    }    public static void main(String[] args){ int choice=0; String menu="Wallet...

  • *Answer must be in C* Write a complete program as follows (declare any necessary variables): Create...

    *Answer must be in C* Write a complete program as follows (declare any necessary variables): Create an array of doubles named “hummus” with 2 rows and 300 columns. Initialize all array elements to zero. Write a loop that will repeatedly ask the user to enter a value and store it in the first row of the array (do not overwrite previously entered values) until the whole first row is populated with the user input. (hint the loop should have the...

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