Question

LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT List by creating a list of movie
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

please find the program below for movie and movieList,

As per HomeworkLib rules , i have answered all the first 6 subparts of the question a(i.e movie class).

Implemented MovieList class also.

kindly upvote

Please find output and program below.

#ifndef MOVIE_H
#define MOVIE_H

#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>

using namespace std;

class Movie
{
private:
std::string _title;
std::string _genre;
size_t _year;
  
public:
Movie(std::string &title, std::string &genre, size_t &year);
Movie(const Movie&);
~Movie()
{
std::cout << "\nDestructor called\n";
}
void write(ostream& output,bool = false);
void read(istream& input);
bool Equals(const Movie&);
void setMovieInfo(std::string &title, std::string &genre, size_t &description);
bool operator == (const Movie& otherPossibleMovie) ;
std::string getTitle() const;
std::string getGenre() const;
size_t getYear() const;
  
void printMovie();
  
};

#endif

bool Movie::Equals(const Movie& otherMovie)
{
if(this == &otherMovie)
return true; //This is the pointer for
else
return false;
}

void Movie::write(ostream& output,bool value)
{
if(value == true)
{
output << setw(30)<< _title << endl;
output << setw(15)<< _genre << endl;
output << setw(6)<< _year << endl;
}
else
{
output << _title << endl << _genre << endl << _year << endl;
}
}
std::string gulp(std::istream &in)
{
std::string ret;
char buffer[4096];
while (in.read(buffer, sizeof(buffer)))
ret.append(buffer, sizeof(buffer));
ret.append(buffer, in.gcount());
return ret;
}

void Movie::read(istream& mystream)
{
gulp(mystream);
}
Movie::Movie(std::string &title, std::string& genre, size_t &year)
{
setMovieInfo(title, genre,year);
}
void Movie::printMovie()
{
std::cout << "Title: " << _title << '\n';
std::cout << "Genre" << _genre << '\n';
std::cout << "Year:" << _year << '\n';
}

// Movie mem function
void Movie::setMovieInfo(std::string &title, std::string& genre, size_t &year)
{
_title= title;
_genre= genre;
_year= year;
}

std::string Movie::getTitle() const
{
return _title;
}

std::string Movie::getGenre() const
{
return _genre;
}

size_t Movie::getYear() const
{
return _year;
}
bool Movie::operator == (const Movie& otherPossibleMovie)
{
if (this->getTitle() == otherPossibleMovie.getTitle() &&
this->getGenre() == otherPossibleMovie.getGenre() &&
this->getYear() == otherPossibleMovie.getYear())
return true;
else
return false;
}

class MovieList {

public:
Movie* movies;
int last_movie_index = 1;
int movies_size = 20;
int movie_count = 0;


~MovieList() {
delete [] movies;
}

int Length() {
return movie_count;
}

bool IsFull()
{
  
if(movie_count = movies_size)
{
return true;
}
else
{
return false;
}
}

void Add(Movie const& m)
{
cout << "coming to add function " << endl;
  
for(int i=0; i<30;i++)
{
  
movies[i]=m;
movie_count++;
break;

}
}

void PrintAll() {
for (int i = 0; i < movie_count; i++) {
movies[i].printMovie();
}
}
};
int main()
{
MovieList *movies ;
std::string title;
size_t releaseYear;
std::string genre;

title= "Aashique";
releaseYear= 1982;
genre= "action.";

Movie letsc(title, genre, releaseYear);
letsc.printMovie();
//movies->Add(letsc);
//movies->PrintAll();
return 0;
}

Title: Aashique Genreaction Year:1982 Destructor called

Thanks,

kindly upvote

