Skip to content

Commit

Permalink
修改影片类型常量
Browse files Browse the repository at this point in the history
  • Loading branch information
chentuo14 committed Mar 7, 2019
1 parent 4c43d61 commit c27eee7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
8 changes: 2 additions & 6 deletions ch1_firstCase/ch1_switch/movie.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#include "movie.h"

const int REGULAR = 0; //普通影片
const int NEW_RELEASE = 1; //新片
const int CHILDRENS = 2; //儿童影片

Movie::Movie(std::__cxx11::string title, int price)
:_title(title), _priceCode(price)
{

_title = title;
_priceCode = price;
}

int Movie::getPriceCode()
Expand Down
9 changes: 6 additions & 3 deletions ch1_firstCase/ch1_switch/movie.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ class Movie
void setPriceCode(int arg);
std::string getTitle();

static const int REGULAR; //普通影片
static const int NEW_RELEASE; //新片
static const int CHILDRENS; //儿童影片
enum category {
REGULAR = 0, //普通影片
NEW_RELEASE, //新片
CHILDRENS //儿童影片
};

private:
std::string _title; //影片名
int _priceCode; //价格码
Expand Down
6 changes: 3 additions & 3 deletions ch1_firstCase/ch1_switch/rental.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ double Rental::getCharge()
{
double result = 0;
switch(getMovie().getPriceCode()) {
case 0: //普通片,起步价为2元,租期超过2天的部分每天1.5元
case Movie::REGULAR: //普通片,起步价为2元,租期超过2天的部分每天1.5元
result += 2;
if(getDaysRented() > 2)
result += (getDaysRented() - 2) * 1.5;
break;
case 1: //新片,每天3元
case Movie::NEW_RELEASE: //新片,每天3元
result += getDaysRented() * 3;
break;
case 2: //儿童片,起步价1.5元,租期超过3天的部分每天1.5元
case Movie::CHILDRENS: //儿童片,起步价1.5元,租期超过3天的部分每天1.5元
result += 1.5;
if(getDaysRented() > 3)
result += (getDaysRented() - 3) * 1.5;
Expand Down

0 comments on commit c27eee7

Please sign in to comment.