• 大小: 2.39MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-27
  • 语言: Java
  • 标签: 重构  c++  

资源简介

自己手动写的c++版本的重构例子。原书上是Java的。实测可行

资源截图

代码片段和文件信息

#include“Customer.h“

string Customer::getName()
{
return _name;
}
void Customer::addRental(Rental *r)
{
_rental.push_back(*r);
}

double Customer::getTotalCharge()
{
double result = 0.0;
vector::iterator it;
it = _rental.begin();
while (it != _rental.end())
{
result += it->getCharge();
//迭代器自加
it++;
}
return result;
}

int Customer::getTotalFrequentRenterPoints()
{
int result = 0;
vector::iterator it;
it = _rental.begin();
while (it != _rental.end())
{
//积分+1/+2
result += it->getFrequentRenterPoints();
//迭代器自加
it++;
}
return result;
}

string Customer::statement()
{
string result = “Rental Record for “ + getName() + “\n“;
vector::iterator it;
it = _rental.begin();
while (it != _rental.end())
{
//输出Rental信息
char temp[256];
sprintf_s(temp “\t%s\t%.2f\n“ it->getMovie()->gettitle().c_str() it->getCharge());
result.append(temp);
//迭代器自加
it++;
}
char total[256];
sprintf_s(total “Amout owed is %.2f\n You earned %d frequent renter points“ getTotalCharge() getTotalFrequentRenterPoints());
result.append(total);
return result;
}

string Customer::htmlStatement()
{
string result = “

Rental Record for“ + getName() + “

\n“;
vector::iterator it;
it = _rental.begin();
while (it != _rental.end())
{
//输出Rental信息
char temp[256];
sprintf_s(temp “\t%s\t%.2f
\n“ it->getMovie()->gettitle().c_str() it->getCharge());
result.append(temp);
//迭代器自加
it++;
}
char total[256];
sprintf_s(total “

Amout owed is %.2f \n You earned %d frequent renter points

“ getTotalCharge() getTotalFrequentRenterPoints());
result.append(total);
return result;
}



 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     77312  2017-08-24 17:50  ConsoleApplicationRefactor\.vs\ConsoleApplicationRefactor\v14\.suo

     文件       7674  2017-08-24 09:50  ConsoleApplicationRefactor\ConsoleApplicationRefactor\ConsoleApplicationRefactor.vcxproj

     文件       1523  2017-08-24 09:50  ConsoleApplicationRefactor\ConsoleApplicationRefactor\ConsoleApplicationRefactor.vcxproj.filters

     文件       1813  2017-08-24 14:57  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Customer.cpp

     文件        474  2017-08-24 14:50  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Customer.h

     文件       3546  2017-08-24 17:43  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Debug\ConsoleA.2BC4EE83.tlog\CL.command.1.tlog

     文件      64506  2017-08-24 17:43  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Debug\ConsoleA.2BC4EE83.tlog\CL.read.1.tlog

     文件       7144  2017-08-24 17:43  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Debug\ConsoleA.2BC4EE83.tlog\CL.write.1.tlog

     文件        237  2017-08-24 17:43  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Debug\ConsoleA.2BC4EE83.tlog\ConsoleApplicationRefactor.lastbuildstate

     文件       2412  2017-08-24 17:43  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Debug\ConsoleA.2BC4EE83.tlog\link.command.1.tlog

     文件       4908  2017-08-24 17:43  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Debug\ConsoleA.2BC4EE83.tlog\link.read.1.tlog

     文件       1600  2017-08-24 17:43  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Debug\ConsoleA.2BC4EE83.tlog\link.write.1.tlog

     文件        447  2017-08-24 17:43  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Debug\ConsoleApplicationRefactor.log

     文件     274053  2017-08-24 17:43  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Debug\Customer.obj

     文件     263335  2017-08-24 11:22  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Debug\customer.obj.enc

     文件     154237  2017-08-24 17:43  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Debug\Movie.obj

     文件     197561  2017-08-24 17:43  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Debug\MovieRentalTest.obj

     文件      34168  2017-08-24 17:43  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Debug\Rental.obj

     文件     494592  2017-08-24 17:43  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Debug\vc140.idb

     文件     462848  2017-08-24 17:43  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Debug\vc140.pdb

     文件       1364  2017-08-24 17:39  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Movie.cpp

     文件       1144  2017-08-24 17:41  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Movie.h

     文件        407  2017-08-24 17:50  ConsoleApplicationRefactor\ConsoleApplicationRefactor\MovieRentalTest.cpp

     文件        308  2017-08-24 15:36  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Rental.cpp

     文件        357  2017-08-24 14:18  ConsoleApplicationRefactor\ConsoleApplicationRefactor\Rental.h

     文件       1360  2017-08-18 08:55  ConsoleApplicationRefactor\ConsoleApplicationRefactor.sln

     文件    8564736  2017-08-24 17:50  ConsoleApplicationRefactor\ConsoleApplicationRefactor.VC.db

     文件     104960  2017-08-24 17:43  ConsoleApplicationRefactor\Debug\ConsoleApplicationRefactor.exe

     文件     543864  2017-08-24 17:43  ConsoleApplicationRefactor\Debug\ConsoleApplicationRefactor.ilk

     文件    1650688  2017-08-24 17:43  ConsoleApplicationRefactor\Debug\ConsoleApplicationRefactor.pdb

............此处省略12个文件信息

评论

共有 条评论