The table given below shows the list of gases, liquids and solids. By entering the substances, find the state of the material. Implement the above logic through C++.
S.No.
Materials
1
Water
2
Oxygen
3
Gold
4
Ice
#include <iostream>
#include<string>
using std::cout;
using std::endl;
using std::cin;
using std::string;
string getstatus(string material) {
if (material == "Water")
return "Liquid";
else if (material == "Gold" || material == "Ice")
return "Solid";
else if (material == "Oxygen")
return "Gas";
return "Unknown";
}
int main()
{
string material;
cout << "Enter the name of the material ";
cin >> material;
cout << "Physical state of the material " << getstatus(material);
return 0;
}
Comments
Leave a comment