Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ You will ask the user which problem to run from the main function: Problem #

ID: 3881339 • Letter: C

Question

C++

You will ask the user which problem to run from the main function:

Problem #1 or #2:

Use a switch/case type statement to determine which was chosen. Call a function to handle each type, such as problem1(), problem2(). Any functions you create should be placed after the main() function and thus require a prototype before main().

PROBLEM 1-------------------------------------------------

Write a function that returns nothing and takes no parameters to take 5 integers from the user, place them in an array, then print them out in reverse order.

Example Output------------

Problem #? (1,2,3):1

Enter 5 integers :1

2

3

4

5

In reverse order:5 , 4 , 3 , 2 , 1

PROBLEM 2----------------------------------------

Create a function that takes 5 integers from the user

The array will be passed to a function that displays which ones of those 5 integers are evenly divisible by 3

Example Output-------------------------

Problem #? (1,2):2

Enter 5 integers you wish to check for divisiblity by 3:1

5

11

30

33

Number 1 is not divisible by 3.

Number 5 is not divisible by 3.

Number 11 is not divisible by 3.

Number 30 is divisible by 3.

Number 33 is divisible by 3.

Explanation / Answer

#include <iostream.h>

#include<conio.h>

void problem1();/* Function 1 prototype */

void problem2();/* Function 2 prototype*/

void main()

{

clrscr();

float x, y;

int choice;

cout << "Problem #? (1,2):" << endl; /* switch/case type statement to determine which has to be chosen */

cin >> choice;

switch (choice)

{

case 1:

problem1(); /* Calling function1 */

break;

case 2:

problem2(); /* Calling function2 */

default:

cout << "Invalid input" << endl;

}

getch();

}

void problem1() /* Function 1 declaration */

{

int a[5],i;

cout<<"Enter 5 integers ";

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

cin>>a[i];

cout<<"The reverse order is:"<<a[4]<<" "<<a[3]<<" "<<a[2]<<" "<<a[1]<<" "<<a[0]<<" ";

}

void problem2() /* Function 2 declaration */

{

int a[5],i;

cout<<"Enter 5 integers ";

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

{

cin>>a[i];

}

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

{

if((a[i]%3)==0)

cout<<"Number"<<i+1<<"is divisible by 3"<<" ";

else

cout<<"Number"<<i+1<<"is not divisible by 3"<<" ";

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote