Professional Documents
Culture Documents
Камера
Камера
Да се преоптовари операторот < за споредба на кои било двe камери според цената за
купување на камерата (5 поени).
Да се дефинирa глобалнa функциja float production(Camera **c, int num, int days)
која ќе прима низа од покажувачи кон камери, бројот на елементите во низата како и
број на денови за кои трае продукцијата. Функцијата како резултат ја враќа цената
на изнајмување на сите камери во соодветното времетаење (10 поени)
//
// Created by krstevkoki on 8/22/17.
//
#include <iostream>
#include <cstring>
class Camera {
protected:
char manufacturer[20];
char model[20];
int year;
float resolution;
public:
Camera(const char *manufacturer, const char *model, const int year, const float
resolution) {
this->year = year;
this->resolution = resolution;
strcpy(this->manufacturer, manufacturer);
strcpy(this->model, model);
}
char *getModel() {
return model;
}
virtual ~Camera() {}
};
~PhotoCamera() {}
};
~VideoCamera() {}
};
~FilmCamera() {}
};
float production(Camera **c, const int num, const int days) {
float total = 0;
for (int i = 0; i < num; ++i)
total += c[i]->rental_price(days);
return total;
}
/*
#include <iostream>
#include <cstring>
using namespace std;
class Camera
{
protected:
char producer[20];
char model[20];
int year;
float resolution;
public:
Camera(char producer[] = "",char model[]="",int year =0,float resolution =0)
{
strcpy(this->producer,producer);
strcpy(this->model,model);
this->year = year;
this->resolution = resolution;
}
char* getModel()
{
return model;
}
virtual float rentalPrice(int days) = 0;
virtual float price() = 0;
virtual ~Camera(){}
};
class PhotoCamera : public Camera
{
private:
bool raw;
public:
PhotoCamera(char producer[] = "",char model[]="",int year =0,float resolution
=0,bool raw=0) : Camera(producer,model,year,resolution)
{
this->raw = raw;
}
float price()
{
if(raw)
{
return 150 + resolution *20;
}
return 100 + resolution*20;
}
float rentalPrice(int days)
{
if(days>7)
{
return (price()/100 - price()/100*20/100);
}
return price()/100;
}
~PhotoCamera(){}
};
class VideoCamera : public Camera
{
private:
int length;
public:
VideoCamera(char producer[] = "",char model[]="",int year =0,float resolution
=0,int length=0) : Camera(producer,model,year,resolution)
{
this->length = length;
}
float price()
{
if(length>3600)
{
return resolution*80 + resolution*80*40/100;
}
return resolution*80;
}
float rentalPrice(int days)
{
if(days>7)
{
return (price()/100 - price()/100*20/100);
}
return (price()/100);
}
~VideoCamera(){}
};
class FilmCamera : public Camera
{
private:
int fps;
public:
FilmCamera(char producer[] = "",char model[]="",int year =0,float resolution
=0,int fps=0) : Camera(producer,model,year,resolution)
{
this->fps = fps;
}
float price()
{
if(fps>30)
{
return 55000;
}
return 50000;
}
float rentalPrice(int days)
{
if(fps<60)
return 1000*days;
return 500*days;
}
~FilmCamera(){}
};
float production(Camera **c, int num, int days)
{
float vk=0;
for(int i=0;i<num;i++)
{
vk = vk + c[i]->rentalPrice(days);
}
return vk;
}
char* mostExpensiveCamera(Camera **c, int num)
{
float max=0;
int index;
for(int i=0;i<num;i++)
{
if(c[i]->price()>max)
{
max = c[i]->price();
index =i;
}
}
return c[index]->getModel();
}
int main()
{
// 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];
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;
return 0;
}
*/
Sample input
4
1
Nikon
NN
2007
3
0
2
Panasonik
K444
2000
0.5
1800
3
BMD
RED
2015
80
60
1
Canon
C1
2015
5
1
5
Sample output
Price of production is: 2504.5
Most expensive camera used in production is: RED