consolidate all repos to one for archive
This commit is contained in:
7
semester_2/programiranje_2/naloga1001/Artist.cpp
Normal file
7
semester_2/programiranje_2/naloga1001/Artist.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "Artist.h"
|
||||
|
||||
Artist::Artist(std::string name, std::string biography, unsigned int day, unsigned int month, unsigned int year) : name(name), biography(biography), dateOfBirth(day, month, year){}
|
||||
|
||||
std::string Artist::toString() const {
|
||||
return name + ", " + biography + ", " + dateOfBirth.toString();
|
||||
}
|
20
semester_2/programiranje_2/naloga1001/Artist.h
Normal file
20
semester_2/programiranje_2/naloga1001/Artist.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef NALOGA0201_ARTIST_H
|
||||
#define NALOGA0201_ARTIST_H
|
||||
|
||||
#include "Date.h"
|
||||
|
||||
class Artist {
|
||||
private:
|
||||
std::string name, biography;
|
||||
Date dateOfBirth;
|
||||
public:
|
||||
Artist() = default;
|
||||
|
||||
Artist(std::string name, std::string biography, unsigned int day, unsigned int month, unsigned int year);
|
||||
|
||||
~Artist() = default;
|
||||
|
||||
std::string toString() const;
|
||||
};
|
||||
|
||||
#endif //NALOGA0201_ARTIST_H
|
21
semester_2/programiranje_2/naloga1001/Artwork.cpp
Normal file
21
semester_2/programiranje_2/naloga1001/Artwork.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "Artwork.h"
|
||||
|
||||
Artwork::Artwork(std::string title, std::string description, int price, int year, Artist *artist, double width, double height, double depth) :
|
||||
title(title), description(description), price(price), year(year), artist(artist), dimension(width, height, depth){}
|
||||
|
||||
std::string Artwork::toString() const {
|
||||
return "Title: " + title +
|
||||
"\nDescription: " + description +
|
||||
"\nPrice: " + std::to_string(price) +
|
||||
" EUR\nYear: " + std::to_string(year) +
|
||||
"\nArtist: " + artist->toString() +
|
||||
"\nDimension: " + dimension.toString() + "\n\n";
|
||||
}
|
||||
|
||||
int Artwork::getPrice() const {
|
||||
return price;
|
||||
}
|
||||
|
||||
int Artwork::getYear() const {
|
||||
return year;
|
||||
}
|
27
semester_2/programiranje_2/naloga1001/Artwork.h
Normal file
27
semester_2/programiranje_2/naloga1001/Artwork.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef NALOGA0201_ARTWORK_H
|
||||
#define NALOGA0201_ARTWORK_H
|
||||
|
||||
#include "Artist.h"
|
||||
#include "Dimension.h"
|
||||
|
||||
class Artwork {
|
||||
protected:
|
||||
std::string title, description;
|
||||
int price, year;
|
||||
Artist *artist;
|
||||
Dimension dimension;
|
||||
public:
|
||||
Artwork() = default;
|
||||
|
||||
Artwork(std::string title, std::string description, int price, int year, Artist *artist, double width, double height, double depth);
|
||||
|
||||
virtual ~Artwork() = default;
|
||||
|
||||
virtual std::string toString() const;
|
||||
|
||||
int getPrice() const;
|
||||
|
||||
int getYear() const;
|
||||
};
|
||||
|
||||
#endif //NALOGA0201_ARTWORK_H
|
7
semester_2/programiranje_2/naloga1001/Date.cpp
Normal file
7
semester_2/programiranje_2/naloga1001/Date.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "Date.h"
|
||||
|
||||
Date::Date(unsigned int day, unsigned int month, unsigned int year) : day(day), month(month), year(year) {}
|
||||
|
||||
std::string Date::toString() const {
|
||||
return std::to_string(day) + ", " + std::to_string(month) + ", " + std::to_string(year);
|
||||
}
|
19
semester_2/programiranje_2/naloga1001/Date.h
Normal file
19
semester_2/programiranje_2/naloga1001/Date.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef NALOGA0201_DATE_H
|
||||
#define NALOGA0201_DATE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class Date {
|
||||
private:
|
||||
unsigned int day, month, year;
|
||||
public:
|
||||
Date() = default;
|
||||
|
||||
Date(unsigned int day, unsigned int month, unsigned int year);
|
||||
|
||||
~Date() = default;
|
||||
|
||||
std::string toString() const;
|
||||
};
|
||||
|
||||
#endif //NALOGA0201_DATE_H
|
9
semester_2/programiranje_2/naloga1001/Dimension.cpp
Normal file
9
semester_2/programiranje_2/naloga1001/Dimension.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "Dimension.h"
|
||||
|
||||
Dimension::Dimension(double width, double height, double depth) : width(width), height(height), depth(depth) {
|
||||
|
||||
}
|
||||
|
||||
std::string Dimension::toString() const {
|
||||
return std::to_string(width) + " " + std::to_string(height) + " " + std::to_string(depth);
|
||||
}
|
18
semester_2/programiranje_2/naloga1001/Dimension.h
Normal file
18
semester_2/programiranje_2/naloga1001/Dimension.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef NALOGA0201_DIMENSION_H
|
||||
#define NALOGA0201_DIMENSION_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class Dimension {
|
||||
private:
|
||||
double width, height, depth;
|
||||
public:
|
||||
Dimension() = default;
|
||||
Dimension(double width, double height, double depth);
|
||||
~Dimension() = default;
|
||||
|
||||
std::string toString() const;
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0201_DIMENSION_H
|
28
semester_2/programiranje_2/naloga1001/Functions.h
Normal file
28
semester_2/programiranje_2/naloga1001/Functions.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef NALOGA1001_FUNCTIONS_H
|
||||
#define NALOGA1001_FUNCTIONS_H
|
||||
|
||||
#include "Artwork.h"
|
||||
|
||||
bool ascendingYear(Artwork* i, Artwork* j){
|
||||
return i->getYear() < j->getYear();
|
||||
};
|
||||
|
||||
bool descandingYear(Artwork* i, Artwork* j){
|
||||
return i->getYear() > j->getYear() ;
|
||||
};
|
||||
|
||||
bool ascendingPrice(Artwork* i, Artwork* j) {
|
||||
return (i->getPrice() > j->getPrice());
|
||||
|
||||
};
|
||||
|
||||
bool isRenaissanceArt(Artwork* a){
|
||||
//return (a->getYear() > 1400 && a->getYear() < 1600);
|
||||
return a->getYear() < 0;
|
||||
};
|
||||
|
||||
bool isCheperThen(Artwork* a){
|
||||
return a->getPrice() < 1500;
|
||||
};
|
||||
|
||||
#endif //NALOGA1001_FUNCTIONS_H
|
43
semester_2/programiranje_2/naloga1001/Gallery.cpp
Normal file
43
semester_2/programiranje_2/naloga1001/Gallery.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "Gallery.h"
|
||||
#include <iostream>
|
||||
|
||||
Gallery::Gallery(std::string name) : name(name) {
|
||||
}
|
||||
|
||||
void Gallery::addArtwork(Artwork *artwork) {
|
||||
artworks.push_back(artwork);
|
||||
}
|
||||
|
||||
void Gallery::printArtworks() const {
|
||||
for (auto &artwork: artworks)
|
||||
std::cout << artwork->toString() << std::endl;
|
||||
}
|
||||
|
||||
std::string Gallery::toString() const {
|
||||
std::string ret;
|
||||
for (auto &artwork: artworks) ret += artwork->toString() + "\n\n";
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Gallery::sort(bool (*c)(Artwork *, Artwork *)) {
|
||||
std::sort(artworks.begin(),artworks.end(), c);
|
||||
}
|
||||
|
||||
Artwork *Gallery::find(bool (*c)(Artwork *)) {
|
||||
auto it = std::find_if(artworks.begin(),artworks.end(),c);
|
||||
return *it;
|
||||
}
|
||||
|
||||
void Gallery::printArtworks(PrintIfPainting i) {
|
||||
std::for_each(artworks.begin(),artworks.end(),i);
|
||||
}
|
||||
|
||||
std::vector<Artwork *> Gallery::filteredVector(bool (*c)(Artwork *)) {
|
||||
std::vector<Artwork *> tmp;
|
||||
for (int i = 0; i < artworks.size(); ++i) {
|
||||
if(c(artworks[i])){
|
||||
tmp.push_back(artworks[i]);
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
};
|
46
semester_2/programiranje_2/naloga1001/Gallery.h
Normal file
46
semester_2/programiranje_2/naloga1001/Gallery.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef NALOGA0201_GALLERY_H
|
||||
#define NALOGA0201_GALLERY_H
|
||||
|
||||
#include "Artwork.h"
|
||||
#include "Painting.h"
|
||||
#include "Literature.h"
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
struct PrintIfPainting{
|
||||
void operator()(Artwork* e){
|
||||
if(auto* derived = dynamic_cast<Painting*> (e)){
|
||||
std::cout << derived->toString() << "\n";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Gallery {
|
||||
private:
|
||||
std::string name;
|
||||
std::vector<Artwork *> artworks;
|
||||
public:
|
||||
Gallery() = default;
|
||||
|
||||
explicit Gallery(std::string name);
|
||||
|
||||
~Gallery() = default;
|
||||
|
||||
void addArtwork(Artwork *artwork);
|
||||
|
||||
void printArtworks() const;
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
void sort(bool (*c)(Artwork*, Artwork*));
|
||||
|
||||
void printArtworks(PrintIfPainting i);
|
||||
|
||||
Artwork* find(bool (*c)(Artwork*));
|
||||
|
||||
std::vector<Artwork *> filteredVector(bool (*c)(Artwork*));
|
||||
};
|
||||
|
||||
#endif //NALOGA0201_GALLERY_H
|
||||
|
47
semester_2/programiranje_2/naloga1001/Literature.cpp
Normal file
47
semester_2/programiranje_2/naloga1001/Literature.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "Literature.h"
|
||||
|
||||
Literature::Literature(std::string title, std::string description, int price, int year, Artist *artist, double width, double height, double depth, LiteratureType material) :
|
||||
Artwork(title, description, price, year, artist, width, height, depth), material(material) {}
|
||||
|
||||
std::string Literature::getMaterial() const{
|
||||
switch (material) {
|
||||
case LiteratureType::Drama:
|
||||
return "Drama";
|
||||
break;
|
||||
case LiteratureType::Biography:
|
||||
return "Biography";
|
||||
break;
|
||||
case LiteratureType::Poetry:
|
||||
return "Poetry";
|
||||
break;
|
||||
case LiteratureType::Prose:
|
||||
return "Prose";
|
||||
break;
|
||||
case LiteratureType::ScienceFiction:
|
||||
return "Science fiction";
|
||||
break;
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
std::string Literature::toString() const {
|
||||
return "Title: " + title +
|
||||
"\nDescription: " + description +
|
||||
"\nPrice: " + std::to_string(price) +
|
||||
" EUR\nYear: " + std::to_string(year) +
|
||||
"\nArtist: " + artist->toString() +
|
||||
"\nDimension: " + dimension.toString() +
|
||||
"\nPainting technique: " + getMaterial() + "\n\n";
|
||||
}
|
||||
|
||||
void Literature::print() const {
|
||||
std::cout <<
|
||||
"Title: " << title <<
|
||||
"\nDescription: " << description <<
|
||||
"\nPrice: " << std::to_string(price) <<
|
||||
" EUR\nYear: " << std::to_string(year) <<
|
||||
"\nArtist: " << artist->toString() <<
|
||||
"\nDimension: " << dimension.toString() <<
|
||||
"\nLiterature type: " << getMaterial() << "\n\n";
|
||||
}
|
22
semester_2/programiranje_2/naloga1001/Literature.h
Normal file
22
semester_2/programiranje_2/naloga1001/Literature.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef NALOGA0201_LITERATURE_H
|
||||
#define NALOGA0201_LITERATURE_H
|
||||
|
||||
#include "Artwork.h"
|
||||
#include <iostream>
|
||||
|
||||
enum class LiteratureType {
|
||||
Drama, Biography, Poetry, Prose, ScienceFiction,
|
||||
};
|
||||
|
||||
class Literature: public Artwork {
|
||||
private:
|
||||
LiteratureType material;
|
||||
public:
|
||||
Literature(std::string title, std::string description, int price, int year, Artist *artist, double width, double height, double depth, LiteratureType material);
|
||||
std::string getMaterial() const;
|
||||
std::string toString() const override;
|
||||
void print() const;
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0201_LITERATURE_H
|
31
semester_2/programiranje_2/naloga1001/Painting.cpp
Normal file
31
semester_2/programiranje_2/naloga1001/Painting.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "Painting.h"
|
||||
|
||||
Painting::Painting(std::string title, std::string description, int price, int year, Artist *artist, double width, double height, double depth, PaintingTechnique technique) :
|
||||
Artwork(title, description, price, year, artist, width, height, depth), technique(technique) {}
|
||||
|
||||
std::string Painting::getTechnique() const{
|
||||
switch (technique) {
|
||||
case PaintingTechnique::Oil:
|
||||
return "Oil";
|
||||
break;
|
||||
case PaintingTechnique::Acrylic:
|
||||
return "Acrylic";
|
||||
break;
|
||||
case PaintingTechnique::Graphite:
|
||||
return "Graphite";
|
||||
break;
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
std::string Painting::toString() const {
|
||||
return "Title: " + title +
|
||||
"\nDescription: " + description +
|
||||
"\nPrice: " + std::to_string(price) +
|
||||
" EUR\nYear: " + std::to_string(year) +
|
||||
"\nArtist: " + artist->toString() +
|
||||
"\nDimension: " + dimension.toString() +
|
||||
"\nPainting technique: " + getTechnique() + "\n\n";
|
||||
}
|
||||
|
28
semester_2/programiranje_2/naloga1001/Painting.h
Normal file
28
semester_2/programiranje_2/naloga1001/Painting.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef NALOGA0201_PAINTING_H
|
||||
#define NALOGA0201_PAINTING_H
|
||||
|
||||
#include "Artwork.h"
|
||||
|
||||
enum class PaintingTechnique {
|
||||
Oil,
|
||||
Acrylic,
|
||||
Graphite
|
||||
};
|
||||
|
||||
class Painting : public Artwork {
|
||||
private:
|
||||
PaintingTechnique technique;
|
||||
public:
|
||||
Painting() = default;
|
||||
|
||||
Painting(std::string title, std::string description, int price, int year, Artist *artist, double width, double height, double depth, PaintingTechnique technique);
|
||||
|
||||
~Painting() = default;
|
||||
|
||||
std::string getTechnique() const;
|
||||
|
||||
std::string toString() const override;
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0201_PAINTING_H
|
59
semester_2/programiranje_2/naloga1001/README.md
Normal file
59
semester_2/programiranje_2/naloga1001/README.md
Normal file
@@ -0,0 +1,59 @@
|
||||
Uporabite in razširite nalogo 5.1 po spodnjih navodilih.
|
||||
|
||||
Razširite nalogo tako, da v glavnem programu podprete spodnje klice metode sort, ki s pomočjo funkcije kot parameter sortira umetnine v galeriji na različne načine:
|
||||
|
||||
gallery.sort(ascendingYear);
|
||||
cout << gallery.toString() << std::endl;
|
||||
gallery.sort(descendingYear);
|
||||
cout << gallery.toString() << std::endl;
|
||||
gallery.sort(ascendingPrice);
|
||||
cout << gallery.toString() << std::endl;
|
||||
|
||||
V ta namen zapišite naslednje:
|
||||
Dodajte metodo sort v razred Gallery:
|
||||
|
||||
void sort(bool (*c)(Artwork*, Artwork*));
|
||||
|
||||
Metoda sort uredi vector artworks v razredu Gallery, tako kot zahteva funkcija, ki jo prejme kot parameter.
|
||||
Za potrebe metode sort implementirajte še:
|
||||
|
||||
bool ascendingYear(Artwork* i, Artwork* j);
|
||||
bool descandingYear(Artwork* i, Artwork* j);
|
||||
bool ascendingPrice(Artwork* i, Artwork* j);
|
||||
|
||||
Funkcije implementirajte zunaj razreda Gallery.
|
||||
|
||||
V glavnem programu podprite naslednjo vrstico kode, ki poišče prvo umetnino, ki je iz renesančnega obdobja.
|
||||
|
||||
cout << gallery.find(isRenaissanceArt)->toString();
|
||||
|
||||
Potrebujemo naslednje:
|
||||
Dodajte metodo find v razred Gallery:
|
||||
|
||||
Artwork* find(bool (*c)(Artwork*));
|
||||
|
||||
Metoda find vrne prvi element vector-ja artworks v razredu Gallery, ki ustreza pogoju. Za implementacijo uporabite funkcijo find_if iz knjižnice algorithms: http://www.cplusplus.com/reference/algorithm/find_if/. Tretji parameter funkcije find_if je parameter metode find (glej zgoraj).
|
||||
|
||||
Za potrebe metode find v glavnem programu implementirajte še:
|
||||
bool isRenaissanceArt(Artwork* a);
|
||||
|
||||
Funkcija preveri, ali je letnica umetnine med 1400 in 1600.
|
||||
|
||||
V glavnem programu podprite naslednji vrstici kode, ki izpiše vse Painting umetnine iz galerije:
|
||||
|
||||
PrintIfPainting paint;
|
||||
gallery.printArtworks(paint);
|
||||
|
||||
Potrebujemo naslednje:
|
||||
Dodajte metodo printArtworks v razred Gallery:
|
||||
|
||||
void printArtworks(PrintIfPainting i);
|
||||
|
||||
Metoda printArtworks izpiše vse umetnine v razredu Gallery, tako kot zahteva funkcijski tip PrintIfPainting, ki jo prejme kot parameter. Za implementacijo uporabite funkcijo for_each iz knjižnice algorithms: http://www.cplusplus.com/reference/algorithm/for_each/. Tretji parameter funkcije for_each je parameter metode printArtworks (glej zgoraj).
|
||||
Za potrebe funkcije for_each implementirajte razred PrintIfPainting ter prekrijte operator:
|
||||
|
||||
void operator()(Artwork* e);
|
||||
|
||||
V zgornji metodi boste potrebovali rezervirano besedo dynamic_cast ( primer: https://en.cppreference.com/w/cpp/language/dynamic_cast).
|
||||
|
||||
V glavnem programu demonstrirajte uporabo kazalcev na funkcije in funkcijske tipe.
|
62
semester_2/programiranje_2/naloga1001/main.cpp
Normal file
62
semester_2/programiranje_2/naloga1001/main.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <iostream>
|
||||
#include "Gallery.h"
|
||||
#include "Functions.h"
|
||||
|
||||
int main() {
|
||||
Gallery slo("galer");
|
||||
|
||||
Artist artist1("Leonardo da Vinci", "biografi", 15, 4, 1452);
|
||||
Artwork art1("Mona Lisa", "desc", 100, 1797, &artist1, 32, 56, 94);
|
||||
slo.addArtwork(&art1);
|
||||
|
||||
Artist artist2 = {"Vincent van Goth", "bio", 30, 3, 1853};
|
||||
Artwork art2 = {"The starry Night", "desc", 256, 1889, &artist2, 56, 86, 15};
|
||||
slo.addArtwork(&art2);
|
||||
|
||||
Artist artist3 = {"Jahannes Vermeer", "biog", 1, 10, 1632};
|
||||
Artwork art3 = {"Girl with a Pearl Erring", "desc", 568, 1665, &artist3, 59, 56, 1};
|
||||
slo.addArtwork(&art3);
|
||||
|
||||
Artist artist4 = {"Gustav Klimt", "biog", 14, 7, 1862};
|
||||
Artwork art4 = {"The kiss", "desc", 465, 1907, &artist4, 47, 56, 2};
|
||||
slo.addArtwork(&art4);
|
||||
|
||||
Artist artist5 = {"Sandro Botticelli", "biog", 17, 5, 1510};
|
||||
Artwork art5 = {"The birth of Venus", "desc", 573, 1458, &artist5, 56, 89, 3.56};
|
||||
slo.addArtwork(&art5);
|
||||
|
||||
Artwork *painting1 = new Painting{"itoao", "desc", 1598, 789, &artist3, 43, 4, 7, PaintingTechnique::Oil};
|
||||
slo.addArtwork(painting1);
|
||||
|
||||
Artwork *painting2 = new Painting{"ito", "de", 1598, 789, &artist3, 43, 4, 7, PaintingTechnique::Acrylic};
|
||||
slo.addArtwork(painting2);
|
||||
|
||||
Artwork *Liter = new Literature("liter", "description", 597, 1590, &artist2, 56, 86, 15, LiteratureType::Biography);
|
||||
slo.addArtwork(Liter);
|
||||
|
||||
slo.printArtworks();
|
||||
//std::cout << slo.toString();
|
||||
std::cout << "--------------Sort-----------------\n";
|
||||
|
||||
slo.sort(ascendingPrice);
|
||||
slo.printArtworks();
|
||||
|
||||
std::cout << "--------------is cheper-----------------\n";
|
||||
|
||||
std::vector<Artwork *> returned;
|
||||
returned = slo.filteredVector(isCheperThen);
|
||||
for (int i = 0; i < returned.size(); ++i) {
|
||||
std::cout << returned[i]->toString();
|
||||
}
|
||||
|
||||
|
||||
std::cout << "------------FindRenaissance-------------------\n";
|
||||
if (slo.find(isRenaissanceArt))
|
||||
std::cout << slo.find(isRenaissanceArt);
|
||||
|
||||
std::cout << "------------Print paint-------------------\n";
|
||||
PrintIfPainting paint;
|
||||
slo.printArtworks(paint);
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user