CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

Search:

Type: Posts; User: 2kaud

Search: Search took 0.06 seconds.

  1. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    Yes, but the current issue with this homework assignment is that the program needs to be able to input r and h and call the overloaded class functions with either int, float or double arguments. So...
  2. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    This follows from my question in post #50. How are you going to have the user input int, float or double? How are you going to test your various class overloaded functions? You can't input a...
  3. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    So where is the code to ask the user to input radius and height? :mad: Where is



    cout<<"\nEnter radius of Cylinder\n";
    cin>>r;
    cout<<"\nEnter height of Cylinder\n";
    cin>>h;
  4. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    What error are you getting? I tried it and it works for me.
  5. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    :cry: No, you cannot do this. r is defined as type integer. You cannot do comparisons against type.

    Again, you are guessing without understanding what you are doing. You cannot guess with c++ -...
  6. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    In main, r and h are defined as integers. cin >> r tries to get an integer and reads 3. cin >> h tries to read another integer but finds . which isn't a digit so the cin fails. Hence h hasn't been...
  7. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    As GCDEF said, much improved:thumb:. Your class calculate now has various overloaded functions for cylinder_area and cylinder_volume. So from you main function, how are you going to allow the user to...
  8. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    r and h are private.
  9. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    GCDEF is quite correct. You cannot guess c++. You must understand what you are doing. You must have a grasp of the basics before you advance.

    As GCDEF said, you really need to take a step back...
  10. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    default:
    cout<<"\nThe choice entered is a wrong choice";
    cout<< "Area =" << c.area() << "\n";
    cout<< "Volume=" << c.volume() << "\n";


    So you are only going to calculate the...
  11. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    Well you're getting closer!

    In your case statements, you haven't actually called the class functions! So in case 1 for example you need



    cin>>y;
    cout << "Area is: " << c.area(x, y) << endl;
  12. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    In a class, by default all members are private - which basically means that they cannot be accessed outside of the class. This is fine for member variables like r and h, but functions such as area...
  13. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    Before posting, format your code properly with indentations etc. Then Go Advanced, paste in the code, select the code and then click '#'. To format the code you have already posted, on the bottom of...
  14. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    Re b). Please re-read Nuzzle's post #8 re polymorphism and casting. This is probably to what your teacher is referring (albeit badly) - ie int into a double and float into a double. Hence only one...
  15. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    cout <<"Enter radius\n";
    cin>>r;
    cout <<"Enter height\n";
    cin>>h;


    Where have you defined the variables r and h??

    Also note that 3.14 * r * r is not the formula for the surface area of a...
  16. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    b)Just because the radius and height input from the keyboard can be either an integer, float or double does not mean that you require 3 different functions to calculate the area and 3 different...
  17. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    If you are going to overload a function, the compiler must be able to differentiate between the various overloaded functions to determine the one to use. Simplified, it matches the number and type of...
  18. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    Please when you post code format your code properly first and use code tags. Go Advanced, select code and click '#'. Your code is pretty unreadable without.
  19. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    I might be useful if you posted what I asked in post #7.

    If you need to input r and h from the keyboard as either int, float or double, then you have three choices. a) Ask the user whether they...
  20. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    ??
  21. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    ??
  22. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    It might be useful if you said exactly what your assignment is because if you are trying to use polymorphism then you use base and derived classes with inheritance. So if your teacher hasn't covered...
  23. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    Polymorphism is to do with derived classes from a base class. So what's your base class definition and what are your derived classes?
  24. Replies
    67
    Views
    19,898

    Re: Area and volume of cylinder

    First, do you know the formula for calculating the surface area and volume in terms of radius and height? Why do you want to do it for integer, float and double? Why not just double?
Results 1 to 24 of 24





Click Here to Expand Forum to Full Width

Featured