Question

In: Computer Science

Consider the following two-letter acronym of the following states in the United States: MD - Maryland,...

Consider the following two-letter acronym of the following states in the United States:

MD - Maryland, FL - Florida, PA - Pennsylvania, Ga - Georgia, CA - California, NY - New York.

Imagine that some students from the above-listed states are at a conference. Using a switch control structure write a C++ program that prompts a student at the conference to enter the two-letter acronym of his/her state and let the program print the student's state and welcome the student to the conference. For example, if the student entered MD then the program should print "Your state is Maryland. Welcome."

Solutions

Expert Solution

C++ code:

#include <iostream>
using namespace std;
int main()
{
//initializing two charcters to store the letters
char ch1,ch2;
//asking for acronym
cout<<"Enter the acronym: ";
//accepting both characters
cin>>ch1>>ch2;
//switching on value of 1st character minus the second
switch(ch1-ch2){
//if the 2 characters are M and D
case 'M'-'D':
//printing the state
cout<<"Your state is Maryland. Welcome."<<endl;
//exiting the switch case
break;
//if the 2 characters are F and L
case 'F'-'L':
//printing the state
cout<<"Your state is Florida. Welcome."<<endl;
//exiting the switch case
break;
//if the 2 characters are P and A
case 'P'-'A':
//printing the state
cout<<"Your state is Pennsylvania. Welcome."<<endl;
//exiting the switch case
break;
//if the 2 characters are G and A
case 'G'-'A':
//printing the state
cout<<"Your state is Georgia. Welcome."<<endl;
//exiting the switch case
break;
//if the 2 characters are C and A
case 'C'-'A':
//printing the state
cout<<"Your state is California. Welcome."<<endl;
//exiting the switch case
break;
//if the 2 characters are N and Y
case 'N'-'Y':
//printing the state
cout<<"Your state is New York. Welcome."<<endl;
//exiting the switch case
break;
}
return 0;
}


Screenshot:


Input and Output:

  


Related Solutions

Consider two countries, the United States (U.S.) and Japan. In the U.S., there are two firms,...
Consider two countries, the United States (U.S.) and Japan. In the U.S., there are two firms, Pikes Peak Steel (PPS) and General Motors (GM), both owned by U.S. citizens. In Japan, there is one firm, Toyota, owned by Japanese citizens. All of the employees of PPS and GM are U.S. citizens and all of the employees of Toyota are Japanese citizens. In a given year, PPS produces $6000 worth of steel and pays wages of $1500. It sells $2000 worth...
Consider the following game between two early settlers in the United States: Settler 2 Move West...
Consider the following game between two early settlers in the United States: Settler 2 Move West Move North Settler 1 Move West 60, 110 100, 140 Move North 70, 130 90, 100 Which player has dominant strategy? What is (are) equilibrium outcome(s) of the game?                                                        
Consider trade relations between the United States and Mexico. Assume that the leaders of the two...
Consider trade relations between the United States and Mexico. Assume that the leaders of the two countries believe the payoffs to alternative trade policies are shown in the following payoff matrix: United States' Decision Low Tariffs High Tariffs Mexico's Decision Low Tariffs $28 billion, $28 billion $20 billion, $30 billion High Tariffs $30 billion, $20 billion $25 billion, $25 billion The dominant strategy for the United States is always to choose   tariffs. The dominant strategy for Mexico is always to...
To what does the acronym soap refer? what does each letter represent?
To what does the acronym soap refer? what does each letter represent?
Consider a study on the number of accidents occurred in 10 states of the United States...
Consider a study on the number of accidents occurred in 10 states of the United States of America in different cities for 3 consecutive years. Create a PivotTable in Excel to answer the following questions. The PivotTable should group the number of accidents into yearly bins and display the sum of accidents occurred each year in columns of Excel. Row labels should include the accident locations and allow for grouping the locations into states or viewing by city. You should...
Assume the following information for the United States and Mexico. The United States can produce a...
Assume the following information for the United States and Mexico. The United States can produce a maximum of 600 bushels of barley or a maximum of 600 bushels of corn. Mexico can produce a maximum of 200 bushels of barley or 400 bushels of corn. Which country has a comparative advantage in the production of barley? Which country has a comparative advantage in the production of Corn? Show your work for the calculation of opportunity cost. (4 Points)
Consider the debt ceiling of the United States and the consequences of a default by the...
Consider the debt ceiling of the United States and the consequences of a default by the United States on its national debt.  Some commentators and politicians during the 2013 negotiations over raising the debt ceiling commented that failure to raise the debt ceiling would not have that dramatic an impact on world financial markets.  Comment on the consequences of a default by the US on its debt.
Consider two alternative reforms to the Disability Insurance (DI) system in the United States. Pay different...
Consider two alternative reforms to the Disability Insurance (DI) system in the United States. Pay different DI benefits for different types of disabilities (e.g., you get 30% of benefits if you have an injured back and 50% of benefits if are paralyzed). Amplify the stigma associated with receipt of social insurance, by enforcing a requirement that individuals receiving DI have a sign that declares “Mooch on Society” planted on the recipient’s lawn. Explain the rationale behind each proposal using the...
Consider the following regression equation for the United States (standard errors in parentheses):             where: Pt     ...
Consider the following regression equation for the United States (standard errors in parentheses):             where: Pt      = per capita pounds of pork consumed in time period t                         PRPt = the price of pork in time period t                        PRBt = the price of beef in time period t                        YDt   = per capita disposable income in time period t (a) Hypothesize signs and specify the appropriate null and alternative hypotheses for the coefficients of each of these variables. (b)...
The SAT is a standardized college admissions test used in the United States. The following two...
The SAT is a standardized college admissions test used in the United States. The following two multi-part questions will ask you some questions about SAT testing. This is a 6-part question asking you to determine some probabilities of what happens when a student guessed for all of their answers on the SAT. Use the information below to inform your answers for the following questions. An old version of the SAT college had a -0.25 point penalty for every incorrect answer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT