help .. using type casting ?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2007
Posts: 27
Reputation: DREAMER546 is an unknown quantity at this point 
Solved Threads: 0
DREAMER546's Avatar
DREAMER546 DREAMER546 is offline Offline
Light Poster

help .. using type casting ?

 
0
  #1
Oct 23rd, 2007
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 ?

  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. class temp_conv
  6. {
  7. private:
  8. float fahrenheit_temp;
  9. float celsius_temp;
  10.  
  11. public:
  12. temp_conv ( float fahrenheit_temp =0 , float celsius_temp = 0)
  13. {
  14. set(fahrenheit_temp);
  15. }
  16. void set(float fahrenheit_temp)
  17. {
  18. cout<< "enter the temperature in fahrenheit: ";
  19. cin>> fahrenheit_temp ;
  20. to_celsius(fahrenheit_temp);
  21. }
  22.  
  23. float to_celsius(float fahrenheit_temp)
  24. {
  25. celsius_temp = (fahrenheit_temp - 32) * 5.0 / 9.0;
  26. return celsius_temp;
  27. }
  28. void print_info()
  29. {
  30. cout<< "the temperature in celsius is:" << to_celsius(fahrenheit_temp) ;
  31. }
  32.  
  33.  
  34. };
  35.  
  36.  
  37. int main()
  38. {
  39. float fahrenheit_temp;
  40.  
  41. temp_conv temp;
  42.  
  43. temp.print_info();
  44. return 0;
  45. }

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

thanx
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,462
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1476
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: help .. using type casting ?

 
0
  #2
Oct 23rd, 2007
apparently requirement 4 wants you to make Celsius the integer result of the calculation -- typecasging the math result to int, like this?
  1. int C;
  2. 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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 27
Reputation: DREAMER546 is an unknown quantity at this point 
Solved Threads: 0
DREAMER546's Avatar
DREAMER546 DREAMER546 is offline Offline
Light Poster

Re: help .. using type casting ?

 
0
  #3
Oct 24th, 2007
thanx Ancient Dragon .. know i know what it's mean ..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC