I am receiving the following errors with my code:
Error 3 error LNK1120: 1 unresolved externals c:\users\toking\documents\visual studio 2012\Projects\11.9\Debug\11.9.exe 11.9
Error 2 error LNK2001: unresolved external symbol "public: double __thiscall Package::calculateCost(float,double)" (?calculateCost@Package@@QAENMN@Z) c:\Users\toking\documents\visual studio 2012\Projects\11.9\11.9\11.9_main.obj 11.9
Error 1 error LNK2019: unresolved external symbol "public: double __thiscall Package::calculateCost(float,double)" (?calculateCost@Package@@QAENMN@Z) referenced in function "public: double __thiscall overnightPackage::calcCostOvernight(float,double,double)" (?calcCostOvernight@overnightPackage@@QAENMNN@Z) c:\Users\toking\documents\visual studio 2012\Projects\11.9\11.9\11.9.obj 11.9
This is my second semester of C++ and my first time using inheritance. I tried calling the functions similarly to how my book calls them, but all of the errors seem to be related to my derived classes functions. Any help is greatly appreciated.
// Main
#include <iostream>
#include "stdafx.h"
#include <string>
using namespace std;
int main()
{
int i;
string customerName,customerAddress,city,state,senderAddress,recipientAddress;
float packageWeight;
string customerCity;
double costPerOunce;
double flatFee;
double additionalCost;
string customerState;
int customerZipcode;
Package base;
twoDayPackage twoday;
overnightPackage overnight;
cout<<" *****Welcome To The American Package Delievery Services*****"<<endl<<endl;
cout<<"Please Fill In The Requested Data Follow: "<<endl<<"-----------------------------------------"<<endl<<endl;;
cout<<"Enter Customer Name "<<endl<<endl;
cin>>customerName;
cout<<endl;
base.setName(customerName);
cout<<"Enter Customer Address"<<endl<<endl;
cin>>customerAddress;
cout<<endl;
base.setAddress(customerAddress);
cout<<"Enter Customer City"<<endl<<endl;
cin>>customerCity;
cout<<endl;
base.setCity(customerCity);
cout<<"Enter Customer State"<<endl<<endl;
cin>>customerState;
cout<<endl;
base.setState(customerState);
cout<<"Enter Customer ZIP code"<<endl<<endl;
cin>>customerZipcode;
cout<<endl;
base.setZip(customerZipcode);
cout<<"Enter Weight"<<endl;
cin>>packageWeight;
cout<<endl;
cout<<"Enter Cost Per Ounce"<<endl;
cin>>costPerOunce;
cout<<endl;
cout<<"Please Enter Your Choice From The Menu Below:"<<endl<<endl;
cout<<" 1- Calculate Base Cost "<<endl<<endl;
cout<<" 2- Calculate Two Day Cost "<<endl<<endl;
cout<<" 3- Calculate Over Night Cost"<<endl<<endl;
cin>>i;
cout<<endl;
switch (i)
{
case 1 :
base.calculateCost(packageWeight,costPerOunce);
break;
case 2 :
cout<<"Enter Flat Cost"<<endl<<endl;
cin >> flatFee;
twoday.calcShippingCost(packageWeight,costPerOunce,flatFee);
break;
case 3 :
cout<<"Enter The Additional Cost"<<endl<<endl;
cin >> additionalCost;
overnight.calcCostOvernight(packageWeight,costPerOunce,additionalCost);
break;
default:
cout << "INVALID CHOICE....Please Enter ur Choice Number From 1-->3 "<<endl;
}
cout<<"Enter sender address "<<endl<<endl;
cin>>senderAddress;
cout<<endl;
base.setSender( senderAddress);
cout<<"Enter ricipent address"<<endl<<endl;
cin>>recipientAddress;
cout<<endl;
base.setRecipient(recipientAddress);
cout<<"address from:"<< senderAddress<<endl;
cout<<"To:"<<recipientAddress<<endl;
system ("pause");
return 0;
}
// Header
#include <iostream>
#include <string>
using namespace std;
class Package // Base Class
{
private:
string name, city, state, sender, recipient;
int zip;
string address;
float weight;
double cost;
public:
void setName(string);
string getName();
void setCity(string);
string getCity();
void setState(string);
string getState();
void setZip(int);
int getZip();
void setAddress(string);
string getAddress();
void setSender(string);
string getSender();
void setRecipient(string);
string getRecipient();
double calculateCost(float , double);
};
class twoDayPackage: public Package
{
public:
double calcShippingCost(float, double, double);
private:
double flatFee;
};
class overnightPackage: public Package
{
public:
double calcCostOvernight(float, double, double);
private:
double overnightCost;
};
// Cpp
#include <iostream>
#include "stdafx.h"
#include <string>
using namespace std;
void Package::setName(string n)
{
name = n;
}
void Package::setCity(string c)
{
city = c;
}
void Package::setState(string s)
{
state = s;
}
void Package::setZip (int zp)
{
zip = zp;
}
void Package::setAddress(string adr)
{
address = adr;
}
void Package::setSender(string sen)
{
sender = sen;
}
void Package::setRecipient(string rec)
{
recipient = rec;
}
string Package::getName()
{
return name;
}
string Package::getCity()
{
return city;
}
string Package::getState()
{
return state;
}
int Package::getZip()
{
return zip;
}
string Package::getAddress()
{
return address;
}
string Package::getSender()
{
return sender;
}
string Package::getRecipient()
{
return recipient;
}
double calculateCost(float weight,double costPerOunce)
{
double z;
z = weight * costPerOunce;
cout<< "The Base Cost = " <<z << endl<<endl;
return z;
}
double twoDayPackage::calcShippingCost(float weight, double costPerOunce, double flatFee)
{
double z;
z = calculateCost(weight,costPerOunce) + flatFee;
cout << "The TwoDayPackage Cost = " << z << endl;
return z;
}
double overnightPackage::calcCostOvernight(float weight,double costPerOunce,double additionalCost )
{
double z;
z = calculateCost(weight, costPerOunce)+(additionalCost * weight);
cout<< "The OvernightPackage Cost = " <<z << endl;
return z;
}