![]() |
| ||
| Help with C++ Classes I am having trouble understanding classes, I'm new at this and have not had any problems with c++ until now. This is what I have so far. I was supplied the driver and cannot make any changes to it. Any help would be appreciated greatly. Thanks. #include <iostream> |
| ||
| Re: Help with C++ Classes Your SodaCan class needs a constructor to assign something to the private height and radius data members. eg, the line SodaCan can(10,5);requires a constructor which looks like SodaCan::SodaCan(int, int) Much in the same way that, for an library type, such as std::string you can say std::string s("Hello");which will initialise s with the value "Hello" - Of course, the constructor for std::string is well hidden inside the standard library, but there's a constructor somewhere, which may have a signature like string::string(const char*) Check out this link for more info :) C++ FAQ - Constructors |
| ||
| Re: Help with C++ Classes I like to think of them as getter and setter methods... Take a look at this example I did... #include <iostream>http://img476.imageshack.us/img476/5171/cut20ln.png Piworld ™ [Tis simple as Pie] |
| ||
| Re: Help with C++ Classes I think I've gotten a little bit further, but still have yet to grasp classes, this is what I've got now. #include <iostream> |
| ||
| Re: Help with C++ Classes Quote:
Quote:
If you edit those functions so that they return the result of the calculations instead (a double), then you won't need the two values inside your SodaCan class surface and volume. |
| ||
| Re: Help with C++ Classes I got it to work only that I'm not getting the right values, and I can't figure out why. The program should display 785.398 & 471.239, instead I get 210 & 342. Thanks for all the help. #include <iostream> |
| ||
| Re: Help with C++ Classes The problem is with your power function. You're using '^' which is the xor operator, I think. Try swapping radius^2 with radius*radius and const pi = 3.1415926;//global constant Pi with double pi = 3.1415926;//global constant Pi http://img476.imageshack.us/img476/5171/cut20ln.png Piworld ™ [Tis simple as Pie] |
| ||
| Re: Help with C++ Classes Thanks a lot. |
| All times are GMT -4. The time now is 6:57 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC