资源简介
有两种邮寄方式,不同的计价标准,可以实现,完好的代码~~
代码片段和文件信息
// package.cpp : 定义控制台应用程序的入口点。
//
#include “stdafx.h“
#include
using std::cout;
using std::endl;
#include
using std::fixed;
using std::setprecision;
#include
using std::vector;
#include
using std::string;
#include “package.h“
#include “twodaypackage.h“
#include “overnightpackage.h“
int _tmain(int argc _TCHAR* argv[])
{
//print welcome message
cout << “Package delivery service program“ << endl;
cout << endl;
cout << “Cost for a package : $“
<< Package::REGULAR_COST
<< “/once“
<< endl;
cout << “Additional cost for two day delivery : $“
<< TwoDayPackage::TWO_DAY_FLAT_FEE
<< “/once“
<< endl;
cout << “Additional cost for over night delivery : $“
<< OverNightPackage::OVER_NIGHT_FLAT_FEE
<< “/once“
<< endl;
cout << endl;
cout << string(30 ‘*‘) << endl;
vector packages;
Address sender recipient;
//composite the first package which is a regular package
sender.name = “John Smith“;
sender.address = “1 Davidson Road“;
sender.city = “Pisctaway“;
sender.state = “NJ“;
sender.zip_code = “08854“;
recipient.name = “Tom Smith“;
recipient.address = “2 Davidson Road“;
recipient.city = “Pisctaway“;
recipient.state = “NJ“;
recipient.zip_code = “08854“;
packages.push_back(new Package(sender recipient 10));
//composite the second package which is a two day package
sender.name = “Mary Smith“;
sender.address = “3 Davidson Road“;
sender.city = “Pisctaway“;
sender.state = “NJ“;
sender.zip_code = “08854“;
recipient.name = “Jennifer Smith“;
recipient.address = “4 Davidson Road“;
recipient.city = “Pisctaway“;
recipient.state = “NJ“;
recipient.zip_code = “08854“;
packages.push_back(new TwoDayPackage(sender recipient 5));
//composite the third package which is a over night package
sender.name = “John Smith“;
sender.address = “1 Davidson Road“;
sender.city = “Pisctaway“;
sender.state = “NJ“;
sender.zip_code = “08854“;
recipient.name = “Mary Smith“;
recipient.address = “3 Davidson Road“;
recipient.city = “Pisctaway“;
recipient.state = “NJ“;
recipient.zip_code = “08854“;
packages.push_back( new OverNightPackage(sender recipient 2) );
//iterate vector to print package information polymorphically
for(vector::size_type sz = 0;
sz != packages.size();
++sz) {
cout << “Package “ << sz+1 << endl;
cout << endl;
packages[sz]->printSenderInfo();
cout << endl;
packages[sz]->printRecipientInfo();
cout << endl;
packages[sz]->printPackageInfo();
cout << endl;
cout << string(30 ‘*‘) << endl;
}
cout << “End of excution“ << endl;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-12-13 18:25 eight\
文件 724 2012-07-10 13:38 eight\OverNightPackage.cpp
文件 456 2012-07-10 13:38 eight\OverNightPackage.h
文件 1204 2012-07-10 13:38 eight\Package.cpp
文件 623 2012-07-10 13:38 eight\Package.h
文件 701 2012-07-10 13:38 eight\TwoDayPackage.cpp
文件 434 2012-07-10 13:38 eight\TwoDayPackage.h
文件 489 2012-07-10 13:38 eight\eight.pro
文件 17564 2012-12-13 18:25 eight\eight.pro.user
文件 21215 2012-07-10 13:38 eight\eight.pro.user.2.5pre1
文件 3041 2012-07-10 13:38 eight\main.cpp
文件 334 2012-07-10 13:38 eight\stdafx.h
- 上一篇:二维区域图形裁剪
- 下一篇:c++面向对象基础 练习题
评论
共有 条评论