Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <cstring>
- using namespace std;
- struct film {
- char name[100];
- char producer[100];
- char genre[20];
- int rating;
- };
- class video_store {
- public:
- video_store() : store(new film* [100]), films_number(0), max_films_number(100) {}
- video_store(int max_number) : store(new film* [max_number]), films_number(0), max_films_number(max_number) {}
- video_store(film arr[], int arr_size) : store(new film* [100]), films_number(0), max_films_number(100) {
- for (int i = 0; i < arr_size; i++) {
- AddMovie(arr[i].name, arr[i].producer, arr[i].genre, arr[i].rating);
- }
- }
- video_store(const video_store& other) : store(new film* [other.max_films_number]), films_number(0), max_films_number(other.max_films_number) {
- for (int i = 0; i < other.films_number; i++) {
- AddMovie(other.store[i]->name, other.store[i]->producer, other.store[i]->genre, other.store[i]->rating);
- }
- }
- video_store& operator=(const video_store& other) {
- if (this != &other) {
- for (int i = 0; i < films_number; i++) {
- delete store[i];
- }
- delete[] store;
- store = new film * [other.max_films_number];
- films_number = 0;
- max_films_number = other.max_films_number;
- for (int i = 0; i < other.films_number; i++) {
- AddMovie(other.store[i]->name, other.store[i]->producer, other.store[i]->genre, other.store[i]->rating);
- }
- }
- return *this;
- }
- video_store(video_store&& other) : store(other.store), films_number(other.films_number), max_films_number(other.max_films_number) {
- other.store = nullptr;
- other.films_number = 0;
- other.max_films_number = 0;
- }
- video_store& operator=(video_store&& other) {
- if (this != &other) {
- for (int i = 0; i < films_number; i++) {
- delete store[i];
- }
- delete[] store;
- store = other.store;
- films_number = other.films_number;
- max_films_number = other.max_films_number;
- other.store = nullptr;
- other.films_number = 0;
- other.max_films_number = 0;
- }
- return *this;
- }
- void ShowAllMovies() {
- if (films_number == 0) {
- cout << "No movies" << endl;
- }
- for (int i = 0; i < films_number; i++) {
- cout << store[i]->name << ", producer: " << store[i]->producer << ", genre: " << store[i]->genre << ", rating: " << store[i]->rating << endl;
- }
- cout << endl;
- }
- void AddMovie(const char name[], const char producer[], const char genre[], const int rating) {
- if (films_number == max_films_number) {
- cout << "The movie cannot be added" << endl;
- return;
- }
- store[films_number] = new film{};
- strcpy(store[films_number]->name, name);
- strcpy(store[films_number]->producer, producer);
- strcpy(store[films_number]->genre, genre);
- store[films_number]->rating = rating;
- films_number++;
- //films_number = films_number + 1;
- }
- void DelMovie(const char name[]) {
- for (int i = 0; i < films_number; i++) {
- if (!strcmp(store[i]->name, name)) {
- delete store[i];
- for (int j = i; j < films_number - 1; j++) {
- store[j] = store[j + 1];
- }
- films_number--;
- }
- }
- }
- void FindMovieName(const char name[]) {
- for (int i = 0; i < films_number; i++) {
- if (!strcmp(store[i]->name, name)) {
- cout << store[i]->name << ", producer: " << store[i]->producer << ", genre: " << store[i]->genre << ", rating: " << store[i]->rating << endl;
- }
- }
- cout << endl;
- }
- void FindMovieProducer(const char producer[]) {
- for (int i = 0; i < films_number; i++) {
- if (!strcmp(store[i]->producer, producer)) {
- cout << store[i]->name << ", producer: " << store[i]->producer << ", genre: " << store[i]->genre << ", rating: " << store[i]->rating << endl;
- }
- }
- cout << endl;
- }
- void FindMovieGenre(const char genre[]) {
- for (int i = 0; i < films_number; i++) {
- if (!strcmp(store[i]->genre, genre)) {
- cout << store[i]->name << ", producer: " << store[i]->producer << ", genre: " << store[i]->genre << ", rating: " << store[i]->rating << endl;
- }
- }
- cout << endl;
- }
- void FindMovieMostPopular(const char genre[]) {
- int index = -1;
- int rating = 0;
- for (int i = 0; i < films_number; i++) {
- if (!strcmp(store[i]->genre, genre)) {
- if (store[i]->rating > rating) {
- index = i;
- rating = store[i]->rating;
- }
- }
- }
- if (index != -1) {
- cout << store[index]->name << ", producer: " << store[index]->producer << ", genre: " << store[index]->genre << ", rating: " << store[index]->rating << endl;
- }
- cout << endl;
- }
- ~video_store() {
- for (int i = 0; i < films_number; i++) {
- delete store[i];
- }
- delete[] store;
- }
- friend bool operator==(const video_store& left, const video_store& right);
- private:
- film** store;
- int films_number;
- int max_films_number;
- };
- bool operator==(const video_store& left, const video_store& right) {
- if (left.films_number != right.films_number) {
- return false;
- }
- for (int i = 0; i < left.films_number; i++) {
- if (strcmp(left.store[i]->name, right.store[i]->name) || strcmp(left.store[i]->producer, right.store[i]->producer) || strcmp(left.store[i]->genre, right.store[i]->genre) || left.store[i]->rating != right.store[i]->rating) {
- return false;
- }
- }
- return true;
- }
- bool operator!=(const video_store& left, const video_store& right) {
- return !(left == right);
- }
- int main() { // для проверки функционала
- video_store my_store; // для проверки конструктора по умолчанию
- //video_store my_store(50); // для проверки конструктора для одного параметра
- //film some_films[]{ {"Pirates of the Caribbean", "Gore Verbinski", "fantasy", 5}, {"Harry Potter", "Chris Columbus", "fantasy", 4}, {"Diamond Hand", "Leonid Gaidai", "comedy", 5} }; // для проверки конструктора для двух параметров (закомментировать первые три добавления фильма)
- //video_store my_store(some_films, 3); // для проверки конструктора для двух параметров
- my_store.AddMovie("Pirates of the Caribbean", "Gore Verbinski", "fantasy", 5);
- my_store.AddMovie("Harry Potter", "Chris Columbus", "fantasy", 4);
- my_store.AddMovie("Diamond Hand", "Leonid Gaidai", "comedy", 5);
- my_store.AddMovie("Ivan Vasilyevich is changing his profession", "Leonid Gaidai", "comedy", 4);
- my_store.AddMovie("Sherlock Holmes", "Guy Ritchie", "detective", 5);
- my_store.AddMovie("Lock, Stock and Two Smoking Barrels", "Guy Ritchie", "comedy", 5);
- my_store.ShowAllMovies();
- my_store.DelMovie("Pirates of the Caribbean");
- my_store.ShowAllMovies();
- my_store.AddMovie("Pirates of the Caribbean", "Gore Verbinski", "fantasy", 5);
- my_store.FindMovieName("Diamond Hand");
- my_store.FindMovieProducer("Guy Ritchie");
- my_store.FindMovieGenre("fantasy");
- my_store.FindMovieMostPopular("fantasy");
- video_store my_store2(200);
- my_store2 = move(my_store);
- cout << "my_store: " << endl;
- my_store.ShowAllMovies();
- cout << "my_store2: " << endl;
- my_store2.ShowAllMovies();
- cout << boolalpha;
- cout << (my_store == my_store2) << endl;
- cout << (my_store != my_store2) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment