-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.cpp
64 lines (64 loc) · 1.17 KB
/
2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <string.h>
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
class Book
{
private:
char name[200];
char author[200];
int sale;
public:
Book();//默认构造函数
Book(char* m_name, char* m_author, int m_sale);//构造函数
Book(const Book&);//深拷贝
void print();//
~Book()
{
}
};
Book::Book()
{
strcpy(name, "No name");
strcpy(author, "No author");
sale = 0;
}
Book::Book(char* m_name, char* m_author, int m_sale)
{
strcpy(name, m_name);
strcpy(author, m_author);
sale = m_sale;
}
Book::Book(const Book& newone)
{
strcpy(name, newone.name);
strcpy(author, newone.author);
sale = newone.sale;
}
void Book::print()
{
cout << "Name:" << name << endl << " " << "Author:" << author << " " << "Sale:" << sale << endl;
}
int main()
{
char bookname[105];
char authorname[105];
int total;
cin >> bookname >> authorname >> total;
if (strcmp(bookname, "-1") == 0 && strcmp(authorname, "-1") == 0 && total == -1)
{
Book one;
one.print();
}
else if (strcmp(bookname, "0") == 0 && strcmp(authorname, "0") == 0 && total == 0)
{
Book bk1;
Book bk2(bk1);
bk2.print();
}
else {
Book one(bookname, authorname, total);
one.print();
}
return 0;
}