3. (20 scores)#
点击查看考点
类的基础语法, C 风格字符串
Complete 3 classes called Date
, Item
and Customer
. Make the following function named main
can output correctly.
翻译
实现 Date
, Item
和 Customer
类, 使 main
函数正确输出对应内容.
main.cpp#
1#include <iostream>
2
3#include <string.h>
4
5using namespace std;
6
7class Date {
8 public:
9 // ...
10
11 private:
12 int year;
13 int month;
14 int day;
15};
16
17class Items {
18 public:
19 // ...
20
21 private:
22 char item_name[20];
23 int number;
24 double price;
25};
26
27class Customer {
28 // ...
29};
30
31auto main() -> int {
32 Date d1(2022, 6, 18);
33 Customer c1("11000001", d1);
34 c1.selectItem("cup", 2, 9.2);
35 c1.selectItem("jacket", 1, 50);
36 c1.selectItem("steak", 3, 10);
37 c1.print();
38 return 0;
39}
output#
1Customer ID:11000001
2Purchase Date:2022-6-18
3The Purchase items are listed as follows:
41: itemName: cup,number: 2,price: 9.2,amount: 18.4
52: itemName: jacker,number: 1,price: 50,amount: 50
63: itemName: steak,number: 3,price: 10,amount: 30
7The total amount of the Purchase items is 98.4