You are on page 1of 8

Камера Problem 2 (2 / 2)

Да се креира програма која ќе овмозможи креирање и репрезентација на дигитални


камери. Да се креира абстрактна класа Camera која ќе овозможи базична
репрезентација на објектите од типот камера. За класата да се дефинираат:

Производител на камерата (низа од макс. 20 знаци)


Модел на камерата (низа од макс. 20 знаци)
Година на производство (цел број)
Резолуција во мегапиксели (MP - децимален број)
За класата да се дефинираат потребните методи и конструктори со цел коректно да
работи програмата (5 поени).

Од класата Camera да се изведат класите: PhotoCamera, VideoCamera и FilmCamera.

За класата PhotoCamera дополнителено да се дефинира дали камерата поддржува сликање


во RAW формат на слики (bool променлива). За FilmCamera треба да се дефинира
максимална брзина на снимање (цел број кој изразува фрејмови во секунда - fps),
додека за VideoCamera треба да се дефинира максималната должина на видео фајловите
кои може да се снимаат (цел број изразен во секунди). (5 поени)

Дополнително за изведените класи да се дефинираат методи price() и rentalPrice(int


days)
кои ќе треба соодветно да ги пресметуваат цените за купување односно изнајмување
на камерата
за одреден број на денови. Цените на камерите се пресметуваат на следниот начин
(15 поени):

За PhotoCamera цената на купување (изразена во евра) е: 100 + MP*20 каде MP e


бројот на мегапиксели.
Доколку камерата поддржува работа со RAW формат, тогаш цената се зголемува за 50
евра.
За VideoCamera основната цената на купување (изразена во евра) е: MP*80 каде MP e
бројот на мегапиксели.
Доколку камерата поддржува снимање на видеа подолги од 60 минути, цената се
зголемува за 40%.
Филмската камера има почетна цена од 50000 евра, а доколку камерата поддржува
снимање со брзина поголема од 30fps,
за секој fps преку 30, цената се зголемува за 5000.
Цената на изнајмување на PhotoCamera и VideoCamera по ден е една стотина (1/100) од
цената на камерата.
Доколку камерата се изнајмува за повеќе од 7 дена, тогаш цената се намалува за 20%.

Цената за изнајмување на филмската камера е 500 евра по ден,


а доколку камерата поддржува снимање со 60fps тогаш цената се дуплира (5 поени)

Да се преоптовари операторот < за споредба на кои било двe камери според цената за
купување на камерата (5 поени).

Да се дефинирa глобалнa функциja float production(Camera **c, int num, int days)
која ќе прима низа од покажувачи кон камери, бројот на елементите во низата како и
број на денови за кои трае продукцијата. Функцијата како резултат ја враќа цената
на изнајмување на сите камери во соодветното времетаење (10 поени)

Да се дефинира глобална функција mostExpensiveCamera(Camera **c, int num,) која ќе


прима низа од покажувачи кон камери и големина на низата, а како резултат ќе го
врати моделот и производителот на камерата која има најголема цена за купување (5
поени)

//
// Created by krstevkoki on 8/22/17.
//
#include <iostream>
#include <cstring>

using namespace std;

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);
}

bool operator<(const Camera &c) {


return this->price() < c.price();
}

virtual const float price() const = 0;

virtual const float rental_price(int days) const = 0;

char *getModel() {
return model;
}

virtual ~Camera() {}
};

class PhotoCamera : public Camera {


private:
bool raw;
public:
PhotoCamera(const char *manufacturer, const char *model, const int year, const
float resolution, const bool raw)
: Camera(manufacturer, model, year, resolution) {
this->raw = raw;
}

const float price() const {


float total = 100 + (resolution * 20);
if (raw)
return total + 50;
return total;
}

const float rental_price(int days) const {


float total = ((1 / float(100)) * price());
if (days > 7)
return total - (20 / float(100)) * total;
return total;
}

~PhotoCamera() {}
};

class VideoCamera : public Camera {


private:
int seconds;
public:
VideoCamera(const char *manufacturer, const char *model, const int year, const
float resolution, const int seconds)
: Camera(manufacturer, model, year, resolution) {
this->seconds = seconds;
}

const float price() const {


float total = resolution * 80;
if (seconds > 3600)
return total + (40 / float(100)) * total;
return total;
}

const float rental_price(int days) const {


float total = ((1 / float(100)) * price());
if (days > 7)
return total - (20 / float(100)) * total;
return total;
}

~VideoCamera() {}
};

class FilmCamera : public Camera {


private:
int fps;
public:
FilmCamera(const char *manufacturer, const char *model, const int year, const
float resolution, const int fps)
: Camera(manufacturer, model, year, resolution) {
this->fps = fps;
}

const float price() const {


float total = 50000;
if (fps > 30) {
return total + ((fps - 30) * 5000);
}
return total;
}

const float rental_price(int days) const {


float total = 500 * days;
/*if (fps == 60)
return 2 * total;*/
return total;
}

~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;
}

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 << endl << "Most expensive camera used in production is: " <<
mostExpensiveCamera(c, n);
return 0;
}

/*
#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];

// 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;
}
*/

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

You might also like