标签:
1.声明:
#include <string> #include <iostream> using namespace std; class AirlineTicket { public : AirlineTicket(); ~AirlineTicket(); int calculatePriceInDollars(); string getPassengerName() const; void setPassengerName(string inName); int getNumberOfMiles() const; void setNumberOfMies(int inMiles); bool getHashEliteSuperRewardsStatus(); void setHashEliteSuperRewardsStatus(bool inStatus); protected: string mPassengerName; int mNumberOfMiles; bool bHashEliteSuperRewardsStatus; };
#include "AirlineTicket.h" AirlineTicket::AirlineTicket() { bHashEliteSuperRewardsStatus=false; mPassengerName="Unknown Passenger"; mNumberOfMiles=0; } AirlineTicket::~AirlineTicket() { //TODO } int AirlineTicket::calculatePriceInDollars() { if (getHashEliteSuperRewardsStatus()) { return 0; } return static_cast<int>(getNumberOfMiles()*0.1); } string AirlineTicket::getPassengerName() const { return mPassengerName; } void AirlineTicket::setPassengerName(string inName) { mPassengerName=inName; } int AirlineTicket::getNumberOfMiles() const { return mNumberOfMiles; } void AirlineTicket::setNumberOfMies(int inMiles) { mNumberOfMiles=inMiles; } bool AirlineTicket::getHashEliteSuperRewardsStatus() { return bHashEliteSuperRewardsStatus; } void AirlineTicket::setHashEliteSuperRewardsStatus(bool status) { bHashEliteSuperRewardsStatus=status; }
#include <iostream> #include "AirlineTicket.h" using namespace std; int main(){ AirlineTicket myTicket; myTicket.setPassengerName("ST.Socketwrench"); myTicket.setNumberOfMies(700); int cost=myTicket.calculatePriceInDollars(); cout << "This ticket will cost $" << cost << endl; AirlineTicket *myTicket2=new AirlineTicket(); myTicket2->setNumberOfMies(3000); cout<< myTicket2->getNumberOfMiles() << endl; delete myTicket2; return 0; }
标签:
原文地址:http://blog.csdn.net/qq285016127/article/details/45245479