![]() |
|
#1
|
|||
|
|||
Inheritance and classesHi, this is the problem:
A. Design a class, circleType, that can store and process the radius of the circle. You should then perform operations on the circle, such as setting the radius of the circle, printin the radius of the circle, returning the value of the radius. Also, write a test program to test various operations on the circle. B. Every cylinder has a height and r radius of two circles. Given the height and the radius, you can determine the cylinder's area and circumference. Design a class, cylinderType, that can store the height and the radius of the cylinder. Because the radius is a data member in the class circleType and you designed a class to capture the properties of a circle in Programming Exercise a , you must derive the class cylinderType from the class circleType. You should be able to perform the usual operations on a cylinder, such as setting the height, printing the height and calculating and printing the area and volume. ========= this is what i came until now: CPP / C++ / C Code:
feel free the change what ever you want.. Last edited by admin : 28-Sep-2007 at 22:30.
Reason: Please insert your C code between [cpp] & [/cpp] tags
|
|||
|
#2
|
|||
|
|||
Re: Inheritance and classesNote that there are some "important" reasons why I disagree with the notion of making "circleType" a base of "cylinderType" ...however, you're not likely to understand them at this juncture. Basically, a circle is a 2D (two-dimensional shape) whereas a cylinder is a 3D shape. In other words, they are not the same "kinds" of objects, yet the notion of cylinderType : public circle means that they ARE the same kinds of objects. What I've done in the code below is to aggregate (aka composition) a circle inside of the cylinder. This is, I believe, a useful design choice IF 2D objects are distinctive from 3D objects. In the case, as presented in the requirements, I would strongly lobby toward a position that accepted that cylinderType IS NOT a kind of circleType. Rather, as shown in my code, circleType (I changed the names because these are fhking stupid, IMO) is an object INSIDE of the cylinderType.
Here's some code: caveat I ran out of time to test it. There could be substantive errors with it yet. Even if you find errors, you should find something about this code that is useful. CPP / C++ / C Code:
Output: Code:
I wish that I had more time to complete the code and fix the errors. Perhaps in the next couple of days I'll be able to provide some changes. However, this should at least demonstrate some of the notions of what I think is an appropriate implementation (less the obvious problems) of the INTENT of supporting 2D and 3D objects in code. DaveOnTheLeftCoast...please feel free to add some comment, as I hurried through this impl in order to stay...at least closely to...my 10 minute implementation limitation. :davis: |
|
#3
|
|||
|
|||
Re: Inheritance and classesthanks davis on the comment,, but there are few things that i dont understand,,
such as (*this) (virtual),,, anyways, i'll ask my friends what excatly the teacher wants us to do, then i'll post, because your program is longer then what she asked us to do. thanks,, i still need your generous help,, lol ,,dont go away |
Recent GIDBlog
Problems with the Navy (Enlisted) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Inheritance Suspicious Problem | Peter_APIIT | C++ Forum | 12 | 15-May-2007 22:01 |
| Need To Learn Inheritance using CLASSES | CanitoCool | C++ Forum | 1 | 24-Oct-2006 00:00 |
| Classes initiation | kdsXchris | C++ Forum | 3 | 05-Jun-2006 03:07 |
| Inheritance Project .. | Qatar | C++ Forum | 1 | 28-Apr-2005 17:04 |
| Assistance with classes... | Bravebird | C++ Forum | 7 | 27-Apr-2005 13:17 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The