Program compiles; won't build

This is a discussion on Program compiles; won't build within the C++ Programming forums, part of the General Programming Boards category; Using MSVC++ 6.0; this program compiles but will not build. Is it simply a compiler error, or is there something ...

  1. #1
    Registered User Kayoss's Avatar
    Join Date
    Sep 2005
    Location
    California
    Posts
    53

    Program compiles; won't build

    Using MSVC++ 6.0; this program compiles but will not build. Is it simply a compiler error, or is there something wrong with the code?

    If someone could post a snippet of the results, I'd appreciate it.

    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    
    class Point3
    {
    
    public:
       Point3( int = 0, int = 0 ); // default constructor
    
       void setX( int ); // set x in coordinate pair
       int getX() const; // return x from coordinate pair; getX is not a member of cylinder
       void setY( int ); // set y in coordinate pair
       int getY() const; // return y from coordinate pair
       void print() const; // output Point3 object
    
    private:
       int x; // x part of coordinate pair
       int y; // y part of coordinate pair
    
    }; // end class Point3
    
    class Circle4 
    {
    
    public:
       // default constructor
       Circle4( int = 0, int = 0, double = 0.0 );
    
       void setRadius( double ); // set Radius
       double getRadius() const; // return Radius
       void setCenter( int, int ); // set center of circle to pass x,y values
       double getDiameter() const; // return diameter
       double getCircumference() const; // return circumference
       double getArea() const;
       void print() const; // output Circle4 object
    
    private:
       double radius; // Circle4's radius
       Point3 point; // Point3 object - COMPOSITION
    
    }; // end class Circle4
    
    
    class Cylinder
    {
    
    public:
       // default constructor
       Cylinder( int = 0, int = 0, double = 0.0, double = 0.0 );
    
       void setHeight( double ); // set Cylinder's height
       double getHeight() const; // return Cylinder's height
       double getArea() const; // return Cylinder's area
       double getVolume() const; // return Cylinder's volume
       void print() const; // output Cylinder
    
       void setX( int ); // set x in coordinate pair
       int getX() const; // return x from coordinate pair; getX is not a member of cylinder
       int getY() const; // return y from coordinate pair; getY is not a member of cylinder
       void setY( int ); // set y in coordinate pair
       void setRadius( double ); // set Radius
       double getRadius() const; // return Radius
       double getDiameter() const; // return diameter
       double getCircumference() const; // return circumference
    
    private:
       double height; // Cylinder's height
       Circle4 circle; // Circle4 object - COMPOSITION
    
    }; // end class Cylinder
    
    
    Point3::Point3( int xValue, int yValue )
       : x( xValue ), y( yValue )
    {
       // empty body
    } // end Point3 constructor
    
    
    // set x in coordinate pair
    void Point3::setX( int xValue )
    {
       x = xValue; // used for validation
    } // end function setX
    
    // return x from coordinate pair
    int Point3::getX() const
    {
       return x;
    } // end function getX
    
    // set y in coordinate pair
    void Point3::setY( int yValue )
    {
       y = yValue; // no need for validation
    } // end function setY
    
    // return y from coordinate pair
    int Point3::getY() const
    {
       return y;
    } // end function getY
    
    // output Point3 object
    void Point3::print() const
    {
       cout << '[' << getX() << ", " << getY() << ']';
    } // end function print
    
    // default constructor
    Circle4::Circle4( int xValue, int yValue, double radiusValue )
        : radius( radiusValue )
    {
       point.setX( xValue ); 
       point.setY( yValue );
       setRadius( radiusValue );
    } // end Circle4 constructor
    
    // set radius
    void Circle4::setRadius( double radiusValue )
    {
       radius = ( radiusValue < 0.0 ? 0.0 : radiusValue );
    } // end function setRadius
    
    // return radius
    double Circle4::getRadius() const
    {
       return radius;
    } // end function getRadius
    
    // calculate and return diameter
    double Circle4::getDiameter() const
    { 
       return 2 * getRadius();
    } // end function getDiameter
    
    // calculate and return circumference
    double Circle4::getCircumference() const
    {
       return 3.14159 * getRadius() * getRadius();
    } // end function getCircumference
    
    // calculate and return area
    double Circle4::getArea() const
    {
       return 3.14159 * getRadius() * getRadius();
    } // end function getArea
    
    void Circle4::setCenter( int x, int y )
    {
        point.setX( x );
        point.setY( y );
    }
    // output Circle4 object
    void Circle4::print() const
    {
       cout << "Center = ";
       point.print(); // invoke Point3's print function
       cout << "; Radius = " << getRadius();
    } // end function print
    
    // default constructor
    Cylinder::Cylinder( int xValue, int yValue, double radiusValue, double heightValue )
        : height( heightValue )
    {
       circle.setCenter( xValue, yValue );
       setHeight( heightValue );
       circle.setRadius( radiusValue );
    } // end function setHeight
    
    // get Cylinder's height
    double Cylinder::getHeight() const
    {
       return height;
    } // end function getHeight
    
    // redefine Circle4 fucntion getArea to calculate Cylinder area
    double Cylinder::getArea() const
    {
       return 2 * circle.getArea() * getCircumference() * getHeight();
    } // end function getArea
    
    // calculate Cylinder volume
    double Cylinder::getVolume() const
    {
       return circle.getArea() * getHeight();
    } // end function getVolume
    
    void Cylinder::print() const
    {
       circle.print();
       cout << "; Height = " << getHeight();
    } // end function print
    
    
    int main()
    {
       // instantiate Cylinder object
       Cylinder cylinder( 12, 23, 2.5, 5.7 );
    
       // display point coordinates
       cout << "X coordinate is " << cylinder.getX()
    	<< "\nY coordinate is " << cylinder.getY()
    	<< "\nRadius is " << cylinder. getRadius()
    	<< "\nHeight is " << cylinder.getHeight();
    
       cylinder.setX( 2 ); // set new x-coordinate
       cylinder.setY( 2 ); // set new y-coordinate
       cylinder.setRadius( 4.25 ); // set new radius
       cylinder.setHeight( 20 ); // set new height
    
       // display new cylinder value
       cout << "\n\nThe new location and radius of circle are\n";
       cylinder.print();
    
       // display floating point values wtih 2 digits of precision
       cout << fixed << setprecision( 2 );
    
       // display cylinder's diameter
       cout << "\n\nDiameter is " << cylinder.getDiameter();
    
       // display cylinder's circumference
       cout << "\nCircumference is "
    	<< cylinder.getCircumference();
    
       // display cylinder's area
       cout << "\nArea is " << cylinder.getArea();
    
       // display cylinder's volume
       cout << "\nVolume is " << cylinder.getVolume();
    
       cout << endl;
    
       return 0;
    
    } // end main
    THE redheaded stepchild.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    I'd say you're just missing the implementation of some of your member functions
    Code:
    g++ -W -Wall -ansi -pedantic -O2  foo.cpp
    /tmp/ccQo2SAO.o(.text+0x1ed): In function `Cylinder::Cylinder(int, int, double, double)':
    foo.cpp: undefined reference to `Cylinder::setHeight(double)'
    /tmp/ccQo2SAO.o(.text+0x255): In function `Cylinder::Cylinder(int, int, double, double)':
    foo.cpp: undefined reference to `Cylinder::setHeight(double)'
    /tmp/ccQo2SAO.o(.text+0x29f): In function `Cylinder::getArea() const':
    foo.cpp: undefined reference to `Cylinder::getCircumference() const'
    /tmp/ccQo2SAO.o(.text+0x4ea): In function `main':
    foo.cpp: undefined reference to `Cylinder::getRadius() const'
    /tmp/ccQo2SAO.o(.text+0x4f5):foo.cpp: undefined reference to `Cylinder::getY() const'
    /tmp/ccQo2SAO.o(.text+0x4ff):foo.cpp: undefined reference to `Cylinder::getX() const'
    /tmp/ccQo2SAO.o(.text+0x5b1):foo.cpp: undefined reference to `Cylinder::setX(int)'
    /tmp/ccQo2SAO.o(.text+0x5bb):foo.cpp: undefined reference to `Cylinder::setY(int)'
    /tmp/ccQo2SAO.o(.text+0x5cb):foo.cpp: undefined reference to `Cylinder::setRadius(double)'
    /tmp/ccQo2SAO.o(.text+0x5db):foo.cpp: undefined reference to `Cylinder::setHeight(double)'
    /tmp/ccQo2SAO.o(.text+0x623):foo.cpp: undefined reference to `Cylinder::getDiameter() const'
    /tmp/ccQo2SAO.o(.text+0x650):foo.cpp: undefined reference to `Cylinder::getCircumference() const'
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 06:49 PM
  2. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  3. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  4. Simple Program wont execute after compiles w. no errors
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 02-03-2002, 03:24 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21