Question #47574

5. Write a program that determines the class of the Ship depending on its class ID (Identifier). Here are the criteria. The class ID serves as the input data and the ship class as the output information.
CLASS ID Ship Class
B or b Battle ship
C or c Cruiser
D or d Destroyer
F or f Frigate
In Switch Case
1

Expert's answer

2014-10-08T00:53:03-0400

Answer on Question #47574 - Programming, C

5. Write a program that determines the class of the Ship depending on its class ID (Identifier). Here are the criteria. The class ID serves as the input data and the ship class as the output information.


CLASS ID Ship Class
B or b Battle ship
C or c Cruiser
D or d Destroyer
F or f Frigate
In Switch Case


Solution.


//Connecting library
#include <iostream>
using namespace std;
int main()
{
char ch;
cout << "Enter the class ID: " <<endl;
cin >> ch;
switch(ch)
{
case 'B':
{
cout << endl << "Battle ship";
break;
}
case 'b':
{
cout << endl << "Battle ship";
break;
}
case 'C':
{
cout << endl << "Cruiser";
break;
}
case 'c':
{
cout << endl << "Cruiser";
break;
}
case 'D':
{
cout << endl << "Destroyer";
break;
}
case 'd':
{
cout << endl << "Destroyer";
break;
}
case 'F':
{
cout << endl << "Frigate";
break;
}
case 'f':
{
cout << endl << "Frigate";
break;
}
default: break;
}
//system("pause");
return 0;
}


http://www.AssignmentExpert.com/

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS