assignment 2 of CPP
@@ -0,0 +1,100 @@ | ||
1 | +#include <iostream> | |
2 | +#include <string> | |
3 | + | |
4 | +std::string truncateString(std::string str); | |
5 | + | |
6 | +using namespace std; | |
7 | + | |
8 | + | |
9 | +class DisneyCharacter { | |
10 | + private: | |
11 | + //has max of 50 characters | |
12 | + std::string name; | |
13 | + | |
14 | + std::string creationDate; | |
15 | + //Number of movies character is in | |
16 | + int numMovies; | |
17 | + //single character indicating which of the Disney parks the character is in | |
18 | + char whichPark; | |
19 | + | |
20 | + public: | |
21 | + //constructor | |
22 | + DisneyCharacter() { | |
23 | + std::cout << "Enter Disney Character name" << std::endl; | |
24 | + std::cin >> name; | |
25 | + if(name.length() > 50) { | |
26 | + name = truncateString(name); | |
27 | + } | |
28 | + std::cout << "Enter the creation date of the movie" << std::endl; | |
29 | + std::cin >> creationDate; | |
30 | + numMovies = 0; | |
31 | + whichPark = 'N'; | |
32 | + } | |
33 | + ~DisneyCharacter() { | |
34 | + std::cout<< name << " Destroyed" << std::endl; | |
35 | + } | |
36 | + int getMovieNum() { | |
37 | + return numMovies; | |
38 | + } | |
39 | + | |
40 | + std::string getCharacterName() { | |
41 | + return name; | |
42 | + } | |
43 | + std::string getCreationDate() { | |
44 | + return creationDate; | |
45 | + } | |
46 | + | |
47 | + void setMoviesNum(int num) { | |
48 | + numMovies = num; | |
49 | + } | |
50 | + void setPark(char parkChar){ | |
51 | + whichPark = parkChar; | |
52 | + } | |
53 | + | |
54 | + char getPark() { | |
55 | + return whichPark; | |
56 | + } | |
57 | + void ShowInfo() { | |
58 | + //prints out the current value of all data members | |
59 | + std::cout << "The name of your Disney Character is " << name << std::endl; | |
60 | + std::cout << "The creation date of this movie is " << creationDate << std::endl; | |
61 | + std::cout << "The number of movies this character has been in is " << numMovies << std::endl; | |
62 | + std::cout << "The park this character can be found in is " << whichPark << std::endl; | |
63 | + } | |
64 | + void PlaceCharacter(char whichPark) { | |
65 | + //places character at a particular park | |
66 | + setPark(whichPark); | |
67 | + } | |
68 | + void SameMovies(DisneyCharacter &anotherCharacter) { | |
69 | + //sets the number of movies said character has been in as the specified character | |
70 | + int num = numMovies; | |
71 | + anotherCharacter.setMoviesNum(num); | |
72 | + } | |
73 | +}; | |
74 | + | |
75 | + | |
76 | +int main() { | |
77 | + DisneyCharacter mickey; | |
78 | + int moviesNum; | |
79 | + std::cout << "What park do you want " << mickey.getCharacterName() << " to be in?" << endl; | |
80 | + std::cout << "M for Magic Kingdom \n S for Disney Studios \n A for Animal Kingdom\n E for Epcot\n C for California Adventure\n N to indicate the character is not placed " << endl; | |
81 | + | |
82 | + char parkChar; | |
83 | + | |
84 | + std::cin >> parkChar; | |
85 | + std::cout << "How many movies has this character been in?" << endl; | |
86 | + std::cin >> moviesNum; | |
87 | + mickey.setMoviesNum(moviesNum); | |
88 | + mickey.PlaceCharacter(parkChar); | |
89 | + | |
90 | + DisneyCharacter minnie; | |
91 | + minnie.SameMovies(mickey); | |
92 | + | |
93 | + mickey.ShowInfo(); | |
94 | + minnie.ShowInfo(); | |
95 | + | |
96 | +} | |
97 | + | |
98 | +std::string truncateString(string str) { | |
99 | + return str.substr(0,46) + "..."; | |
100 | +} |