Advertisements
Advertisements
Question
Implement a class temperature. Include a constructor in it which accepts value of temperature from user .in degree Celsius. Include two functions in it, one of which calculates its equivalent temperature in degree Fahrenheit and other function prints the answer.
Advertisements
Solution
#include
class temperature
{
float cel;
float far;
public : Temperature(); //constructor
void convert();
void print();
};
temperature::temperature()
{
cout<<"Enter the degree celsius";
cin>>cel;
}
void temperature::convert()
{
far = cel * 9/5 + 32;
}
void temperature::print()
{
cout<<"The degree fahernheit is:";
cout<<far;
}
void main()
{
temperaute obj;
obj.convert();
obj.print();
}shaalaa.com
Is there an error in this question or solution?
