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

Expert's answer

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/

LATEST TUTORIALS
APPROVED BY CLIENTS