Add a comment
Know the answer?
Add Answer to:
LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Implement a templated class list and listnode. You may add methods/functions as you see fit....

    C++ Implement a templated class list and listnode. You may add methods/functions as you see fit. Test these classes. I have left all of the implementation as an exercise for you. template< class NODETYPE > class List;  // forward declaration template<class NODETYPE> class ListNode {    friend class List< NODETYPE >; // make List a friend public:    ListNode( const NODETYPE &newData);  // copy constructor    NODETYPE getData() const;      // return data in the node private:    NODETYPE data;                 // data    ListNode< NODETYPE > *nextPtr; // next node...

  • Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director,...

    Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director, Genre, Year Released, Running Time) into a vector of structures and perform the following operations: Search for a specific title Search for movies by a specific director Search for movies by a specific genre Search for movies released in a certain time period Search for movies within a range for running time Display the movies on the screen in a nice, easy to read...

  • Help! Not sure how to create this java program to run efficiently. Current code and assignment...

    Help! Not sure how to create this java program to run efficiently. Current code and assignment attached. Assignment :Write a class Movies.java that reads in a movie list file (movies.txt). The file must contain the following fields: name, genre, and time. Provide the user with the options to sort on each field. Allow the user to continue to sort the list until they enter the exit option. ---------------------------------------------------------- import java.util.*; import java.io.*; public class Movies { String movieTitle; String movieGenre;...

  • C++ LinkedList I need the code for copy constructor and assignment operator #include <iostream> #include <string> using namespace std; typedef string ItemType; struct Node {    ItemType va...

    C++ LinkedList I need the code for copy constructor and assignment operator #include <iostream> #include <string> using namespace std; typedef string ItemType; struct Node {    ItemType value;    Node *next; }; class LinkedList { private:    Node *head;    // You may add whatever private data members or private member functions you want to this class.    void printReverseRecursiveHelper(Node *temp) const; public:    // default constructor    LinkedList() : head(nullptr) { }    // copy constructor    LinkedList(const LinkedList& rhs);    // Destroys all the dynamically allocated memory    //...

  • c++ Part 1 Consider using the following Card class as a base class to implement a...

    c++ Part 1 Consider using the following Card class as a base class to implement a hierarchy of related classes: class Card { public: Card(); Card (string n) ; virtual bool is_expired() const; virtual void print () const; private: string name; Card:: Card() name = ""; Card: :Card (string n) { name = n; Card::is_expired() return false; } Write definitions for each of the following derived classes. Derived Class Data IDcard ID number CallingCard Card number, PIN Driverlicense Expiration date...

  • Implement a Java application for the following: 1.) Keep track of a movie collection. 2.) Each...

    Implement a Java application for the following: 1.) Keep track of a movie collection. 2.) Each movie in the collection will contain: Title, Genre, Year (4 digits) and Runtime (double - ex. 2.1 (hrs)). 3.) Program will read movies from a local text file named movies.txt in the current project directory in Eclipse. 4.) Each line in the text file contains one movie, containing each field, per line.separated by commas. 5.) Read the text file and load the movies into...

  • Implement a Java application for the following: We want to keep track of a Movie Collection....

    Implement a Java application for the following: We want to keep track of a Movie Collection. Each Movie in the collection will contain: Title, Genre, Year (4 digits) and Runtime (double - ex. 2.1 (hrs)). Your program will read movies from a local text file named movies.txt in the current project directory in Eclipse. Each line in the text file contains one Movie with the fields separated by commas. Read the text file and load the movies in to a...

  • C++ In this homework, you will implement a single linked list to store a list of computer science textbooks. Ever...

    C++ In this homework, you will implement a single linked list to store a list of computer science textbooks. Every book has a title, author, and an ISBN number. You will create 2 classes: Textbook and Library. Textbook class should have all above attributes and also a "next" pointer. Textbook Туре String String String Attribute title author ISBN Textbook* next Library class should have a head node as an attribute to keep the list of the books. Also, following member...

  • C++ program, item.cpp implementation. Implementation: You are supposed to write three classes, called Item, Node and In...

    C++ program, item.cpp implementation. Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data class with item id, name, price and quantity information accompanied by getters and setters Node is a plain linked list node class with Item pointer and next pointer (with getters/setters) Inventory is an inventory database class that provides basic linked list operations, delete load from file / formatted print functionalities. The majority of implementation will be done...

  • C++: Learning Outcomes Implement two stacks and use them to implement an infix to prefix expression...

    C++: Learning Outcomes Implement two stacks and use them to implement an infix to prefix expression convertor Stacks A stack is an abstract data type which uses a sequential container and limits access to that container to one end. You may enter or remove from the container, but only at one end. Using the Linked List data structure from your last homework assignment, implement a Stack of type string. The Stack should only have one data member: the Linked List....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT