
January 31st, 2013, 02:54 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 1
Time spent in forums: 22 m 21 sec
Reputation Power: 0
|
|
|
Classes - Link Errors when working with Classes and IMPs (Beginner)
I'm am my second semester of Computer Science II C++. I got a 98 in the first semester and everything seemed really easy, but this semester seems a bit harder. Also, this is my first forum post. Any help would be appreciated!
I'm learning about working with classes, header files and IMP files associated. We're supposed to have two classes: 'circleType' and 'cylinderType', with their implementation files and a source file. Finding total costs and shipping etc (shown down below in code).
I've got mostly all of the meat in the program. It compiles in VS2012 but has two errors:
1:Source.obj : error LNK2019: unresolved external symbol "public: __thiscall cylinderType::cylinderType(double)" (??0cylinderType@@QAE@N@Z) referenced in function _main
2:C:\Users\rawda_000\documents\visual studio 2012\Projects\Discussion Unit 1\Debug\Discussion Unit 1.exe : fatal error LNK1120: 1 unresolved externals
Any help to fix this linking error would be greatly appreciated! My files are down below.
Again, thanks!
********** "circleType.h" **********
#ifndef H_CircleType
#define H_CircleType
class circleType
{
public:
void setRadius(double radius);
double getRadius();
double getArea();
double getCircumference();
void print() const;
circleType(double radius = 0);
protected:
double radius;
};
#endif
****************************************
******** circleTypeImp.cpp **********
#include <iostream>
#include <iomanip>
#include "circleType.h"
using namespace std;
void circleType::setRadius(double radius)
{
if (radius >= 0)
radius = radius;
else
radius = 0;
}
double circleType::getRadius()
{
return radius;
}
double circleType::getArea()
{
return 3.1416 * radius * radius;
}
double circleType::getCircumference()
{
return 2 * 3.1416 * radius;
}
circleType::circleType(double radius)
{
radius = radius;
}
*******************************************
********** cylinderType.h **********
#ifndef H_CylinderType
#define H_CylinderType
#include "circleType.h"
class cylinderType: public circleType
{
public:
double getHeight() const;
double getSurfArea() const;
double getVolume() const;
void print() const;
cylinderType(double height = 0);
private:
double surfArea, volume, height;
};
#endif
******************************************
********** cylinderTypeImp.cpp **********
#include <iostream>
#include <iomanip>
#include "cylinderType.h"
#include "circleType.h"
using namespace std;
double radius = 0;
double height = 0;
double cylinderType::getSurfArea() const
{
return ((2 * 3.1416 * radius * radius * height) + (2 * 3.1416 * radius * height));
};
double cylinderType::getVolume() const
{
return (3.1416 * radius * radius * height);
};
cylinderType::cylinderType (double height) const
{
height = height;
};
*******************************************
********** source.cpp **********
#include <iostream>
#include <iomanip>
#include "circleType.h"
#include "cylinderType.h"
using namespace std;
int main ()
{
circleType circle;
cylinderType container;
double shipping, shippingCost, paintCost,estPaintCost, total;
double radius = 0, height = 0;
cout << "Enter the dimensions (in feet) of the container "
"(radius of the base then the height, separated by a space)." << endl;
cin >> radius >> height;
cout << endl;
cout << "Enter the shipping cost per liter." << endl;
cin >> shipping;
cout << endl;
cout << "Enter the paint cost per square foot." << endl;
cin >> paintCost;
cout << endl;
estPaintCost = paintCost * container.getSurfArea();
shippingCost = container.getVolume() * shipping;
cout << "Your shipping cost is: $" << shippingCost << "." << endl;
cout << endl;
total = estPaintCost + shippingCost;
cout << "Your total cost of painting is: $" << total << "." << endl;
system("PAUSE");
return 0;
}
***************************************
|