| | |
help .. using type casting ?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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 ?
could any one tell me please if the code is right and if n't what's the wrong?
thanx
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 ?
C++ Syntax (Toggle Plain Text)
#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
apparently requirement 4 wants you to make Celsius the integer result of the calculation -- typecasging the math result to int, like this?
C++ Syntax (Toggle Plain Text)
int C; C = (int) ((F - 32) * 5.0 / 9.0);
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Problem while Type Casting (C++)
- Type casting and type conversions (C)
- Type casting (C++)
- type casting (C++)
- conversion type (C++)
Other Threads in the C++ Forum
- Previous Thread: oracle APIs
- Next Thread: introduction to functions
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count data delete deploy desktop directshow dll download dynamic encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






