• R/O
  • SSH
  • HTTPS

assignment: Commit


Commit MetaInfo

Revision12 (tree)
Time2020-09-12 09:18:21
Authorephd

Log Message

Fixed multiple functions, added error checking and comments.

Change Summary

Incremental Difference

--- CPPCode/assign02/main.cpp (revision 11)
+++ CPPCode/assign02/main.cpp (revision 12)
@@ -2,6 +2,7 @@
22 #include <string>
33
44 std::string truncateString(std::string str);
5+void error(std::string errorMessage);
56
67 using namespace std;
78
@@ -25,7 +26,7 @@
2526 if(name.length() > 50) {
2627 name = truncateString(name);
2728 }
28- std::cout << "Enter the creation date of the movie" << std::endl;
29+ std::cout << "Enter the creation date for " << name << " 's movie" << std::endl;
2930 std::cin >> creationDate;
3031 numMovies = 0;
3132 whichPark = 'N';
@@ -45,6 +46,9 @@
4546 }
4647
4748 void setMoviesNum(int num) {
49+ if(num < 0) {
50+ error("Number is smaller than zero");
51+ }
4852 numMovies = num;
4953 }
5054 void setPark(char parkChar){
@@ -67,32 +71,33 @@
6771 }
6872 void SameMovies(DisneyCharacter &anotherCharacter) {
6973 //sets the number of movies said character has been in as the specified character
70- int num = numMovies;
71- anotherCharacter.setMoviesNum(num);
74+ numMovies = anotherCharacter.getMovieNum();
7275 }
7376 };
7477
7578
76-/**< program entry point */
77-
7879 int main() {
7980 DisneyCharacter mickey;
80- int moviesNum;
81- std::cout << "What park do you want " << mickey.getCharacterName() << " to be in?" << endl;
81+ int numberOfMovies;
82+ std::cout << "What park is " << mickey.getCharacterName() << " in?" << endl;
8283 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;
8384
8485 char parkChar;
8586
8687 std::cin >> parkChar;
88+ mickey.setPark(parkChar);
8789 std::cout << "How many movies has this character been in?" << endl;
88- std::cin >> moviesNum;
89- mickey.setMoviesNum(moviesNum);
90- mickey.PlaceCharacter(parkChar);
90+ std::cin >> numberOfMovies;
91+ mickey.setMoviesNum(numberOfMovies);
9192
93+
9294 DisneyCharacter minnie;
9395 minnie.SameMovies(mickey);
96+ minnie.PlaceCharacter(mickey.getPark());
9497
98+ //Prints Info
9599 mickey.ShowInfo();
100+ std::cout << "==========================================" << endl;
96101 minnie.ShowInfo();
97102
98103 }
@@ -100,3 +105,9 @@
100105 std::string truncateString(string str) {
101106 return str.substr(0,46) + "...";
102107 }
108+
109+//Function for errors
110+void error(std::string errorMessage) {
111+ std::cout << errorMessage << endl;
112+ exit(0);
113+}
Show on old repository browser