product.cpp
来自「C++ 这是国外计算机科学教材系列《big C++》书籍的源代码ch6」· C++ 代码 · 共 38 行
CPP
38 行
#include <iostream>
#include "product.h"
using namespace std;
Product::Product()
{
price = 1;
score = 0;
}
void Product::read()
{
cout << "Please enter the model name: ";
getline(cin, name);
cout << "Please enter the price: ";
cin >> price;
cout << "Please enter the score: ";
cin >> score;
string remainder; /* read remainder of line */
getline(cin, remainder);
}
bool Product::is_better_than(Product b) const
{
if (price == 0) return false;
if (b.price == 0) return true;
return score / price > b.score / b.price;
}
void Product::print() const
{
cout << name
<< " Price: " << price
<< " Score: " << score << "\n";
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?