hello .. please i need ur help in this ..

i have this exercise ..
1. Define the following data member:
a. fahrenheit_temp of type float.
b. celsius_temp of type float.
2. Define a constructor that:
a. Set the default value for the data member to zero.
b. Call set function.
3. Define a member function called set that:
a. Take the value of Fahrenheit temperature from the user.
b. Call To_Celsius function.
4. Define a member function called To_Celsius that convert Fahrenheit temperature to Celsius. (Note: use this formula: C = (F - 32) * 5.0 / 9.0. Celsius must be integer by using type casting )
5. Define a member function called Print_info that print the degree after the conversion and output a message.
6. Declare temp as an object of Temp_conv.
7. Call Print_info function in the main.


i solve it like this .. is it right ? .. but the number of out put To_Celsius is wrong .. i don't kow what mean's by using type casting ?

#include<iostream>

using namespace std;

class temp_conv
{
	private:
    float fahrenheit_temp;
    float celsius_temp; 

    public:
        temp_conv ( float fahrenheit_temp =0 , float celsius_temp = 0)
		{
           set(fahrenheit_temp);
		}
        void set(float fahrenheit_temp)
		{
		cout<< "enter the temperature in fahrenheit: ";
        cin>> fahrenheit_temp ;
		to_celsius(fahrenheit_temp); 
		}

      float to_celsius(float fahrenheit_temp)
		{
         celsius_temp = (fahrenheit_temp - 32) * 5.0 / 9.0;
		 return celsius_temp;
		}
		void print_info()
		{
				cout<< "the temperature in celsius is:" << to_celsius(fahrenheit_temp) ;
		}


};


int main()
{
	float fahrenheit_temp;

    temp_conv temp;

    temp.print_info();
    return 0;
}

could any one tell me please if the code is right and if n't what's the wrong?

thanx

Recommended Answers

All 2 Replies

apparently requirement 4 wants you to make Celsius the integer result of the calculation -- typecasging the math result to int, like this?

int C;
C = (int) ((F - 32) * 5.0 / 9.0);

thanx Ancient Dragon .. know i know what it's mean ..
:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.