Question: C++ make a program with an array of integer values. You will create 2 operations on the array for this lab (and 6 more for
C++
make a program with an array of integer values. You will create 2 operations on the array for this lab (and 6 more for assignment 6) and call each operation from a switch using a do-while loop
#include
using namespace std;
void fillArray(int ar[],int s);
void printArray(const int ar[],int s);
int main()
{
const int SIZE=5;
int ar[SIZE];
int choice;
do
{
cout
cout
cout
cout
cout
switch(choice)
{
case '1':illArray(ar,SIZE);
break;
case '2':printArray(ar,SIZE);
break;
default:"Invalid choice"
}
}
while(choice=true)
fillArray(ar,SIZE);
cout
printArray(ar,SIZE);
cout
return 0;
}
void fillArray(int ar[],int s)
{
for(int i= 0;i
{
cout
cin>>ar[i];
}
}
void printArray(const int ar[],int s)
{
for (int i=0;i
cout
}
Sample Run 1: fill the array 2: print the array 9: quit Enter your choice: 1 Enter a number: 15 Enter a number: 1 Enter a number: 10 Enter a number: -3 Enter a number: 0 1: fill the array 2: print the array 9: quit Enter your choice: 2 The numbers in the array are 15 1 10-3 0 1: fill the array 2: print the array 9: quit Enter your choice: 8 Invalid choice
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
