Sunteți pe pagina 1din 15

Data Science and Data Analytics Lab

CS695A
Sayan Maity
CSE 3B
Roll-05
12017009001365

Shamik Basu
CSE 3B
Roll-06
12017009001193
INDEX

Sno Title Page


1 Acknowledgement
2 Title
3 Introduction
4 Specification
5 Solution
6 Source Code
7 Output
8 Conclusion
ACKNOWLEDGEMENT

The success and final outcome of this project required a lot of guidance
and assistance from many people and we are extremely privileged to
have got this all along the completion of our project. All that we have
done is only due to such supervision and assistance and we would not
forget to thank them.

We respect and thank Prof. Somnath Banerjee, for providing me an


opportunity to do the project and giving us all support and guidance
which made me complete the project duly. I am extremely thankful to her
for providing such a nice support and guidance.

We owe my deep gratitude to our project guide Prof. Anoy Ghosh who
took keen interest on our project work and guided us all along, till the
completion of our project work by providing all the necessary information
for developing a good system.

We are thankful to and fortunate enough to get constant


encouragement, support and guidance from all Teaching staffs of CSE
which helped us in successfully completing our project work.

Sayan Maity

Shamik Basu
TITLE

Movie Ticket Booking System

Introduction
SPECIFICATIONS
Problem Statement: Movie Ticket Booking System

Programming Language: C++

UML Diagram
Source Code
#include<iostream>

#include<fstream>

#include<stdio.h>

#include<string.h>

using namespace std;

class Movies{

private:

int ticketsAvailability;

int movieId;

public:

char movieName[50];

int cost;

void getMovieData(){

cout<<"Enter MovieId:\n";

cin>>movieId;

cin.ignore();

cout<<"Enter MovieName:\n";

cin.getline(movieName,49);

cout<<"Enter Cost(per head):\n";

cin>>cost;

cout<<"Enter Available Tickets:\n";


cin>>ticketsAvailability;

storeMovies();

void displayMovies(){

cout<<movieId<<"\t"<<movieName<<"\t"<<cost<<"\t"<<ticketsAvailability<<"\n\n";

int isTicketsAvailable(int id,int seats){

int tempCost=0;

fstream file;

file.open("MoviesData.dat",ios::in|ios::out|ios::ate|ios::binary);

file.seekg(0);

file.read((char*)this,sizeof(*this));

while(!file.eof()){

if(movieId==id && ticketsAvailability>=seats){

ticketsAvailability-=seats;

tempCost=cost;

file.seekp((int)file.tellp()-sizeof(*this));

file.write((char*)this,sizeof(*this));

file.close();

return tempCost;

file.read((char*)this,sizeof(*this));

return 0;

void storeMovies();

void fetchAllMovies();
void deleteMovie(int);

void updateMovies(int);

};

void Movies::updateMovies(int id){

fstream file;

file.open("MoviesData.dat",ios::in|ios::out|ios::ate|ios::binary);

file.seekg(0);

file.read((char*)this,sizeof(*this));

while(!file.eof()){

if(movieId==id){

cout<<"Enter New Data to be Updated\n";

cout<<"Enter MovieId:\n";

cin>>movieId;

cin.ignore();

cout<<"Enter MovieName:\n";

cin.getline(movieName,49);

cout<<"Enter Cost(per head):\n";

cin>>cost;

cout<<"Enter Available Tickets:\n";

cin>>ticketsAvailability;

file.seekp((int)file.tellp()-sizeof(*this));

file.write((char*)this,sizeof(*this));

break;

file.read((char*)this,sizeof(*this));

file.close();

cout<<"Movie Details Updated Successfully...\n";


}

void Movies::deleteMovie(int id){

ifstream fin;

ofstream fout;

fin.open("MoviesData.dat",ios::in|ios::binary);

if(!fin)

cout<<"No file found\n";

else{

fout.open("temp.dat",ios::out|ios::binary);

fin.read((char*)this,sizeof(*this));

while(!fin.eof()){

if(movieId!=id){

fout.write((char*)this,sizeof(*this));

fin.read((char*)this,sizeof(*this));

fout.close();

fin.close();

remove("MoviesData.dat");

rename("temp.dat","MoviesData.dat");

cout<<"Movie Deleted...\n";

void Movies::fetchAllMovies(){

ifstream fin;

fin.open("MoviesData.dat",ios::in|ios::binary);

if(!fin)
cout<<"File Not FOund....\n";

else{

fin.read((char*)this,sizeof(*this));

cout<<"movieId\t"<<"movieName\t"<<"Cost\t"<<"TicketsAvailable\n";

while(!fin.eof()){

displayMovies();

fin.read((char*)this,sizeof(*this));

fin.close();

void Movies::storeMovies(){

ofstream fout;

fout.open("MoviesData.dat",ios::app|ios::binary);

fout.write((char*)this,sizeof(*this));

fout.close();

cout<<"Movies Stored Successfully...\n";

class BookedTickets: public Movies{

private:

int userId;

char userName[20];

int seats;

int totalCost;

char date[20];

char time[10];

public:

void getUserDetails(){
int id,checkSeatsCost;

cout<<"Movies Details...\n";

Movies::fetchAllMovies();

cout<<"Enter userId:\n";

cin>>userId;

cin.ignore();

cout<<"Enter UserName:\n";

cin.getline(userName,19);

cout<<"Enter MovieId:\n";

cin>>id;

cout<<"Enter Required Seats:\n";

cin>>seats;

//check seats available or not, comparing to ticketsAvailable

checkSeatsCost=Movies::isTicketsAvailable(id,seats);

if(checkSeatsCost>0){

totalCost=seats*checkSeatsCost;

cout<<"Enough seats are available\n";

cout<<"Continue and enter date[dd.mm.yyyy]\n";

cin.ignore();

cin.getline(date,19);

cout<<"Enter time[hhmm]hrs\n";

cin.getline(time,9);

storeTicketsDetails();

else

cout<<"Sorry Not Enough seats for you\n";

void displayTicket(){

cout<<"Here's your Ticket.Enjoy....\n";

cout<<"UserId\t\t"<<"userName\t"<<"seats\t"<<"TotalCost\t\t"<<"Date\t\t\t"<<"Time\n";
cout<<userId<<"\t"<<userName<<"\t\t"<<seats<<"\t"<<totalCost<<"\t\t\t"<<date<<"\t\t"<<time<<"\
n\n";

void storeTicketsDetails();

void checkMyTicket(int);

};

void BookedTickets::checkMyTicket(int no){

ifstream fin;int flag=0;

fin.open("TicketsBooked.dat",ios::in|ios::binary);

if(!fin)

cout<<"File Not FOund....\n";

else{

fin.read((char*)this,sizeof(*this));

while(!fin.eof()){

if(userId==no){

displayTicket();

flag++;

fin.read((char*)this,sizeof(*this));

if(flag==0)

cout<<"Sorry No Ticket Found(check your userId)\n";

fin.close();

void BookedTickets::storeTicketsDetails(){

ofstream fout;

fout.open("TicketsBooked.dat",ios::app|ios::binary);
fout.write((char*)this,sizeof(*this));

fout.close();

cout<<"Ticket Booked Successfully\n";

int main(){

int id,menuChoice,userno;

Movies m1;

BookedTickets b1;

while(1){

cout<<"\n\n";

cout<<"1. Enter New Movie.\n";

cout<<"2. Update A Movie.\n";

cout<<"3. Delete A Movie.\n";

cout<<"4. Display All Movies.\n";

cout<<"5. Book A Ticket\n";

cout<<"6. Check Your Ticket\n";

cout<<"0. Press 0 to Exit\n";

cout<<"Enter Your Choice...\n";

cin>>menuChoice;

if(menuChoice==0)

break;

else{

switch(menuChoice){

case 1: m1.getMovieData();

break;

case 2: cout<<"Displaying All Movies...\n";

m1.fetchAllMovies();

cout<<"Enter Id of movie which want to update\n";


cin>>id;

m1.updateMovies(id);

break;

case 3: cout<<"Displaying All Movies...\n";

m1.fetchAllMovies();

cout<<"Eneter the Id of Movie to Delete\n";

cin>>id;

m1.deleteMovie(id);

break;

case 4: cout<<"Displaying All Movies...\n";

m1.fetchAllMovies();

break;

case 5: b1.getUserDetails();

break;

case 6: cout<<"Check Your Booked Ticket(Enter your userId)";

cin>>userno;

b1.checkMyTicket(userno);

break;

default: cout<<"Invalid Input(please choose(1-6))\n";

cout<<"Thank You For Using the Software...\n";

return 0;

Output
Conlcusion

S-ar putea să vă placă și