Advertisement Remove all ads

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. - Computer Science 1

Advertisement Remove all ads
Advertisement Remove all ads
Advertisement Remove all ads

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.

Advertisement Remove all ads

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();
}
Concept: C++ Programming
  Is there an error in this question or solution?

APPEARS IN

Advertisement Remove all ads
Share
Notifications

View all notifications


      Forgot password?
View in app×