3(我相信相关)我的c ++程序中的错误

时间:2014-02-28 00:17:01

标签: c++ visual-studio

我的代码收到以下错误:

  

错误3错误LNK1120:1未解决   外部c:\ users \ toking \ documents \ visual studio   2012 \ Projects \ 11.9 \ Debug \ 11.9.exe 11.9

     

错误2错误LNK2001:未解析的外部符号" 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

     

错误1错误LNK2019:未解析的外部符号" public:double   __thiscall Package :: calculateCost(float,double)" (?calculateCost @ Package @@ QAENMN @ Z)在函数" public中引用:   双__thiscall   overnightPackage :: calcCostOvernight(浮动,双,双)"   (?calcCostOvernight @ overnightPackage @@ QAENMNN @ Z)c:\ Users \ toking \ documents \ visual   studio 2012 \ Projects \ 11.9 \ 11.9 \ 11.9.obj 11.9

这是我第二个学期的C ++,也是我第一次使用继承。我试着调用函数类似于我的书如何调用它们,但所有错误似乎都与我的派生类函数有关。任何帮助是极大的赞赏。

//主要

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

//标题

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

1 个答案:

答案 0 :(得分:1)

您的代码无法确定calculateCost是否是Package的成员函数。选择一种方式并坚持下去。