Skip to content

Instantly share code, notes, and snippets.

@Abdulazizsayed
Created November 1, 2018 12:41
Show Gist options
  • Save Abdulazizsayed/2d94395fd8787d8bf6e60abb75ee3291 to your computer and use it in GitHub Desktop.
Save Abdulazizsayed/2d94395fd8787d8bf6e60abb75ee3291 to your computer and use it in GitHub Desktop.
movie class
#ifndef MOVIE_H
#define MOVIE_H
#include <iostream>
using namespace std;
class movie{
public:
movie(string movieName ,string MPAA);
int rate ,one = 0 ,two = 0 ,three = 0 ,four = 0 ,five = 0 ,nOfPeople_rated;
void setname(string name);
// fun to set the name (setter)
void setmpaa(string mpaa);
// fun to set MPAA rating (setter)
string getname();
// fun to get the value of movieName
string getmpaa();
// fun to get the value of movieName
int addRating(int rate);
// fun to take the ratings
int getAverage();
// fun to calculate the average of the ratings
void setNum(int num);
int getNum(int num);
void output(ostream& out);
private:
string movieName ,MPAA;
};
#endif // MOVIE_H
#include "movie.h"
movie::movie(string movieName ,string MPAA){
nOfPeople_rated = 0;
this->movieName=movieName;
this->MPAA=MPAA;
}
void movie::setname(string name){
movieName = name;
}
void movie::setmpaa(string mpaa){
MPAA = mpaa;
}
string movie::getname(){
return movieName;
}
string movie::getmpaa(){
return MPAA;
}
void movie::setNum(int num){
nOfPeople_rated = num;
}
int movie::getNum(int num){
return num;
}
int movie::addRating(int rate){
if(rate < 1 || rate > 5){
cout << "Invalid input.\n";
return 0;
}
if(rate == 1){
one++;
}
if(rate == 2){
two++;
}
if(rate == 3){
three++;
}
if(rate == 4){
four++;
}
if(rate == 5){
five++;
}
}
int movie::getAverage(){
nOfPeople_rated = one + two + three + four + five;
return (one + two*2 + three*3 + four*4 + five*5)/nOfPeople_rated;
}
void movie::output(ostream& out){
out << "The movie name: " << movieName << endl;
out << "MPAA rating: " << MPAA << endl;
out << "The average rating: " << getAverage() << endl;
}
/*the author : Abdulaziz Sayed
*the problem: details for movies
*version : 1.0
*/
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include "movie.h"
using namespace std;
int main()
{
int rate;
movie movie1("Matrix" ,"G"), movie2("KingKong" ,"PG");
cout << "Rating for Matrix: \n";
for(int i = 0 ; i < 5 ; i++){
cout << i+1 << "- ";
cout << "Enter your rate (between 1-5): ";
cin >> rate;
movie1.addRating(rate);
}
cout << "Rating for KingKong: \n";
for(int i = 0 ; i < 5 ; i++){
cout << i+1 << "- ";
cout << "Enter your rate (between 1-5): ";
cin >> rate;
movie2.addRating(rate);
}
cout << "Movie1 name: " << movie1.getname() << endl;
cout << "Movie1 MPAA rating: " << movie1.getmpaa() << endl;
cout << "Movie1 average rating: " << movie1.getAverage() << endl;
cout << "Movie2 name: " << movie2.getname() << endl;
cout << "Movie2 MPAA rating: " << movie2.getmpaa() << endl;
cout << "Movie2 average rating: " << movie2.getAverage() << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment