2013-02-22 2 views
0
#include <iostream> 
#include <string> 
#include <fstream> 
#include <ios> 
using namespace std; 

static int numofPPackages=0; 
static int numofOPackages=0; 
static int numofTPackages=0; 

class Persons { 
public: 
string Name; 
string Address; 
string City; 
string State; 
string Zip; 

Persons(); 
/*Persons (string name, string address, string city, string state, string zip) { 
    Name=name; Address=address; City=city; State=state; Zip=zip;}*/ 
void fillpers (string name, string address, string city, string state, string zip)   { 
    Name=name; Address=address; City=city; State=state; Zip=zip;} 
friend ostream &operator<<(ostream &out, Persons); 
string getName(){return Name;} 
string getAddress(){return Address;} 
string getCity(){return City;} 
string getState(){return State;} 
string getZip(){return Zip;} 


}; 

class Package { 
public: 
int Weight; 
char Ptype; 
double Cost; 
Persons Sender; 
Persons Reciver; 

Package(){} 
/*Package(char ptype, int weight, double cost, Persons sender,Persons reciver){ 
    Ptype=ptype; Weight=weight; Cost=cost; Sender=sender; Reciver=reciver;}*/ 
void fillpak(char ptype, int weight, double cost, Persons sender,Persons reciver) 
    {Ptype=ptype; Weight=weight; Cost=cost; Sender=sender; Reciver=reciver;} 
static void printpak(Package toprint){ 
    cout<<"Package #"<<numofPPackages; 
    cout<<"Shipper"<<endl<<toprint.Sender; 
    cout<<"Reciver"<<endl<<toprint.Reciver; 
    cout<<"Shipping cost for "<<toprint.Weight<<" ounces @"  <<toprint.Cost<<"/ounce is "<<toprint.Weight*toprint.Cost; 
} 
}; 

class OvernightPackage : public Package { 
public: 
double addcost; 
//void printpak; 
double Flat_rate_increase(){ 
    double addcost; 
    ifstream readin; 
    readin>>addcost; 
    return addcost; 
} 
static void printOpak(Package toprint, double extcost){ 
    cout<<"Package #"<<numofOPackages; 
    cout<<"Shipper"<<endl<<toprint.Sender; 
    cout<<"Reciver"<<endl<<toprint.Reciver; 
    cout<<"Shipping cost for "<<toprint.Weight<<" ounces @"<<toprint.Cost<<"/ounce + a flat rate of" << extcost<<" is "<<toprint.Weight*toprint.Cost+extcost; 
} 
}; 

class TwoDayPackage : public Package{ 
public: 
double addcost; 
//void printpak; 
double Cost_per_ounce(int weight,double addcost){ 
    ifstream readin; 
    readin>>addcost; 
    return weight*addcost; 
} 
static void printTpak(Package toprint, double extcost){ 
    cout<<"Package #"<<numofTPackages; 
    cout<<"Shipper"<<endl<<toprint.Sender; 
    cout<<"Reciver"<<endl<<toprint.Reciver; 
    cout<<"Shipping cost for "<<(toprint.Weight+extcost)<<" ounces @"<<toprint.Cost<<"/ounce is "<<(toprint.Weight+extcost)*toprint.Cost; 
} 
}; 

//overload for output 
ostream &operator<<(ostream & out, Persons aperson) 
{ 
out <<"Name: "<< aperson.getName()<<endl<<"Address: "<<aperson.getAddress() <<endl<<"City, State Zip: "<<aperson.getCity()<<aperson.getState()<<aperson.getZip()<<endl; 
return out; 
} 

int main() { 
string filename; 
int realfile=0; 
int inWeight; 
char inPtype; 
double inCost; 
string Name1, Address1, City1, State1, Zip1, Name2, Address2, City2, State2, Zip2; 
double inaddcost; 
Persons Pers1; 
Persons Pers2; 

Package stdpak; 
TwoDayPackage tdpak; 
OvernightPackage onpak; 


while (realfile==0) 
{ 
    cout<<"Enter the file name you wish to pull data from"<<endl; 
    cin>>filename; 
    ifstream readin(filename+".txt"); 
    if (readin.is_open()){ 
     realfile++; 
      while (!readin.eof()){ 

       readin>>inPtype; 
       readin>>inWeight;    
       readin>>inCost; 
       readin>>Name1; 
       readin>>Address1; 
       readin>>City1; 
       readin>>State1; 
       readin>>Zip1; 
       readin>>Name2; 
       readin>>Address2; 
       readin>>City2; 
       readin>>State2; 
       readin>>Zip2; 

       Pers1.fillpers(Name1, Address1, City1, State1, Zip1); 
       Pers2.fillpers(Name2, Address2, City2, State2, Zip2); 

       if (inPtype=='o'||inPtype=='O'){ 
        readin>>inaddcost; 
        onpak.fillpak(inPtype, inWeight, inCost, Pers1, Pers2); 
        numofOPackages++; 
        OvernightPackage::printOpak(onpak,inaddcost); 
       } 
       if (inPtype=='t'||inPtype=='T'){ 
        readin>>inaddcost; 
        tdpak.fillpak(inPtype, inWeight, inCost, Pers1, Pers2); 
        numofTPackages++; 
        TwoDayPackage::printTpak(tdpak,inaddcost); 
       } 
       else{ 
        stdpak.fillpak(inPtype, inWeight, inCost, Pers1, Pers2); 
        numofPPackages++; 
        Package::printpak(stdpak); 
       } 
      } 
     } 
     else{cout<<"Try another file name."<<endl;} 
    } 



return 0; 
} 

이 프로그램은 파일에서 입력을 가져 와서 그 정보를 화면에 인쇄합니다. 그래서이 오류가 계속 발생합니다. (오류 _1 오류 LNK2019 : _main 함수에서 참조 된 "public : __thiscall Persons :: Persons (void)"(0Persons @@ QAE @ XZ)의 미해결 된 외부 기호를 참조하십시오.이 오류 LNK2019를 받고 이유를 모르겠 음

답변

0

가 기본 생성자의 어떠한 구현 없기 때문에 -

Persons(); 

가 그리고 당신이 그것을 사용하여 개체를 만들려고 :

Persons Pers1; 
Persons Pers2; 

좀 더 팁 :

  • 패스 클래스 유형 값 대신 const 참조. 당신이
  • 들여 쓰기 코드가
  • 도랑 using namespace std;
  • 는 전역에게
  • 메이크업 데이터 멤버 private
  • 구성을 피할 수
  • 마르크 회원 consthas-a 관계는 - Package이 없습니다 2 명.
  • static void printpak(Package toprint)? 왜 매개 변수가없는 일반 매개 변수는 없습니까?
  • virtual 인쇄 방법을 사용하면 클래스를 유도 할 때 무시할 수 있습니다.
+0

감사합니다. 이제 나는 조금 느린 지혜를 느낀다. – user2101085

관련 문제