Class Sample?

Posted on 2006-04-17
Last Modified: 2010-10-05
Not quite sure how to do this...

Implement a class SodaCan with functions get_surface_area() and get_volume(). In the constructor, supply the height and radius of the can. Download lab5a.cpp. This skeleton program only contains a driver of class SodaCan, but the class interface and implementation are missing. Your job is to complete this program.

Formulas ( pi=3.1415926, R is radius, H is height):
can surface area = 2piRH +2piR2
can volume = piR2H

Your complete program should display the following results (or approximate values):

#include <iostream>

using namespace std;

   A cylindrical can.

//define interface here:
class SodaCan


//implemente the class Can here:

// a driver:
int main()
   SodaCan can(10, 5); //height is 10, and radius is 5
   cout << can.get_volume() << "\n";
   cout << can.get_surface_area() << "\n";
   return 0;
Question by:Geezy1984
    LVL 23

    Expert Comment

    This appears to be an academic assignment.   The instructions are clear.  The skeletal program provides most of the infrastructure, leaving your task to implement the specified class methods.  The experts here cannot do your homework for you - neither of us would learn anything.  If you are having some difficulty doing the assignment, you may ask for some assistance.  But you cannot simply post the assignment here and expect someone to do all the work for you.
    LVL 12

    Expert Comment

    You have the basic idea in your disposal. Just implement the function.
    And if you face any difficuly after implementation then post you questions.

    Accepted Solution

    //define interface here:
    class SodaCan
       float get_surface_area();
       float get_volume();

       int height;
       int radius;

    just implement those 2 functions

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
    C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now