Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- using namespace std;
- // Your code here
- class Camera {
- protected:
- char manufacturer[20];
- char model[20];
- int year;
- float resolution;
- public:
- Camera(char *manufacturer, char *model, int year, float resolution) {
- strcpy(this->manufacturer, manufacturer);
- strcpy(this->model, model);
- this->year = year;
- this->resolution = resolution;
- }
- virtual const float price() const = 0;
- virtual const float rentalPrice(int days) const = 0;
- bool operator<(const Camera &c) {
- return this->price() < c.price();
- }
- char *getModel() {
- return model;
- }
- virtual ~Camera() {
- }
- };
- class PhotoCamera : public Camera {
- private:
- bool raw;
- public:
- PhotoCamera(char *manufacturer, char *model, int year, float resolution, bool raw) :
- Camera(manufacturer, model, year, resolution) {
- this->raw = raw;
- }
- const virtual float price() const {
- float total = 100 + (resolution * 20.0);
- if(raw == 1)
- return total + 50.0;
- else
- return total;
- }
- const virtual float rentalPrice(int days) const {
- float total = ((1/(float)100)) * price();
- if(days > 7)
- return total - (20/float(100)) * total;
- else
- return total;
- }
- };
- class VideoCamera : public Camera {
- private:
- int length;
- public:
- VideoCamera(char *manufacturer, char *model, int year, float resolution, int length) :
- Camera(manufacturer, model, year, resolution) {
- this->length = length;
- }
- const virtual float price() const {
- float total = resolution * 80;
- if(length > 3600) {
- return total + (40 / float(100)) * total;
- } else
- return total;
- }
- const virtual float rentalPrice(int days) const {
- float total = ((1/(float)100)) * price();
- if(days > 7)
- return total - (20/float(100)) * total;
- else
- return total;
- }
- };
- class FilmCamera : public Camera {
- private:
- int fps;
- public:
- FilmCamera(char *manufacturer, char *model, int year, float resolution, int fps) :
- Camera(manufacturer, model, year, resolution) {
- this->fps=fps;
- }
- const virtual float price() const {
- float total = 50000;
- if(fps>30)
- return total + ((fps - 30) * 5000);
- return total;
- }
- const virtual float rentalPrice(int days) const {
- float total = 500 * days;
- /* if(fps>60)
- return 2 * total;
- else */
- return total;
- }
- };
- float production(Camera **c, int num, int days) {
- float total = 0;
- for(int i = 0; i < num; i++) {
- total += c[i]->rentalPrice(days);
- }
- return total;
- }
- char *mostExpensiveCamera(Camera **c, int num) {
- Camera *max = c[0];
- for(int i = 1; i < num; i++) {
- if(*max < *c[i])
- max = c[i];
- }
- return max->getModel();
- }
- int main(int argc, char *argv[])
- {
- // Variables for reading input
- char model[20], producer[20];
- int year, length, fps, n;
- float resolution;
- bool raw;
- int t;
- // Array of cameras
- Camera *c [10];
- // Read number of cameras
- cin>>n;
- for(int i = 0; i < n; ++i){
- // Camera type: 1 - Photo, 2 - Video, 3 - Film
- cin>>t;
- if (t==1){
- cin >> producer >> model >> year >> resolution;
- cin >> raw;
- c[i] = new PhotoCamera(producer, model, year, resolution, raw);
- }
- else if (t==2){
- cin >> producer >> model >> year >> resolution;
- cin >> length;
- c[i] = new VideoCamera(producer, model, year, resolution, length);
- }
- else if (t==3){
- cin >> producer >> model >> year >> resolution;
- cin >> fps;
- c[i] = new FilmCamera(producer, model, year, resolution, fps);
- }
- }
- // Production days
- int days;
- cin >> days;
- cout<< "Price of production is: " << production(c, n, days);
- cout<<"\n" << "Most expensive camera used in production is: " << mostExpensiveCamera(c, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment