Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <iostream>

#include <string>
#include <algorithm>
#define N 3
using namespace std;

struct movie {
string name;
double price;
string director;

void input() {
getline(cin, name);
cout << endl << "Director: ";
getline(cin, director);
cout << endl << "Price: ";
cin >> price;
cin.ignore();
cout << endl;
}

void output() {
cout << name << endl;
cout << director << endl;
cout << price << endl;
cout << "------------------------------\n";
}
};

int main()
{
movie* videot = new movie[N];
int avg_price = 0, min_price = 0, max_price = 0;
double total_price = 0;
for (int i = 0; i < N; i++) {
cout << "Name of " << i + 1 << " movie: ";
videot[i].input();
total_price += videot[i].price;
if (videot[i].price > videot[max_price].price) max_price = i;
if (videot[i].price < videot[min_price].price) min_price = i;
}
avg_price = total_price / N;
cout << "------------------------------\n";
cout << "Movie with max price:\n";
videot[max_price].output();
cout << "Movie with min price:\n";
videot[min_price].output();
cout << "Movie(s) with price more than avg:\n";
for (int i = 0; i < N; i++) {
if (videot[i].price > avg_price) {
videot[i].output();
}
}
}

You might also like