skb50bd

Movies [Lab -3]

Jun 4th, 2015
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. //Defining the Class "Movies
  9. class Movies{
  10. private:
  11.     int id, duration;
  12.     double price;
  13.     string title;
  14. public:
  15.     Movies(): id(0), duration(0), price(0.00), title("N/A") {} //Constructor
  16.  
  17.     ~Movies(){} //Destructor
  18.  
  19.     void updPrice(double n){ //for Updating the Price of a Movie
  20.         price = price * (100 + n) / 100;
  21.         return;
  22.     }
  23.  
  24.     void readData(){ //Takes input from user for movie info
  25.         cin >> id >> title >> duration >> price;
  26.         return;
  27.     }
  28.  
  29.     void showData(){ //Prints the Movie info
  30.         cout.setf (ios :: fixed);
  31.         cout << left << setw(5) << id << left << setw(15) << title << right << setw(9) << duration << right << setw(9) << setprecision(2) << price << endl;
  32.         return;
  33.     }
  34.  
  35.     void maxPrice(Movies M[], int n){ //finds and prints the Maximum Priced Movie
  36.         int i, m = 0, mi = -1;
  37.  
  38.         for (i = 0; i < n; i++)
  39.             if (mi < M[i].price){
  40.                 mi = M[i].price;
  41.                 m = i;
  42.             }
  43.         cout << endl << "Highest Priced Movie is: " << endl;
  44.         M[m].showData(); //calls the Movie info Printing function to print the info of the Max Priced Movie
  45.         return;
  46.         }
  47. };
  48.  
  49.  
  50.  
  51. int main(){
  52.     int n, i;
  53.     double upd;
  54.  
  55.     cout << "How many movies in the store? ";
  56.     cin >> n;
  57.  
  58.     Movies M[n]; //Declaring the Array of Objects
  59.  
  60.     //takes input for all the movies using loop
  61.     for (i = 0; i < n ; i++){
  62.         cout << "Enter info for movie " << i + 1 << ": ";
  63.         M[i].readData();
  64.     }
  65.  
  66.     //prints all the Movies info using loop
  67.     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;
  68.     for (i = 0; i < n; i++)
  69.         M[i].showData();
  70.  
  71.     M[0].maxPrice(M, n); //Calls the maxPrice function to print the Highest Priced Movie info
  72.  
  73.     cout << endl << endl;
  74.  
  75.     //updates the Movie Prices
  76.     for (i = 0; i < n; i++){
  77.         cout << "Update the price of Movie " << i + 1 << "(in percentage): ";
  78.         cin >> upd;
  79.         M[i].updPrice(upd);
  80.     }
  81.  
  82.     //prints all the updated Movies info using loop
  83.     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;
  84.     for (i = 0; i < n; i++)
  85.         M[i].showData();
  86.  
  87.     M[0].maxPrice(M, n); //Calls the maxPrice function to print the Highest Priced Movie info
  88.  
  89.     cout << endl << endl << "Thank You" << endl;
  90.  
  91.     return 0;
  92. }
Add Comment
Please, Sign In to add comment