Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- //Defining the Class "Movies
- class Movies{
- private:
- int id, duration;
- double price;
- string title;
- public:
- Movies(): id(0), duration(0), price(0.00), title("N/A") {} //Constructor
- ~Movies(){} //Destructor
- void updPrice(double n){ //for Updating the Price of a Movie
- price = price * (100 + n) / 100;
- return;
- }
- void readData(){ //Takes input from user for movie info
- cin >> id >> title >> duration >> price;
- return;
- }
- void showData(){ //Prints the Movie info
- cout.setf (ios :: fixed);
- cout << left << setw(5) << id << left << setw(15) << title << right << setw(9) << duration << right << setw(9) << setprecision(2) << price << endl;
- return;
- }
- void maxPrice(Movies M[], int n){ //finds and prints the Maximum Priced Movie
- int i, m = 0, mi = -1;
- for (i = 0; i < n; i++)
- if (mi < M[i].price){
- mi = M[i].price;
- m = i;
- }
- cout << endl << "Highest Priced Movie is: " << endl;
- M[m].showData(); //calls the Movie info Printing function to print the info of the Max Priced Movie
- return;
- }
- };
- int main(){
- int n, i;
- double upd;
- cout << "How many movies in the store? ";
- cin >> n;
- Movies M[n]; //Declaring the Array of Objects
- //takes input for all the movies using loop
- for (i = 0; i < n ; i++){
- cout << "Enter info for movie " << i + 1 << ": ";
- M[i].readData();
- }
- //prints all the Movies info using loop
- cout << endl << "List of the Movies in the store: " << endl << left << setw(5) << "ID" << left << setw(15) << "Title" << right << setw(9) << "Duration" << right << setw(9) << "Price" << endl;
- for (i = 0; i < n; i++)
- M[i].showData();
- M[0].maxPrice(M, n); //Calls the maxPrice function to print the Highest Priced Movie info
- cout << endl << endl;
- //updates the Movie Prices
- for (i = 0; i < n; i++){
- cout << "Update the price of Movie " << i + 1 << "(in percentage): ";
- cin >> upd;
- M[i].updPrice(upd);
- }
- //prints all the updated Movies info using loop
- cout << endl << "Updated list of the Movies in the store: " << endl << left << setw(5) << "ID" << left << setw(15) << "Title" << right << setw(9) << "Duration" << right << setw(9) << "Price" << endl;
- for (i = 0; i < n; i++)
- M[i].showData();
- M[0].maxPrice(M, n); //Calls the maxPrice function to print the Highest Priced Movie info
- cout << endl << endl << "Thank You" << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment