I'm supposed to create a menu, but when I try to run my program in codeRunner it says that a few of my variables were not declared, how can I fix that?
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
#include <string>
#include <iostream>
using namespace std;
class Movie
{
public: // member functions
// constructors
Movie();
Movie(string title, string releaseYear); // default constructor
// getters
string getTitle();
string getReleaseYear();
// setters
void setTitle(string);
void setReleaseYear(string);
private: // data members
string title; // title of movie
string releaseYear; // release year of movie
};
Movie::Movie()
{
this->setTitle("");
this->setReleaseYear("");
}
// parameterized constructor
Movie::Movie(string title, string releaseYear)
{
this->setTitle(title);
this->setReleaseYear(releaseYear);
}
// function
string Movie::getTitle()
{
return title;
}
// function to set movie title
void Movie::setTitle(string title)
{
this->title = title;
}
// function
string Movie::getReleaseYear()
{
return releaseYear;
}
// function
void Movie::setReleaseYear(string releaseYear)
{
this->releaseYear = releaseYear;
}
class User
{
private:
string username;
const static int size = 50;
int ratings[size];
int numRatings;
public:
User();
User(string username, int ratings[], int numRatings);
string getUsername();
void setUsername(string);
int getRatingAt(int);
bool setRatingAt(int, int);
int getNumRatings();
void setNumRatings(int);
int getSize();
};
User::User() // calls the default constructor
{
username = ""; // makes a emputy string
numRatings = 0; // makes numratings = 0
for (int i = 0; i < size; i++)
{
ratings[i] = 0; // makes the ratings array become 0
}
}
User::User(string inputname, int inputratings[], int inputnumrating) // calls the function from Class User
{
username = inputname;
numRatings = inputnumrating;
for (int i = 0; i < size; i++)
{
ratings[i] = 0;
}
for (int i = 0; i < numRatings; i++)
{
ratings[i] = inputratings[i]; // makes the rating array equal to inputratings array
}
}
string User::getUsername() // calls the function from Class User
{
return username;
}
void User::setUsername(string inputname) // calls the function from Class User
{
username = inputname;
}
int User::getRatingAt(int index) // calls the function from Class User
{
int rate = 0;
if (index >= size) // if index is greater than or equal to size
{
return -1;
}
else // if index is less than size
{
rate = ratings[index];
return rate;
}
}
bool User::setRatingAt(int index, int val) // calls the bool function from Class User
{
bool value; // bool value
if ((val >= 0 && val <= 5) && (index < size && index >= 0)) // make sure both statements are true
{
ratings[index] = val;
value = true;
}
else
{
value = false;
}
return value;
}
int User::getNumRatings() // calls the function from Class User
{
return numRatings;
}
void User::setNumRatings(int inputnumratings) // calls the function from Class User
{
numRatings = inputnumratings;
}
int User::getSize() // calls the function from Class User
{
return size;
}
int main()
{
Movie movies[50];
User users[100];
int choice;
do {
cout << "\n====== Main Menu ======\n";
cout << "1. Read movies\n";
cout << "2. Read ratings\n";
cout << "3. Print movies by year\n";
cout << "4. Get rating\n";
cout << "5. Find number of movies user rated\n";
cout << "6. Quit\n";
cin >> choice;
string filename, username, title;
int retVal, year, rating;
switch(choice) {
case 1:
cout << "Enter a movie file name: ";
cin >> filename;
retVal = readMovies(filename);
if(retVal == -1)
cout << "No movies saved to the database.\n";
else if(retVal == -2)
cout << "Database is already full. No movies were added.\n";
else if(retVal == 50)
cout << "Database is full. Some movies may have not been added.\n";
else if(retVal >= 0 && retVal < 50)
cout << "Total movies in the database: " << retVal << endl;
break;
case 2:
cout << "Enter a movie file name: ";
cin >> filename;
retVal = readRatings(filename);
if(retVal == -1)
cout << "No users saved to the database.\n";
else if(retVal == -2)
cout << "Database is already full. No users were added.\n";
else if(retVal == 100)
cout << "Database is full. Some users may have not been added.\n";
else if(retVal >= 0 && retVal < 100)
cout << "Total users in the database: " << retVal << endl;
break;
case 3:
cout << "Enter release year of movie: ";
cin >> year;
printMoviesByYear(year);
break;
case 4:
cout << "Enter a user name: ";
getline(cin, username);
cout << "Enter a movie title: ";
getline(cin, title);
retVal = getRating(username, title);
if(retVal == 0)
cout << username << " has not rated\n";
else if(retVal == -3)
cout << "does not exist\n";
else
cout << "ratedwith " << retVal << endl;
break;
case 5:
cout << "Enter a user name: ";
getline(cin, username);
retVal = getCountWatchedMovies(username);
if(retVal == 0)
cout << username << " has not rated any movies\n";
else if(retVal == -3)
cout << "does not exist\n";
break;
case 6:
cout << "Good bye!\n";
break;
default:
cout << "Invalid input.\n";
}
} while(choice != 6);
return 0;
}
|
And this is the syntax error I get:
Syntax Error(s)
__tester__.cpp: In function ‘int main()’:
__tester__.cpp:183:45: error: ‘readMovies’ was not declared in this scope
retVal = readMovies(filename);
^
__tester__.cpp:196:46: error: ‘readRatings’ was not declared in this scope
retVal = readRatings(filename);
^
__tester__.cpp:209:39: error: ‘printMoviesByYear’ was not declared in this scope
printMoviesByYear(year);
^
__tester__.cpp:216:51: error: ‘getRating’ was not declared in this scope
retVal = getRating(username, title);
^
__tester__.cpp:227:56: error: ‘getCountWatchedMovies’ was not declared in this scope
retVal = getCountWatchedMovies(username);
^