-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBooktitle.cpp
59 lines (48 loc) · 1.32 KB
/
Booktitle.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
#include <iostream>
#include <string>
using namespace std;
class Book{
string str;
int price;
char *publishedDate;
public:
Book(){};
Book(char *title, int price, char *pDate){ str = title; this->price = price; publishedDate = pDate; };
void set(char* title, int price, char* pDate){ str = title; this->price = price; publishedDate = pDate; };
void show(){ cout << "책 이름:" << str << " 책 가격:" << price << " 출판일:" << publishedDate << endl; };
int replaceBookTitle(Book *books, int nbks, char *oldtitle, char *newtitle);
string getName() { string a = this->str; return a; }
void setName(string a) { str = a; }
};
int replaceBookTitle(Book *books, int nbks, char *oldtitle, char *newtitle){
for (int i = 0; i < nbks; i++){
if (books[i].getName() == oldtitle){
books[i].setName(newtitle);
return i;
break;
}
else{
if (i == nbks - 1){
return -1;
}
}
}
}
int main(){
Book bookShelf[3] = {
Book("C#프로그래밍", 20000, "0901216"),
Book("c++", 25000, "09022018"),
Book()
};
bookShelf[2].set("Java programming", 28000, "12052017");
bookShelf[0].show();
bookShelf[1].show();
int n = replaceBookTitle(bookShelf, 3, "c++", "C++");
if (n < 0){
cout << "책이름이 없습니다." << endl;
}
else{
cout << n;
bookShelf[n].show();
}
}