product1.cpp
来自「C++ 这是国外计算机科学教材系列《big C++》书籍的源代码ch6」· C++ 代码 · 共 45 行
CPP
45 行
/*
This program compiles but doesn't run.
See product2.cpp for the complete program.
*/
#include <iostream>
#include <string>
using namespace std;
class Product
{
public:
Product();
void read();
bool is_better_than(Product b) const;
void print() const;
private:
};
int main()
{
Product best;
bool more = true;
while (more)
{
Product next;
next.read();
if (next.is_better_than(best)) best = next;
cout << "More data? (y/n) ";
string answer;
getline(cin, answer);
if (answer != "y") more = false;
}
cout << "The best value is ";
best.print();
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?