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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

2 Compiler Errors

I am trying to write a class interface and an imp\lementation to get this program to print out the surface area and volume of a soda can I ran in to the following two errors and can not figure out how to fix them:

line 25: Error E2333 lab5a.cpp 25: Class member 'SodaCan::SodaCan(int,int)' declared outside its class
line 26: Error E2040 lab5a.cpp 26: Declaration terminated incorrectly

#include <iostream>

using namespace std;

/**
   A cylindrical can.
*/

//define interface here:
#define pi = 3.14159
class SodaCan
{
      public:
             
            SodaCan(int height, int radius);
            
            double get_volume();
            double get_surface_area();
            
      private:
            double volume;
         double surface_area;
};
      
SodaCan::SodaCan(int height, int radius);
      {
            volume = pi*radius*radius*height;
            surface_area = 2*pi*radius*height + 2*pi*radius*radius;
      }
      
double SodaCan::get_volume()
      {
        return volume;
      }

double SodaCan::get_surface_area()
      {
        return surface_area;
      }

// 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;
}

       
 
0
Geezy1984
Asked:
Geezy1984
1 Solution
 
sunnycoderCommented:
Hi Geezy1984,

> SodaCan::SodaCan(int height, int radius); <<<<< remove the terminating ;
>      {
>           volume = pi*radius*radius*height;
>           surface_area = 2*pi*radius*height + 2*pi*radius*radius;
>      }


Cheers!
Sunnycoder
0
 
rajeev_devinCommented:
>> SodaCan::SodaCan(int height, int radius);
Remove semi-clon from it

SodaCan::SodaCan(int height, int radius)
     {
          volume = pi*radius*radius*height;
          surface_area = 2*pi*radius*height + 2*pi*radius*radius;
     }
0
 
Raj_KauCommented:
#include <iostream>

using namespace std;

/**
   A cylindrical can.
*/

//define interface here:
#define pi = 3.14159
class SodaCan
{
     public:
           
          void SodaCan(int height, int radius);
         
          double get_volume();
          double get_surface_area();
         
     private:
          double volume;
        double surface_area;
};
     
void SodaCan::SodaCan(int height, int radius);
     {
          volume = pi*radius*radius*height;
          surface_area = 2*pi*radius*height + 2*pi*radius*radius;
     }
     
double SodaCan::get_volume()
     {
       return volume;
     }

double SodaCan::get_surface_area()
     {
       return surface_area;
     }

// 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;
}
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Raj_KauCommented:
SodaCan::SodaCan(int height, int radius);
remove this ";" from end
0
 
Raj_KauCommented:
sorry full code is like this





#include <iostream>

using namespace std;

/**
   A cylindrical can.
*/

//define interface here:
#define pi = 3.14159
class SodaCan
{
     public:
           
          void SodaCan(int height, int radius);
         
          double get_volume();
          double get_surface_area();
         
     private:
          double volume;
        double surface_area;
};
     
void SodaCan::SodaCan(int height, int radius)
     {
          volume = pi*radius*radius*height;
          surface_area = 2*pi*radius*height + 2*pi*radius*radius;
     }
     
double SodaCan::get_volume()
     {
       return volume;
     }

double SodaCan::get_surface_area()
     {
       return surface_area;
     }

// 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;
}
0
 
sunnycoderCommented:
Hi Geezy1984,
> #define pi = 3.14159
should be
#define pi  3.14159

#defines make literal substitution


Cheers!
Sunnycoder
0
 
HuyBDCommented:
try to move ; in implement , you have declared correddconstructor before

SodaCan::SodaCan(int height, int radius)
{
do somt;
}


try to check syntax before compile!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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