Movie Class in C++
Posted by Samath
Last Updated: December 25, 2014
  6141

Create a class called movie that has the following attributes:

age: int

movieName: string

price: double

numTickets:int

ratings: string 

The movie class has the following behaviours:

default constructor

getPrice: product of price and number of tickets

ticketInfo: displays the movie name, rating and price in a single statement. 

 

Code:

#include <iostream>
#include <cstdlib>
 
using namespace std;
 
class Movie
{
	public:
             Movie();
             Movie(int a, string m, double p, int n, string r);
             double getPrice();
             void ticketInfo();
      private:
              int age; 
	          string movieName;
		      double price;
			  int numTickets;
			  string ratings;    
};


Movie::Movie(int a, string m, double p, int n, string r)
{
	  age = a;
      movieName = m;
      price = p;
      numTickets = n;
      ratings = r; 
}
Movie::Movie()
{
  age = 0;
  movieName = "";
  price = 0;
  numTickets = 0;
  ratings = "";  
}

double Movie::getPrice()
{
	return price * numTickets;
}

void Movie::ticketInfo()
{
	cout<<"Movie Name: "<<movieName<<"\nRating: "<<ratings<<"\nPrice: "<<price;	
}


int main(int argc, char *argv[])
{
 	Movie m1(10,"The Notebook", 12.5, 1, "5");
 	cout<<"Price: "<<m1.getPrice()<<"\n";
 	m1.ticketInfo();
	system("pause");
	return 0;
}