Movie Class in C++
Posted by Samath
Last Updated: January 20, 2024

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;
}
Related Content
Movie Class in Java
Movie Class in Java
Samath | Jan 20, 2024
Simple Data Class using C++
Simple Data Class using C++
Samath | Jan 07, 2021
Account Class in C++
Account Class in C++
Samath | Jan 07, 2021
Car Class using C++
Car Class using C++
Samath | Jan 07, 2021
Circle Class in C++
Circle Class in C++
Samath | Jan 07, 2021
Invoice class using Java
Invoice class using Java
Samath | Jan 17, 2024
Rectangle Class in C++
Rectangle Class in C++
Samath | Jan 17, 2024
Student Class in Java
Student Class in Java
Samath | Jan 20, 2024
Glossary Class using Java
Glossary Class using Java
Samath | Jan 20, 2024
Vehicle Class using Java
Vehicle Class using Java
Samath | Jan 18, 2024
Phone Class using Java
Phone Class using Java
Samath | Jan 17, 2024
Airplane Class in Java
Airplane Class in Java
Samath | Jan 17, 2024