Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need to change the following code to c++ to give the following output --------------------------------------------------------------------------------------------------------- import java.util.Scanner; public class Assignment6 { public static void main(String[] args)

need to change the following code to c++ to give the following output

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

import java.util.Scanner;

public class Assignment6

{

public static void main(String[] args)

{

int number, size;

String choice;

char command;

Scanner keyboard = new Scanner(System.in);

// ask a user for a array size

System.out.println("Please enter a size for the array. ");

size = keyboard.nextInt();

// instantiate a NumberCollection object

NumberCollection collection = new NumberCollection(size);

// print the menu

printMenu();

do

{

// ask a user to choose a command

System.out.println(" Please enter a command or type ?");

choice = keyboard.next().toLowerCase();

command = choice.charAt(0);

switch (command)

{

case 'a': // add a number

System.out.println(" Please enter an integer to add.");

number = keyboard.nextInt();

if(collection.addNumber(number))

System.out.println(" " + number + " successfully added.");

else

System.out.println(" " + number + " is already in the array. " + number + " was not added.");

break;

case 'b': // print the collection

System.out.println(" " + collection);

break;

case 'c': // compute and display the maximum

System.out.println(" The maximum is: " + collection.findMax());

break;

case 'd': // compute and display the minimum

System.out.println(" The minimum is: " + collection.findMin());

break;

case 'e': // compute and display the sum

System.out.println(" The sum is: " + collection.computeSum());

break;

case '?':

printMenu();

break;

case 'q':

break;

default:

System.out.println("Invalid input!");

}

} while (command != 'q');

} //end of the main method

// this method prints out the menu to a user

public static void printMenu()

{

System.out.print(" Command Options "

+ "----------------------------------- "

+ "a: add an integer in the array "

+ "b: display the array "

+ "c: compute and display the maximum "

+ "d: compute and display the minimum "

+ "e: compute and display the sum "

+ "?: display the menu again "

+ "q: quit this program ");

} // end of the printMenu method

}

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

here is the fuction list that i need for the array

image text in transcribed

HERE IS THE SAMPLE OUTPUT THANK YOU

image text in transcribed

image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago