#include <iostream> class Order while(a<0) int main() |
|
5分 |
1、代码请格式化后,用”
“框起来 |
能解释一下吗,或者举一个例子,初学者不懂
|
|
修改如下:
#include <iostream> #include <iomanip> #include <string> using namespace std; template<class T> T judge(T a) { while (a<0) { cout << "输入不合法,重新输入:"; cin >> a; } return a; } const int MAX = 100; const int N = 8; class Order { private: int num; //订单编号 string name; //订单名称 float price; //订单价格 int quantity; //订单数量 static int cout; static double total; public: void Input(); void Output(); }; int Order::cout=0; double Order::total=0; void Order::Input() { std::cout << "请输入订单编号:"; cin >> num; std::cout << "请输入订单名称:"; cin >> name; std::cout << "请输入订单价格:"; cin >> price; price = judge(price); std::cout << "请输入订单数量:"; cin >> quantity; quantity = judge(quantity); } void Order::Output() { std::cout << setw(N) << "编号" << setw(N) << "名称" << setw(N) << "价格" << setw(N) << "数量" << endl; std::cout << setw(N) << num << setw(N) << name << setw(N) << price << setw(N) << quantity << endl; } int main()//21 { Order c; c.Input(); c.Output(); return 0; } |
|
25分 |
你自定义了一个cout,所以会有std::cout的代码出现。
其实你应该把 static int cout; 改为 static int count; |
cout 是关键字
|