[Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1137
  • Last Modified:

Class Sample?

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;
1 Solution
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.
You have the basic idea in your disposal. Just implement the function.
And if you face any difficuly after implementation then post you questions.
//define interface here:
class SodaCan
   float get_surface_area();
   float get_volume();

   int height;
   int radius;

just implement those 2 functions

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now