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

In C++: Create a function named branchInfo()that accepts an integer argument and

ID: 3711054 • Letter: I

Question

In C++:

Create a function named branchInfo()that accepts an integer argument and displays the correct contact data for each of five branch offices of a loan company (manager’s name, street address, and phone number). Write a main()function that contains an enumeration for the five branch office names. For example, you might choose to call the offices NORTH, SOUTH, EAST, WEST, and CENTRAL. Display the contact data for all five offices using the enumerations in a loop. Save the file as UsingAllEnumerations.cpp.

Explanation / Answer

#include <iostream>

using namespace std;

void branchInfo(int loc)

{

/* Switch to uniquely identify the branch

* name(consider name as id in integer format)

*/

switch(loc)

{

/* A structure can be created and branch info can be stored and

* retrieved in one go, but as it is not mentioned in the question

* leaving as an user task.

*/

case 0: /* North */

cout<<"Manager's name: Manager of North Branch"<<endl;

cout<<"Street Address: North Street"<<endl;

cout<<"Phone Number: +00 111 222 333"<<endl;

break; /* break the case, else it will fall down to other cases */

case 1: /* SOUTH */

cout<<"Manager's name: Manager of SOUTH Branch"<<endl;

cout<<"Street Address: SOUTH Street"<<endl;

cout<<"Phone Number: +01 111 222 333"<<endl;

break;

case 2: /* EAST */

cout<<"Manager's name: Manager of EAST Branch"<<endl;

cout<<"Street Address: EAST Street"<<endl;

cout<<"Phone Number: +02 111 222 333"<<endl;

break;

case 3: /* WEST */

cout<<"Manager's name: Manager of WEST Branch"<<endl;

cout<<"Street Address: WEST Street"<<endl;

cout<<"Phone Number: +03 111 222 333"<<endl;

break;

case 4: /* CENTRAL */

cout<<"Manager's name: Manager of CENTRAL Branch"<<endl;

cout<<"Street Address: CENTRAL Street"<<endl;

cout<<"Phone Number: +04 111 222 333"<<endl;

break;

}

}

int main()

{

/* Enumeration to hold branch office names

* We use the property of enum: where if

* value is not defined for each enum variable

* then it assigns values from 0 and increments

* up along the way. (As it is shown below: default values)

*/

enum branch

{ NORTH, /* default value: 0 */

SOUTH, /* default value: 1 */

EAST, /* default value: 2 */

WEST, /* default value: 3 */

CENTRAL /* default value: 4 */

};

/* To display the contact data for all five offices using a loop.

* Assign the loop with the initial variable of the enum,

* here we are able to get the next respective variables of enum

* because they are not initialized by the user and hence, It will start

* at 0 and increments up along the way.

*/

for (int d=NORTH; d<5; ++d)

/* call the branchinfo function with an argument

* branch name in integer format

*/

branchInfo(d);

return 0;

}