Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // магазин (вариант на стеке)
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <string.h>
- using namespace std;
- struct film {
- char name[100]{};
- char producer[100]{};
- char genre[20]{};
- int rating = 0;
- };
- struct video_store {
- film store[100]{};
- int films_number = 0;
- };
- void ShowAllMovies(const video_store& some_store) {
- cout << "The following films are available: " << endl;
- if (some_store.films_number == 0) {
- cout << "No movies";
- }
- for (int i = 0; i < some_store.films_number; ++i) {
- cout << '\"' << some_store.store[i].name << "\", producer: " << some_store.store[i].producer << ", " << some_store.store[i].genre << ", rating " << some_store.store[i].rating << endl;
- }
- cout << endl;
- }
- void AddMovie(video_store& some_store, const char name[], const char producer[], const char genre[], const int rating) { // не забывать ставить const, иначе не скомпилируется
- if (some_store.films_number == 100) {
- cout << "The movie cannot be added" << endl;
- return;
- }
- strcpy(some_store.store[some_store.films_number].name, name);
- strcpy(some_store.store[some_store.films_number].producer, producer);
- strcpy(some_store.store[some_store.films_number].genre, genre);
- some_store.store[some_store.films_number].rating = rating;
- some_store.films_number++;
- }
- void DelMovie(video_store& some_store, const char name[]) {
- for (int i = 0; i < some_store.films_number; i++) {
- if (!strcmp(some_store.store[i].name, name)) { // возвращает 0 если строки одинаковые, поэтому используем ! (чтобы возврат нуля означал "истину")
- for (int j = i; j < some_store.films_number - 1; j++) {
- some_store.store[j] = some_store.store[j + 1];
- }
- some_store.store[some_store.films_number - 1] = {};
- some_store.films_number--;
- }
- }
- }
- int main() {
- video_store my_store;
- AddMovie(my_store, "Pirates of the Caribbean", "Gore Verbinski", "fantasy", 5);
- AddMovie(my_store, "Harry Potter", "Chris Columbus", "fantasy", 4);
- AddMovie(my_store, "Diamond Hand", "Leonid Gaidai", "comedy", 5);
- AddMovie(my_store, "Ivan Vasilyevich is changing his profession", "Leonid Gaidai", "comedy", 4);
- AddMovie(my_store, "Sherlock Holmes", "Guy Ritchie", "detective", 5);
- AddMovie(my_store, "Lock, Stock and Two Smoking Barrels", "Guy Ritchie", "comedy", 5);
- ShowAllMovies(my_store);
- DelMovie(my_store, "Pirates of the Caribbean");
- ShowAllMovies(my_store);
- }
Advertisement
Add Comment
Please, Sign In to add comment