asked 14.5k views
4 votes
Given three int variables that have been declared and given values, areaCode, exchange, and lastFour, write a String expression whose value is the String equivalent of each these variables joined by a single hyphen (-) So if areaCode, exchange, and lastFour, had the values 800, 555, and 1212, the expression's value would be "800-555-1212". Alternatively, if areaCode, exchange, and lastFour, had the values 212, 867 and 5309 the expression's value would be "212-867-5309".

asked
User Dunois
by
7.9k points

1 Answer

3 votes

Answer:

The program to this question can be given as:

Program:

#include <iostream> //header file.

using namespace std; //using namespace

int main() //main method

{

int areaCode,exchange,lastFour; //define variable.

areaCode=800; //assign value.

exchange=555; //assign value.

lastFour=1212; //assign value.

cout<<areaCode<<"-"<<exchange<<"-"<<lastFour; //print value.

cout<<endl; //change values of variable.

areaCode=212; //assign value

exchange=867; //assign value

lastFour=5309; //assign value

cout<<areaCode<<"-"<<exchange<<"-"<<lastFour; //print value.

return 0;

}

Output

800-555-1212

212-867-5309

Step-by-step explanation:

  • In the above c++ program firstly we include the header file. Then we define the Main method in the main method we define three integer variable that is "areaCode, exchange, and lastFour" and assign a value that is "800, 555, and 1212".
  • Then we print the values of the variable. To print values we use the hyphen "-" in the middle of the variables and print values.
  • Now we assign a different value to this variable that is "212, 867 and 5309" and to print this variable value we use the hyphen in like above.
answered
User Johannes Riecken
by
8.7k points