-
Notifications
You must be signed in to change notification settings - Fork 0
/
drama.cpp
96 lines (81 loc) · 2.08 KB
/
drama.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* drama.cpp is part of the Movie Store Simulator, a C++ program that
* offers the function of borrow, return, or stock with up to 10,000
* customers and 26 genres of movies
*
* @author Bill Zhao, Lucas Bradley
* @date March 12th
*/
#include "drama.h"
#include <iostream>
// The constructor takes a string and turns it into
// a drama movie object
Drama::Drama(std::string Input) {
Type = Input[0];
int It = 3;
Stock = 0;
Year = 0;
while (Input[It] != ',') {
Stock *= 10;
Stock += Input[It] - '0';
It++;
}
It += 2;
while (Input[It] != ',') {
Director += Input[It];
It++;
}
It += 2;
while (Input[It] != ',') {
Title += Input[It];
It++;
}
It += 2;
while (Input[It] != '\0') {
Year *= 10;
Year += Input[It] - '0';
It++;
}
Borrowed = 0;
}
// This is a accessor function for the type of movie
char Drama::type() { return Type; }
// This is a accessor function which reforms the
// original string input
std::string Drama::reformString() {
std::string Result;
Result += Type;
return Result + ", " + std::to_string(Stock) + ", " + Director + ", " +
Title + ", " + std::to_string(Year);
}
// This is an accessor for the sorting element of the classic movie
std::string Drama::sortingElement() { return Director + ", " + Title; }
// This function simply prints the contents of the drama movie object
void Drama::print() {
std::cout << Director << std::endl
<< Title << std::endl
<< Year << std::endl
<< Stock << std::endl;
}
// Inventory display helper reforms the total string
std::string Drama::inventoryDisplayHelper() {
return reformString() + ", " + std::to_string(Borrowed);
}
// This function operates on the drama movie to mark
// as borrowed or deny the function call
bool Drama::borrowMovie() {
if (Stock == 0)
return false;
Stock--;
Borrowed++;
return true;
}
// This function operates on the drama movie to mark
// as returned or deny the function call
bool Drama::returnMovie() {
if (Borrowed == 0)
return false;
Stock++;
Borrowed--;
return true;
}