203k views
3 votes
Write a program that use a switch statement whose controlling expression is the variable area code. If the value of area_code is in the table, the switch statement will print the corresponding city's name to the screen. Otherwise, the switch statement will print the message "Area code not found." to the screen. Use case "fall throughs" in order to simplify the switch block as much as possible.

User Srquinn
by
5.2k points

1 Answer

1 vote

Answer:

Table for Area codes are not missing;

See Attachment for area codes and major city I used

This program will be implemented using c++ programming language.

// Comments are used for explanatory purposes

// Program starts here

#include <iostream>

using namespace std;

int main( )

{

// Declare Variable area_code

int area_code;

// Prompt response from user

cout<<Enter your area code: ";

cin<<"area_code;

// Start switch statement

switch (area_code) {

// Major city Albany has 1 area code: 229...

case 229:

cout<<"Albany\\";

break;

// Major city Atlanta has 4 area codes: 404, 470 678 and 770

case 404:

case 470:

case 678:

case 770:

cout<<"Atlanta\\";

break;

//Major city Columbus has 2 area code:706 and 762...

case 706:

case 762:

cout<<"Columbus\\";

break;

//Major city Macon has 1 area code: 478...

case 478:

cout<<"Macon\\";

break;

//Major city Savannah has 1 area code: 912..

case 912:

cout<<"Savannah\\";

break;

default:

cout<<"Area code not recognized\\";

}

return 0;

}

// End of Program

The syntax used for the above program is; om

Write a program that use a switch statement whose controlling expression is the variable-example-1
User Justin Zhang
by
6.3k points