consolidate all repos to one for archive
This commit is contained in:
31
semester_2/programiranje_2/Prirava_1/Article.cpp
Normal file
31
semester_2/programiranje_2/Prirava_1/Article.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Created by Nik on 07/04/2022.
|
||||
//
|
||||
|
||||
#include "Article.h"
|
||||
|
||||
Article::Article(std::string name, std::string barcode, double price) : name(name), barcode(barcode), price(price), quantity(1) {}
|
||||
|
||||
bool Article::hasSameCode(Article *a) const {
|
||||
return (barcode == a->barcode);
|
||||
}
|
||||
|
||||
double Article::getTotalPrice() const{
|
||||
return price * quantity;
|
||||
}
|
||||
|
||||
std::string Article::toSting() const{
|
||||
return name + " " + std::to_string(quantity) + " " + std::to_string(getTotalPrice()) + " E";
|
||||
}
|
||||
|
||||
void Article::increseQuantity() {
|
||||
quantity += 1;
|
||||
}
|
||||
|
||||
void Article::setQuantity(double q) {
|
||||
quantity = q;
|
||||
}
|
||||
|
||||
void Article::setPrice(double p) {
|
||||
price = p;
|
||||
}
|
23
semester_2/programiranje_2/Prirava_1/Article.h
Normal file
23
semester_2/programiranje_2/Prirava_1/Article.h
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Created by Nik on 07/04/2022.
|
||||
//
|
||||
#ifndef PRIRAVA_1_ARTICLE_H
|
||||
#define PRIRAVA_1_ARTICLE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class Article {
|
||||
protected:
|
||||
std::string name, barcode;
|
||||
double price, quantity;
|
||||
public:
|
||||
Article(std::string name, std::string barcode, double price);
|
||||
bool hasSameCode(Article* a) const;
|
||||
double getTotalPrice() const;
|
||||
virtual std::string toSting() const;
|
||||
void increseQuantity();
|
||||
void setQuantity(double q);
|
||||
void setPrice(double p);
|
||||
};
|
||||
|
||||
#endif //PRIRAVA_1_ARTICLE_H
|
38
semester_2/programiranje_2/Prirava_1/Invoice.cpp
Normal file
38
semester_2/programiranje_2/Prirava_1/Invoice.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// Created by Nik on 07/04/2022.
|
||||
//
|
||||
|
||||
#include "Invoice.h"
|
||||
|
||||
//int Invoice::countId = 0;
|
||||
|
||||
Invoice::Invoice(std::string seller) : seller(seller){
|
||||
countId += 1;
|
||||
id = countId;
|
||||
}
|
||||
|
||||
Invoice::~Invoice() {
|
||||
countId -= 1;
|
||||
}
|
||||
|
||||
void Invoice::addArticle(Article *a) {
|
||||
for(int i = 0; i < articels.size(); i++){
|
||||
if(articels[i]->hasSameCode(a)){
|
||||
articels[i]->increseQuantity();
|
||||
return;
|
||||
}
|
||||
}
|
||||
articels.push_back(a);
|
||||
}
|
||||
|
||||
void Invoice::print() const {
|
||||
double skupaj = 0.0;
|
||||
std::cout << seller << " " << std::to_string(id) << "\n";
|
||||
for(int i = 0; i < articels.size(); i++){
|
||||
std::cout << articels[i]->toSting() << "\n";
|
||||
skupaj += articels[i]->getTotalPrice();
|
||||
}
|
||||
std::cout << "skupna cena " << std::to_string(skupaj) << " E \n\n";
|
||||
}
|
||||
|
||||
|
27
semester_2/programiranje_2/Prirava_1/Invoice.h
Normal file
27
semester_2/programiranje_2/Prirava_1/Invoice.h
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by Nik on 07/04/2022.
|
||||
//
|
||||
|
||||
#ifndef PRIRAVA_1_INVOICE_H
|
||||
#define PRIRAVA_1_INVOICE_H
|
||||
|
||||
#include "Article.h"
|
||||
#include "WeighableArticle.h"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
class Invoice {
|
||||
private:
|
||||
std::string seller;
|
||||
int id;
|
||||
static int countId;
|
||||
std::vector<Article*> articels;
|
||||
public:
|
||||
Invoice(std::string seller);
|
||||
~Invoice();
|
||||
void addArticle(Article* a);
|
||||
void print() const;
|
||||
};
|
||||
|
||||
|
||||
#endif //PRIRAVA_1_INVOICE_H
|
13
semester_2/programiranje_2/Prirava_1/WeighableArticle.cpp
Normal file
13
semester_2/programiranje_2/Prirava_1/WeighableArticle.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// Created by Nik on 07/04/2022.
|
||||
//
|
||||
|
||||
#include "WeighableArticle.h"
|
||||
|
||||
WeighableArticle::WeighableArticle(std::string name, std::string barcode, double price, double quantity) : Article(name, barcode, price) {
|
||||
this->quantity = quantity;
|
||||
}
|
||||
|
||||
std::string WeighableArticle::toString() {
|
||||
return name + " " + std::to_string(quantity) + " " + std::to_string(getTotalPrice()) + " E \n";
|
||||
}
|
18
semester_2/programiranje_2/Prirava_1/WeighableArticle.h
Normal file
18
semester_2/programiranje_2/Prirava_1/WeighableArticle.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by Nik on 07/04/2022.
|
||||
//
|
||||
|
||||
#ifndef PRIRAVA_1_WEIGHABLEARTICLE_H
|
||||
#define PRIRAVA_1_WEIGHABLEARTICLE_H
|
||||
|
||||
#include "Article.h"
|
||||
|
||||
class WeighableArticle : public Article{
|
||||
private:
|
||||
public:
|
||||
WeighableArticle(std::string name, std::string barcode, double price, double quantity);
|
||||
std::string toString();
|
||||
};
|
||||
|
||||
|
||||
#endif //PRIRAVA_1_WEIGHABLEARTICLE_H
|
18
semester_2/programiranje_2/Prirava_1/main.cpp
Normal file
18
semester_2/programiranje_2/Prirava_1/main.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "Invoice.h"
|
||||
|
||||
int main() {
|
||||
Article *artikel1 = new Article("Habotov tic", "1223", 25.69);
|
||||
Article *artikel2 = new WeighableArticle("Golobov tic", "2233", 2.33, 0.9);
|
||||
Invoice *racun1 = new Invoice("Tici d.o.o");
|
||||
artikel1->setQuantity(7);
|
||||
racun1->addArticle(artikel1);
|
||||
racun1->addArticle(artikel2);
|
||||
racun1->print();
|
||||
Article *artikel3 = new Article("Ficotov tic", "1223", 50000.12);
|
||||
Article *artikel4 = new WeighableArticle("rajzmanov tic", "2234", 98.8, 15);
|
||||
Invoice *racun2 = new Invoice("Novi Tici d.o.o");
|
||||
racun2->addArticle(artikel3);
|
||||
racun2->addArticle(artikel4);
|
||||
racun2->print();
|
||||
return 0;
|
||||
}
|
23
semester_2/programiranje_2/Prirava_2/Message.h
Normal file
23
semester_2/programiranje_2/Prirava_2/Message.h
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Created by Nik on 09/06/2022.
|
||||
//
|
||||
|
||||
#ifndef PRIRAVA_2_MESSAGE_H
|
||||
#define PRIRAVA_2_MESSAGE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class Message{
|
||||
protected:
|
||||
int time;
|
||||
std::string text;
|
||||
public:
|
||||
Message(int time, std::string text): text(text) {
|
||||
if (time < 1 or time > 90) throw WrongTimeException();
|
||||
};
|
||||
virtual std::string toString() const{
|
||||
return std::to_string(time) + text + "\n";
|
||||
};
|
||||
};
|
||||
|
||||
#endif //PRIRAVA_2_MESSAGE_H
|
22
semester_2/programiranje_2/Prirava_2/Player.h
Normal file
22
semester_2/programiranje_2/Prirava_2/Player.h
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by Nik on 09/06/2022.
|
||||
//
|
||||
|
||||
#ifndef PRIRAVA_2_PLAYER_H
|
||||
#define PRIRAVA_2_PLAYER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class Player {
|
||||
private:
|
||||
std::string name;
|
||||
int number;
|
||||
public:
|
||||
Player(std::string name, int number) : name(name), number(number){} ;
|
||||
std::string toString(){
|
||||
return "Player: " + name + " " + std::to_string(number) + "\n";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#endif //PRIRAVA_2_PLAYER_H
|
6
semester_2/programiranje_2/Prirava_2/main.cpp
Normal file
6
semester_2/programiranje_2/Prirava_2/main.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello, World!" << std::endl;
|
||||
return 0;
|
||||
}
|
1
semester_2/programiranje_2/README.md
Normal file
1
semester_2/programiranje_2/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# Programiranje_2
|
25
semester_2/programiranje_2/naloga0101/README.md
Normal file
25
semester_2/programiranje_2/naloga0101/README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
Napisali boste program, ki bo omogočal vnos poljubnega števila. Program bo moral izračunati vsoto vseh cifer v podanem številu in preveriti ali je vsota popolno število.
|
||||
|
||||
Kaj je popolno število? Popolno število je v matematiki pozitivno celo število n, za katerega je vsota pozitivnih pravih deliteljev enaka številu n. Več o popolnem številu.
|
||||
https://en.wikipedia.org/wiki/Perfect_number
|
||||
Zahteve programa:
|
||||
|
||||
Napišite program, ki od uporabnika zahteva število tako dolgo, dokler podano število ni pozitivno ( uporabite do while zanko).
|
||||
|
||||
Izračunajte in izpišite vsoto cifer v podanem številu.
|
||||
|
||||
Na koncu preverite in izpišite ali je vsota števil popolno število.
|
||||
|
||||
Primer programa:
|
||||
|
||||
> Vnesite stevilo:-50
|
||||
> Vnesite stevilo:-29
|
||||
> Vnesite stevilo:10325
|
||||
> Vsota cifer v stevilu je 11
|
||||
> Stevilo 11 ni popolno stevilo
|
||||
|
||||
Kako preverimo ali je število popolno?
|
||||
|
||||
Primer 1: Število 11 ni popolno, ker je njeni edini pravi delitelj 1. Vsota je torej 1, kar ni enako številu samemu.
|
||||
|
||||
Primer 2: Število 28 je popolno, ker so njeni pravi delitelji 1, 2, 4, 7, 14. Vsota številj je 28, kar je enako številu samemu.
|
43
semester_2/programiranje_2/naloga0101/naloga0101.cpp
Normal file
43
semester_2/programiranje_2/naloga0101/naloga0101.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int add(int number) {
|
||||
int sum = 0;
|
||||
while (number > 0) {
|
||||
sum = sum + number % 10;
|
||||
number = number / 10;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
void perfect_number(int number) {
|
||||
int sum = 0;
|
||||
for (int i = 1; i < number; i++) {
|
||||
if (number % i == 0) {
|
||||
sum = sum + i;
|
||||
}
|
||||
}
|
||||
if (sum == number) {
|
||||
cout << number << " is a perfect number";
|
||||
} else {
|
||||
cout << number << " is not a perfect number";
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int input_number;
|
||||
for (;;) {
|
||||
cout << "Input number: ";
|
||||
cin >> input_number;
|
||||
if (input_number > 0) break;
|
||||
}
|
||||
|
||||
int sum = add(input_number);
|
||||
cout << "Sum is " << sum << endl;
|
||||
perfect_number(sum);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// namesto while use for
|
19
semester_2/programiranje_2/naloga0102/README.md
Normal file
19
semester_2/programiranje_2/naloga0102/README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
1.Preučite in uporabite zgled.(zgled.cpp)
|
||||
|
||||
2.Spremenite program tako, da se v polje vnese 30 naključnih na eno decimalno mesto natančnih števil med 0,5 in 3,5. Vrednosti predstavljajo količino popite vode (v litrih) na dan.
|
||||
|
||||
3.Dopolnite program z izpisom povprečne količine popite vode.
|
||||
|
||||
4.Dopolnite program z izpisom števila dni, ko je bila količina popite vode pod povprečjem.
|
||||
|
||||
5.Dopolnite program z izpisom največje popite količine vode.
|
||||
|
||||
6.Izpišite število dni, ko je bila popita količina vode v mejah priporočenih količin, in sicer med 2 in 2,5 litra.
|
||||
|
||||
|
||||
Končana naloga mora imeti v meniju 6 izbir + izbira za izhod iz programa.
|
||||
|
||||
Pomoč pri generiranju naključnih števil:
|
||||
|
||||
https://en.cppreference.com/w/cpp/numeric/random/rand
|
||||
https://en.cppreference.com/w/cpp/numeric/random/random_device
|
146
semester_2/programiranje_2/naloga0102/naloga0102.cpp
Normal file
146
semester_2/programiranje_2/naloga0102/naloga0102.cpp
Normal file
@@ -0,0 +1,146 @@
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void menu() {
|
||||
cout << "============================" << endl;
|
||||
cout << "=========== MENU ===========" << endl;
|
||||
cout << "============================" << endl;
|
||||
cout << "1 ... GENERATE WATER INTAKES" << endl;
|
||||
cout << "2 ... PRINT WATER INTAKES" << endl;
|
||||
cout << "3 ... AVERAGE" << endl;
|
||||
cout << "4 ... DAYS UNDER AVERAGE" << endl;
|
||||
cout << "5 ... THE MOST WATER" << endl;
|
||||
cout << "6 ... IN LIMIT" << endl;
|
||||
cout << "7 ... ALL THE WATER" << endl;
|
||||
cout << "0 ... EXIT" << endl;
|
||||
cout << "============================" << endl;
|
||||
cout << "Select: ";
|
||||
}
|
||||
|
||||
float map(float value, float start1, float stop1, float start2, float stop2) {
|
||||
return start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
|
||||
}
|
||||
|
||||
void fillArray(float *array, const unsigned int size) {
|
||||
float rand_number;
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
rand_number = map(rand(), 0, RAND_MAX, 0.5, 3.5);
|
||||
rand_number = round(10 * rand_number) / 10;
|
||||
array[i] = rand_number;
|
||||
}
|
||||
}
|
||||
|
||||
void printArray(const float *array, const unsigned int size) {
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
cout << "Day: " << i << " --> " << array[i] << "L\n";
|
||||
}
|
||||
}
|
||||
|
||||
float sum(const float *array, const unsigned int size) {
|
||||
float liters = 0;
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
liters += array[i];
|
||||
}
|
||||
return liters;
|
||||
}
|
||||
|
||||
float average(const float *array, const unsigned int size) {
|
||||
float liters = sum(array, size);
|
||||
liters = liters / size;
|
||||
liters = round(10 * liters) / 10;
|
||||
return liters;
|
||||
}
|
||||
|
||||
void under_average(const float *array, const unsigned int size) {
|
||||
float avg = average(array, size);
|
||||
unsigned int dni = 0;
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
if (avg > array[i]) {
|
||||
cout << "Day: " << i << " --> " << array[i] << "L\n";
|
||||
dni++;
|
||||
}
|
||||
}
|
||||
cout << dni << " days are under average \n";
|
||||
}
|
||||
|
||||
void max_day(const float *array, const unsigned int size) {
|
||||
float max_drank = array[0];
|
||||
unsigned int day;
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
if (max_drank < array[i]) {
|
||||
max_drank = array[i];
|
||||
day = i;
|
||||
}
|
||||
}
|
||||
cout << "On day " << day << " you drank the most water " << max_drank << "L";
|
||||
}
|
||||
|
||||
void in_limit(const float *array, const unsigned int size) {
|
||||
unsigned int day = 0;
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
if (2.0 <= array[i] && array[i] <= 2.5) {
|
||||
cout << "Day: " << i << " --> " << array[i] << "L\n";
|
||||
day++;
|
||||
}
|
||||
}
|
||||
cout << day << endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
const unsigned int days = 30;
|
||||
float *waterIntakes = new float[days];
|
||||
float tmp;
|
||||
srand(time(nullptr));
|
||||
|
||||
fillArray(waterIntakes, days);
|
||||
|
||||
bool running = true;
|
||||
int selection;
|
||||
|
||||
do {
|
||||
menu();
|
||||
cin >> selection;
|
||||
cout << endl;
|
||||
switch (selection) {
|
||||
case 1:
|
||||
fillArray(waterIntakes, days);
|
||||
break;
|
||||
case 2:
|
||||
printArray(waterIntakes, days);
|
||||
break;
|
||||
case 3:
|
||||
tmp = average(waterIntakes, days);
|
||||
cout << "On average you drank " << tmp << "L a day";
|
||||
break;
|
||||
case 4:
|
||||
under_average(waterIntakes, days);
|
||||
break;
|
||||
case 5:
|
||||
max_day(waterIntakes, days);
|
||||
break;
|
||||
case 6:
|
||||
in_limit(waterIntakes, days);
|
||||
break;
|
||||
case 7:
|
||||
tmp = sum(waterIntakes, days);
|
||||
cout << "Vsa voda popita" << tmp;
|
||||
break;
|
||||
case 0:
|
||||
running = false;
|
||||
break;
|
||||
default:
|
||||
cout << "Wrong selection!" << endl;
|
||||
break;
|
||||
}
|
||||
cout << endl;
|
||||
} while (running);
|
||||
|
||||
delete[] waterIntakes;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// izpis celotne kolicine vode
|
61
semester_2/programiranje_2/naloga0102/zgled.cpp
Normal file
61
semester_2/programiranje_2/naloga0102/zgled.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void menu() {
|
||||
cout << "============================" << endl;
|
||||
cout << "=========== MENU ===========" << endl;
|
||||
cout << "============================" << endl;
|
||||
cout << "1 ... GENERATE WATER INTAKES" << endl;
|
||||
cout << "2 ... PRINT WATER INTAKES" << endl;
|
||||
cout << "0 ... EXIT" << endl;
|
||||
cout << "============================" << endl;
|
||||
cout << "Select: ";
|
||||
}
|
||||
|
||||
void fillArray(float* array, const unsigned int size) {
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
array[i] = 0.5f + i * 0.3f;
|
||||
}
|
||||
}
|
||||
|
||||
void printArray(const float* array, const unsigned int size) {
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
cout << ((i > 0) ? ", " : "") << array[i];
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
const unsigned int days = 10;
|
||||
float* waterIntakes = new float[days];
|
||||
|
||||
srand(time(nullptr));
|
||||
|
||||
bool running = true;
|
||||
int selection;
|
||||
|
||||
do {
|
||||
menu();
|
||||
cin >> selection;
|
||||
switch (selection) {
|
||||
case 1:
|
||||
fillArray(waterIntakes, days);
|
||||
break;
|
||||
case 2:
|
||||
printArray(waterIntakes, days);
|
||||
break;
|
||||
case 0:
|
||||
running = false;
|
||||
break;
|
||||
default:
|
||||
cout << "Wrong selection!" << endl;
|
||||
break;
|
||||
}
|
||||
cout << endl;
|
||||
} while (running);
|
||||
|
||||
delete[] waterIntakes;
|
||||
|
||||
return 0;
|
||||
}
|
39
semester_2/programiranje_2/naloga0201/Artwork.cpp
Normal file
39
semester_2/programiranje_2/naloga0201/Artwork.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "Artwork.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
Artwork::Artwork() : author(""), title(""), description(""), price(0), year(0) {}
|
||||
|
||||
Artwork::Artwork(std::string author, std::string title, std::string description, int price, int year) : author(author), title(title), description(description), price(price), year(year) {}
|
||||
|
||||
Artwork::~Artwork() {};
|
||||
|
||||
void Artwork::setAuthor(std::string author) {this->author = author;}
|
||||
|
||||
void Artwork::setTitle(std::string title) {this ->title = title;}
|
||||
|
||||
void Artwork::setDescription(std::string description) {this->description = description;}
|
||||
|
||||
void Artwork::setPrice(int price) {this->price = price;}
|
||||
|
||||
void Artwork::setYear(int year) { this->year = year;}
|
||||
|
||||
std::string Artwork::getAuthor() { return author; }
|
||||
|
||||
std::string Artwork::getTitle() { return title; }
|
||||
|
||||
std::string Artwork::getDescription() { return description; }
|
||||
|
||||
int Artwork::getPrice() { return price; }
|
||||
|
||||
int Artwork::getYear() { return year; }
|
||||
|
||||
std::string Artwork::toString() {
|
||||
return "Author: " + author + "\nTitle: " + title + "\nDescription: " + description + "\nPrice: " +
|
||||
std::to_string(price) + " EUR\nYear: " + std::to_string(year) + "\n\n";
|
||||
}
|
||||
|
||||
void Artwork::print() {
|
||||
std::cout << "Author: " << author << "\nTitle: " << title << "\nDescription: " << description << "\nPrice: "
|
||||
<< price << " EUR\nYear: " << year << "\n\n";
|
||||
}
|
37
semester_2/programiranje_2/naloga0201/Artwork.h
Normal file
37
semester_2/programiranje_2/naloga0201/Artwork.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef NALOGA0201_ARTWORK_H
|
||||
#define NALOGA0201_ARTWORK_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class Artwork {
|
||||
private:
|
||||
std::string author, title, description;
|
||||
int price, year;
|
||||
public:
|
||||
Artwork(); //constructor
|
||||
Artwork(std::string author, std::string title, std::string description, int price, int year);
|
||||
|
||||
~Artwork(); //destructor
|
||||
//Methods
|
||||
|
||||
void setAuthor(std::string);
|
||||
void setTitle(std::string);
|
||||
void setDescription(std::string);
|
||||
void setPrice(int);
|
||||
void setYear(int);
|
||||
|
||||
std::string getAuthor();
|
||||
|
||||
std::string getTitle();
|
||||
|
||||
std::string getDescription();
|
||||
|
||||
int getPrice();
|
||||
int getYear();
|
||||
|
||||
std::string toString();
|
||||
|
||||
void print();
|
||||
};
|
||||
|
||||
#endif //NALOGA0201_ARTWORK_H
|
15
semester_2/programiranje_2/naloga0201/README.md
Normal file
15
semester_2/programiranje_2/naloga0201/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
Preučite primer Point na prosojnicah iz predavanj in po enakem vzoru napišite razred Artwork (zapišite Artwork.h in Artwork.cpp). Vse metode (tudi krajše) implementirajte v datoteki Artwork.cpp.
|
||||
|
||||
Razred Artwork mora imeti naslednje instančne spremenljivke:
|
||||
title,
|
||||
description,
|
||||
price in
|
||||
year.
|
||||
Razred Artwork mora imeti konstruktor s 4 parametri.
|
||||
Napišite javne metode: get (vrne podatek) za vsako lastnost posebej.
|
||||
Napišite javne metode: set (nastavi podatek) pri izbranih lastnostih, kjer je smiselno.
|
||||
Napišite metodo toString(), ki vrne string, ki vsebuje vse podatke o umetnini.
|
||||
Napišite javno metodo print(), ki izpiše vse podatke.
|
||||
V glavnem programu demonstrirajte uporabo konstruktorjev in metod iz razreda Artwork. Ustvarite vsaj 5 objektov, kjer demonstrirate:
|
||||
statično in dinamično alokacijo objektov (razreda Artwork),
|
||||
uporabo vseh metod iz razreda Artwork.
|
52
semester_2/programiranje_2/naloga0201/naloga0201.cpp
Normal file
52
semester_2/programiranje_2/naloga0201/naloga0201.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <iostream>
|
||||
#include "Artwork.h"
|
||||
#include <string>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello, World!" << std::endl;
|
||||
Artwork a("nikola", "nik", "pet", 20, 15);
|
||||
Artwork b;
|
||||
|
||||
std::string name = "lag";
|
||||
std::string tit = "dsla";
|
||||
std::string des = "pet";
|
||||
int pri = 33;
|
||||
int ye = 66;
|
||||
|
||||
b.setAuthor(name);
|
||||
b.setTitle(tit);
|
||||
b.setDescription(des);
|
||||
b.setDescription(des);
|
||||
b.setPrice(pri);
|
||||
b.setYear(ye);
|
||||
|
||||
std::cout << a.toString();
|
||||
b.print();
|
||||
|
||||
Artwork f(a);
|
||||
f.print();
|
||||
Artwork *c = new Artwork;
|
||||
Artwork *d = new Artwork("jan", "andz", "novak", 34, 75);
|
||||
|
||||
c->setAuthor(name);
|
||||
c->setTitle(tit);
|
||||
c->setDescription(des);
|
||||
c->setDescription(des);
|
||||
c->setPrice(pri);
|
||||
c->setYear(ye);
|
||||
|
||||
d->print();
|
||||
std::cout << c->toString();
|
||||
|
||||
std::cout << f.getAuthor() << "\n";
|
||||
std::cout << a.getTitle() << "\n";
|
||||
std::cout << b.getDescription() << "\n";
|
||||
std::cout << c->getPrice() << "\n";
|
||||
std::cout << d->getYear() << "\n";
|
||||
|
||||
delete c;
|
||||
delete d;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//string Avto
|
12
semester_2/programiranje_2/naloga0202/README.md
Normal file
12
semester_2/programiranje_2/naloga0202/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
Vzemite vašo rešitev naloge 1.2.
|
||||
Preučite in uporabite zgled ter predelajte nalogo 1.2 tako, da uporabite (https://en.cppreference.com/w/cpp/numeric/random/random_device) naključnih števil za generiranje objektov popite vode (mesec naj bo 3, leto 2022, dnevi pa od 1 do 30). Namesto polja uporabite (https://en.cppreference.com/w/cpp/container/vector).
|
||||
Napišite razred WaterIntake, ki bo imel naslednje instančne privatne lastnosti:
|
||||
day: unsigned int,
|
||||
month: unsigned int,
|
||||
year: unsigned int,
|
||||
quantity: float.
|
||||
Razred naj vsebuje konstruktor s 4 argumenti.
|
||||
Napišite javne metode: get (vrne podatek) za vsako lastnost posebej in set (nastavi podatek) samo za lastnost quantity.
|
||||
Razredu dodajte metodo toString, ki vrne vse podatke objekta.
|
||||
Razredu dodajte metodo addQuantity, ki prejme realno vrednost, za katero poveča quantity.
|
||||
Preuredite glavni program iz naloge 1.2 tako, da bo vector vseboval kazalce na objekte razreda WaterIntake (zgled.cpp).
|
37
semester_2/programiranje_2/naloga0202/WaterIntake.cpp
Normal file
37
semester_2/programiranje_2/naloga0202/WaterIntake.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "WaterIntake.h"
|
||||
#include <iostream>
|
||||
|
||||
WaterIntake::WaterIntake() : day(0), month(0), year(0), quantity(0.0) {}
|
||||
|
||||
WaterIntake::WaterIntake(unsigned int day, unsigned int month, unsigned int year, float quantity) : day(day), month(month), year(year), quantity(quantity) {
|
||||
}
|
||||
|
||||
WaterIntake::~WaterIntake() {}
|
||||
|
||||
unsigned int WaterIntake::getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
unsigned int WaterIntake::getMonth() {
|
||||
return month;
|
||||
}
|
||||
|
||||
unsigned int WaterIntake::getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
float WaterIntake::getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
std::string WaterIntake::toString() {
|
||||
return "day: " + std::to_string(day) + "\n month: " + std::to_string(month) + "\n year: " + std::to_string(year) + "\n quantity: " + std::to_string(quantity) + "\n";
|
||||
}
|
||||
|
||||
void WaterIntake::addQuantity(float addQuantity) {
|
||||
quantity = quantity + addQuantity;
|
||||
}
|
||||
|
||||
bool WaterIntake::isNormal() {
|
||||
return 2.0 <= quantity && quantity <= 2.5;
|
||||
}
|
33
semester_2/programiranje_2/naloga0202/WaterIntake.h
Normal file
33
semester_2/programiranje_2/naloga0202/WaterIntake.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef NALOGA0102_WATERINTAKE_H
|
||||
#define NALOGA0102_WATERINTAKE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class WaterIntake {
|
||||
private:
|
||||
unsigned int day, month, year;
|
||||
float quantity;
|
||||
public:
|
||||
WaterIntake();
|
||||
|
||||
WaterIntake(unsigned int, unsigned int, unsigned int, float);
|
||||
|
||||
~WaterIntake();
|
||||
|
||||
unsigned int getDay();
|
||||
|
||||
unsigned int getMonth();
|
||||
|
||||
unsigned int getYear();
|
||||
|
||||
float getQuantity();
|
||||
|
||||
std::string toString();
|
||||
|
||||
void addQuantity(float);
|
||||
|
||||
bool isNormal();
|
||||
|
||||
};
|
||||
|
||||
#endif //NALOGA0102_WATERINTAKE_H
|
140
semester_2/programiranje_2/naloga0202/naloga0202.cpp
Normal file
140
semester_2/programiranje_2/naloga0202/naloga0202.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
#include "WaterIntake.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void menu() {
|
||||
cout << "============================" << endl;
|
||||
cout << "=========== MENU ===========" << endl;
|
||||
cout << "============================" << endl;
|
||||
cout << "1 ... GENERATE WATER INTAKES" << endl;
|
||||
cout << "2 ... PRINT WATER INTAKES" << endl;
|
||||
cout << "3 ... AVERAGE" << endl;
|
||||
cout << "4 ... DAYS UNDER AVERAGE" << endl;
|
||||
cout << "5 ... THE MOST WATER" << endl;
|
||||
cout << "6 ... IN LIMIT" << endl;
|
||||
cout << "7 ... ALL THE WATER" << endl;
|
||||
cout << "0 ... EXIT" << endl;
|
||||
cout << "============================" << endl;
|
||||
cout << "Select: ";
|
||||
}
|
||||
|
||||
void fillArray(vector<WaterIntake*> &waterIntakes, const unsigned int size) {
|
||||
float randNumber;
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
randNumber = (rand() / (RAND_MAX + 0.0)) * 3 + 0.5;
|
||||
randNumber = round(10 * randNumber) / 10;
|
||||
waterIntakes.push_back(new WaterIntake(i,2,2022,randNumber));
|
||||
}
|
||||
}
|
||||
|
||||
void printArray(const vector<WaterIntake*> &waterIntakes) {
|
||||
for (unsigned int i = 0; i < waterIntakes.size(); i++)
|
||||
cout << waterIntakes[i]->toString() << std::endl;
|
||||
}
|
||||
|
||||
float sum(const vector<WaterIntake*> &waterIntakes) {
|
||||
float liters = 0;
|
||||
for (unsigned int i = 0; i < waterIntakes.size(); i++) {
|
||||
liters += waterIntakes[i]->getQuantity();
|
||||
}
|
||||
return liters;
|
||||
}
|
||||
|
||||
float average(const vector<WaterIntake*> &waterIntakes) {
|
||||
float liters = sum(waterIntakes);
|
||||
liters = liters / waterIntakes.size();
|
||||
liters = round(10 * liters) / 10;
|
||||
return liters;
|
||||
}
|
||||
|
||||
void under_average(const vector<WaterIntake*> &waterIntakes) {
|
||||
float avg = average(waterIntakes);
|
||||
unsigned int dni = 0;
|
||||
for (unsigned int i = 0; i < waterIntakes.size(); i++) {
|
||||
if (avg > waterIntakes[i]->getQuantity()) {
|
||||
cout << waterIntakes[i]->toString();
|
||||
dni++;
|
||||
}
|
||||
}
|
||||
cout << dni << " days are under average \n";
|
||||
}
|
||||
|
||||
void max_day(const vector<WaterIntake*> &waterIntakes) {
|
||||
float max_drank = waterIntakes[0]->getQuantity();
|
||||
unsigned int day;
|
||||
for (unsigned int i = 0; i < waterIntakes.size(); i++) {
|
||||
if (max_drank < waterIntakes[i]->getQuantity()) {;
|
||||
day = i;
|
||||
}
|
||||
}
|
||||
cout << "On day \n" << waterIntakes[day]->toString();
|
||||
}
|
||||
|
||||
void in_limit(const vector<WaterIntake*> &waterIntakes) {
|
||||
unsigned int day = 0;
|
||||
for (unsigned int i = 0; i < waterIntakes.size(); i++) {
|
||||
if (waterIntakes[i]->isNormal()) {
|
||||
cout << waterIntakes[i]->toString();
|
||||
day++;
|
||||
}
|
||||
}
|
||||
cout << day << endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
const unsigned int days = 30;
|
||||
vector<WaterIntake*> waterIntakes;
|
||||
float tmp;
|
||||
srand(time(nullptr));
|
||||
|
||||
fillArray(waterIntakes, days);
|
||||
|
||||
bool running = true;
|
||||
int selection;
|
||||
|
||||
do {
|
||||
menu();
|
||||
cin >> selection;
|
||||
cout << endl;
|
||||
switch (selection) {
|
||||
case 1:
|
||||
fillArray(waterIntakes, days);
|
||||
break;
|
||||
case 2:
|
||||
printArray(waterIntakes);
|
||||
break;
|
||||
case 3:
|
||||
tmp = average(waterIntakes);
|
||||
cout << "On average you drank " << tmp << "L a day";
|
||||
break;
|
||||
case 4:
|
||||
under_average(waterIntakes);
|
||||
break;
|
||||
case 5:
|
||||
max_day(waterIntakes);
|
||||
break;
|
||||
case 6:
|
||||
in_limit(waterIntakes);
|
||||
break;
|
||||
case 7:
|
||||
tmp = sum(waterIntakes);
|
||||
cout << "Vsa voda popita" << tmp;
|
||||
break;
|
||||
case 0:
|
||||
running = false;
|
||||
break;
|
||||
default:
|
||||
cout << "Wrong selection!" << endl;
|
||||
break;
|
||||
}
|
||||
cout << endl;
|
||||
} while (running);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//isNormal bool med
|
59
semester_2/programiranje_2/naloga0202/zgled.cpp
Normal file
59
semester_2/programiranje_2/naloga0202/zgled.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <ctime>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void menu() {
|
||||
cout << "============================" << endl;
|
||||
cout << "=========== MENU ===========" << endl;
|
||||
cout << "============================" << endl;
|
||||
cout << "1 ... GENERATE WATER INTAKES" << endl;
|
||||
cout << "2 ... PRINT WATER INTAKES" << endl;
|
||||
cout << "0 ... EXIT" << endl;
|
||||
cout << "============================" << endl;
|
||||
cout << "Select: ";
|
||||
}
|
||||
|
||||
void fillVector(vector<WaterIntake*> &waterIntakes, const unsigned int size) {
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
waterIntakes.push_back(new WaterIntake(3, 3, 2022, (float)(rand() % 31 + 5)/10.f));
|
||||
}
|
||||
}
|
||||
|
||||
void printVector(const vector<WaterIntake*> &waterIntakes) {
|
||||
for (unsigned int i = 0; i < waterIntakes.size(); i++)
|
||||
cout << waterIntakes[i]->toString() << ((i < waterIntakes.size() - 1) ? ", " : ".") << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
const unsigned int days = 30;
|
||||
vector<WaterIntake*> waterIntakes;
|
||||
|
||||
srand(time(nullptr));
|
||||
|
||||
bool running = true;
|
||||
int selection;
|
||||
|
||||
do {
|
||||
menu();
|
||||
cin >> selection;
|
||||
switch (selection) {
|
||||
case 1:
|
||||
fillVector(waterIntakes, days);
|
||||
break;
|
||||
case 2:
|
||||
printVector(waterIntakes);
|
||||
break;
|
||||
case 0:
|
||||
running = false;
|
||||
break;
|
||||
default:
|
||||
cout << "Wrong selection!" << endl;
|
||||
break;
|
||||
}
|
||||
cout << endl;
|
||||
} while (running);
|
||||
|
||||
return 0;
|
||||
}
|
21
semester_2/programiranje_2/naloga0301/README.md
Normal file
21
semester_2/programiranje_2/naloga0301/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
Napišite razred Time, ki naj ima:
|
||||
privatne instančne spremenljivke:
|
||||
hour,
|
||||
minute in
|
||||
second.
|
||||
razredne spremenljivke:
|
||||
maxHour, ki je konstanta in predstavlja maksimalno vrednost, in sicer 24
|
||||
noonHour, ki je konstanta in predstvalja opoldne, in sicer ima vrednost 12
|
||||
javni konstruktor s 3 parametri (pri tem pazite, da nastavite vrednosti le, če je čas veljaven, sicer nastavite vse vrednosti na 0),
|
||||
javno metodo toString, ki vrne čas kot string, in sicer v formatu hh:mm:ss (npr. 14:05:30),
|
||||
javno metodo toString12HourFormat, ki vrne čas kot string, vendar je čas prilagojen za 12-urni časovni sistem. Torej je potrebno ustrezno spremeniti čas in na koncu dodati še "AM"/"PM". Format pri tem zapisu je hh:mm:ss XM (npr. 18:03:01 --> 06:03:01 PM),
|
||||
javno razredno metodo isTimeValid(unsigned int hour, unsigned int minute, unsigned int second), ki preveri, ali je možen čas glede na podane podatke. Potrebno je upoštevati maksimalne vrednosti, in sicer 23:59:59. Primer: isTimeValid(14, 3, 43) vrne true, isTimeValid(16, 67, 91) vrne false.
|
||||
javno razredno metodo parse(std::string time), ki prejme čas v obiki niza (v formatu hh:mm:ss), razbere posamezne vrednosti in vrne čas tipa Time.
|
||||
|
||||
V glavnem programu prikažite delovanje vseh metod. Ustvarite vsaj 5 različnih objektov razreda Time in na ta način preverite, ali metode pokrivajo vse možne scenarije.
|
||||
|
||||
Ostali napotki pri reševanju naloge:
|
||||
Če potrebujete kako metodo get ali set (za posamezno instančno spremenljivko), si jo zapišite.
|
||||
V nalogi uporabite kazalec this na vseh mestih, kjer je smiselno.
|
||||
V nalogi uporabite določilo const pri vseh metodah, kjer je smiselno.
|
||||
substr: https://cplusplus.com/reference/string/string/substr/
|
62
semester_2/programiranje_2/naloga0301/Time.cpp
Normal file
62
semester_2/programiranje_2/naloga0301/Time.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "Time.h"
|
||||
#include <string>
|
||||
|
||||
Time::Time() : hour(0), minute(0), second(0) {}
|
||||
|
||||
Time::Time(unsigned int hour) : Time(hour, 0, 0) {}
|
||||
|
||||
Time::Time(unsigned int hour, unsigned int minute, unsigned int second) : hour(hour), minute(minute), second(second) {
|
||||
if (hour >= MAX_HOUR || minute >= 60 || second >= 60) {
|
||||
this->hour = 0;
|
||||
this->minute = 0;
|
||||
this->second = 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Time::toString() const {
|
||||
return std::to_string(hour) + ":" + std::to_string(minute) + ":" + std::to_string(second);
|
||||
}
|
||||
|
||||
std::string Time::toString12HourFormat() const {
|
||||
std::string ret;
|
||||
if (hour > NOON_HOUR) ret = std::to_string(hour - 12); //" PM";
|
||||
if (hour == NOON_HOUR) ret = std::to_string(hour); //" PM";
|
||||
if (hour < NOON_HOUR) ret = std::to_string(hour); // " AM";
|
||||
if (hour == 0) ret = std::to_string(12); //AM
|
||||
|
||||
ret = ret + ":" + std::to_string(minute) + ":" + std::to_string(second);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Time::isTimeValid(unsigned int hour, unsigned int minute, unsigned int second) {
|
||||
return !(hour >= MAX_HOUR || minute >= 60 || second >= 60);
|
||||
}
|
||||
|
||||
Time Time::parse(const std::string &time) {
|
||||
unsigned int h = std::stoi(time.substr(0, 2));
|
||||
unsigned int m = std::stoi(time.substr(3, 2));
|
||||
unsigned int s = std::stoi(time.substr(6, 2));
|
||||
return {h, m, s};
|
||||
}
|
||||
|
||||
const Time* Time::maxTime(const Time *time1, const Time *time2) {
|
||||
unsigned int timeSec1 = time1->second + time1->minute * 60 + time1->hour * 3600;
|
||||
unsigned int timeSec2 = time2->second + time2->minute * 60 + time2->hour * 3600;
|
||||
return (timeSec1 > timeSec2) ? time1 : time2;
|
||||
}
|
||||
|
||||
unsigned int Time::getHour() const {
|
||||
return hour;
|
||||
}
|
||||
|
||||
unsigned int Time::getMinute() const {
|
||||
return minute;
|
||||
}
|
||||
|
||||
unsigned int Time::getSecond() const {
|
||||
return second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
39
semester_2/programiranje_2/naloga0301/Time.h
Normal file
39
semester_2/programiranje_2/naloga0301/Time.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef NALOGA0301_TIME_H
|
||||
#define NALOGA0301_TIME_H
|
||||
|
||||
#include <string>
|
||||
|
||||
/*#define MAX_HOUR 24
|
||||
#define NOON_HOUR 12*/
|
||||
|
||||
class Time {
|
||||
private:
|
||||
unsigned int hour, minute, second;
|
||||
public:
|
||||
const static unsigned int MAX_HOUR = 24;
|
||||
const static unsigned int NOON_HOUR = 12;
|
||||
|
||||
Time();
|
||||
|
||||
explicit Time(unsigned int hour);//time(hour,0,0);
|
||||
|
||||
Time(unsigned int hour, unsigned int minute, unsigned int second);
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
std::string toString12HourFormat() const;
|
||||
|
||||
static bool isTimeValid(unsigned int hour, unsigned int minute, unsigned int second);
|
||||
|
||||
static Time parse(const std::string &time);
|
||||
|
||||
static const Time *maxTime(const Time *time1, const Time *time2);
|
||||
|
||||
unsigned int getHour() const;
|
||||
|
||||
unsigned int getMinute() const;
|
||||
|
||||
unsigned int getSecond() const;
|
||||
};
|
||||
|
||||
#endif //NALOGA0301_TIME_H
|
38
semester_2/programiranje_2/naloga0301/naloga0301.cpp
Normal file
38
semester_2/programiranje_2/naloga0301/naloga0301.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include "Time.h"
|
||||
#include <string>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello, World!" << std::endl;
|
||||
Time a;
|
||||
Time b(1, 45, 55);
|
||||
Time c(20);
|
||||
Time e(1, 65, 55);
|
||||
Time f(25);
|
||||
std::cout << a.toString() << "\n";
|
||||
std::cout << b.toString() << "\n";
|
||||
std::cout << c.toString() << "\n";
|
||||
std::cout << e.toString() << "\n";
|
||||
std::cout << f.toString() << "\n\n";
|
||||
|
||||
std::cout << a.toString12HourFormat() << "\n";
|
||||
std::cout << b.toString12HourFormat() << "\n";
|
||||
std::cout << c.toString12HourFormat() << "\n";
|
||||
std::cout << e.toString12HourFormat() << "\n";
|
||||
std::cout << f.toString12HourFormat() << "\n\n";
|
||||
|
||||
std::string tim1 = "01:42:48";
|
||||
a = Time::parse(tim1);
|
||||
tim1 = "01:62:48";
|
||||
e = Time::parse(tim1);
|
||||
std::cout << a.toString() << "\n";
|
||||
std::cout << e.toString() << "\n\n";
|
||||
std::cout << Time::isTimeValid(50, 22, 65)<< "\n";
|
||||
|
||||
const Time *g = new Time(20,56,5);
|
||||
const Time *h = new Time(18,4,6);
|
||||
|
||||
std::cout << Time::maxTime(g,h)->toString();
|
||||
|
||||
return 0;
|
||||
}
|
14
semester_2/programiranje_2/naloga0302/README.md
Normal file
14
semester_2/programiranje_2/naloga0302/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
Napišite razred TextUtility, ki naj ima privatni privzeti konstruktor.
|
||||
|
||||
Razredu dodajte javne razredne metode:
|
||||
|
||||
capitalize(const std::string &str), ki kot argument prejme niz in vrne niz, ki ima za vsakim končnim ločilom (. ,! in ?) veliko začetnico. V primeru, da ugotovimo, da se velika začetnica že nahaja, na tistem mestu ne spremenimo nič. Pazite tudi na to, da je prva črka v nizu z veliko. Primer: lorem ipsum dolor, adipiscing magna? facil isi 2.5 morbi tempus urna id. Gravida non tellus orci! molestieac sed lectus. --> Lorem ipsum dolor, adipiscing magna? Facil isi 2.5 morbi tempus urna id. Gravida non tellus orci! Molestieac sed lectus.
|
||||
toUpperCase(const std::string &str), ki kot argument prejme niz in vrne niz, v katerem so vse črke velike tiskane. Primer: Lorem ipsum dolor 12, adipiscing Magna. --> LOREM IPSUM DOLOR 12, ADIPISCING MAGNA.
|
||||
isNumeric(const std::string &str), ki kot argument prejme niz in preveri, ali se v tem nizu nahajo le števke (0-9) . Primer: "432423" --> true, "4234 234" --> false, "4453asd" --> false
|
||||
contains(const std::string &str, const std::string &substr), ki kot argument prejme niz in iskani niz. Metoda vrne prvi indeks, kje se iskani niz pojavi v nizu. V primeru, da se iskani niz ne nahaja znotraj niza, potem vrnemo -1. Algoritem napišite sami in ni dovoljena uporaba knjižnice. Primer: contains("Lorem ipsum dolor.", "sum") vrne 8, contains("Neobvezna naloga.", "goft") vrne -1
|
||||
|
||||
Razredu dodajte še eno razredno metodo po lastni izbiri (naj bo vezana na tekst)!
|
||||
|
||||
V glavnem programu prikažite delovanje vseh metod. Pri tem pa kličite metode z različnimi argumenti in na ta način preverite, ali metode pokrivajo vse možne scenarije.
|
||||
|
||||
Pomoč za delo z nizi v C++. https://en.cppreference.com/w/cpp/string/basic_string
|
74
semester_2/programiranje_2/naloga0302/TextUtility.cpp
Normal file
74
semester_2/programiranje_2/naloga0302/TextUtility.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include "TextUtility.h"
|
||||
#include <string>
|
||||
#include <cctype>
|
||||
|
||||
std::string TextUtility::capitalize(const std::string &str) {
|
||||
std::string ret;
|
||||
bool nex = false;
|
||||
auto it = str.begin();
|
||||
ret.push_back(std::toupper(*it));
|
||||
it++;
|
||||
while (it != str.end()) {
|
||||
if (nex) {
|
||||
ret.push_back(std::toupper(*it));
|
||||
nex = false;
|
||||
} else {
|
||||
ret.push_back(*it);
|
||||
}
|
||||
if ('.' == *it || '!' == *it || '?' == *it) nex = true;
|
||||
it++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string TextUtility::toUpperCase(const std::string &str) {
|
||||
std::string ret;
|
||||
auto it = str.begin();
|
||||
while (it != str.end()) {
|
||||
ret.push_back(std::toupper(*it));
|
||||
it++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool TextUtility::isNumeric(const std::string &str) {
|
||||
auto it = str.begin();
|
||||
while (it != str.end() && std::isdigit(*it)) ++it;
|
||||
return !str.empty() && it == str.end();
|
||||
}
|
||||
|
||||
int TextUtility::contains(const std::string &str, const std::string &substr) {
|
||||
std::size_t found = str.find(substr);
|
||||
if (found != std::string::npos) return found;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string TextUtility::addSpaces(const std::string &str) {
|
||||
std::string ret;
|
||||
auto it = str.begin();
|
||||
while (it != str.end()) {
|
||||
ret.push_back(*it);
|
||||
ret.push_back(' ');
|
||||
it++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string TextUtility::removeDuplicatedSpaces(const std::string &str) {
|
||||
std::string ret;
|
||||
bool next = false;
|
||||
auto it = str.begin();
|
||||
while (it != str.end()) {
|
||||
if (next) {
|
||||
if(*it != ' ') {
|
||||
ret.push_back(*it);
|
||||
}
|
||||
next = false;
|
||||
} else {
|
||||
ret.push_back(*it);
|
||||
}
|
||||
if (*it == ' ') next = true;
|
||||
it++;
|
||||
}
|
||||
return ret;
|
||||
}
|
24
semester_2/programiranje_2/naloga0302/TextUtility.h
Normal file
24
semester_2/programiranje_2/naloga0302/TextUtility.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef NALOGA0302_TEXTUTILITY_H
|
||||
#define NALOGA0302_TEXTUTILITY_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class TextUtility {
|
||||
private:
|
||||
TextUtility() = default;
|
||||
|
||||
public:
|
||||
static std::string capitalize(const std::string &str);
|
||||
|
||||
static std::string toUpperCase(const std::string &str);
|
||||
|
||||
static bool isNumeric(const std::string &str);
|
||||
|
||||
static int contains(const std::string &str, const std::string &substr);
|
||||
|
||||
static std::string addSpaces(const std::string &str);
|
||||
|
||||
static std::string removeDuplicatedSpaces(const std::string &str);
|
||||
};
|
||||
|
||||
#endif //NALOGA0302_TEXTUTILITY_H
|
19
semester_2/programiranje_2/naloga0302/naloga0302.cpp
Normal file
19
semester_2/programiranje_2/naloga0302/naloga0302.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <iostream>
|
||||
#include "TextUtility.h"
|
||||
|
||||
int main() {
|
||||
std::cout << "capitalize \n";
|
||||
std::cout << "Ni.kola!na: " << TextUtility::capitalize("Ni.kola!na") << "\n";
|
||||
std::cout << "toUpperCase \n";
|
||||
std::cout << "nikola!: " << TextUtility::toUpperCase("nikola!") << "\n";
|
||||
std::cout << "isNumeric \n";
|
||||
std::cout << "59 " << TextUtility::isNumeric("59") << "\n";
|
||||
std::cout << "nik " << TextUtility::isNumeric("nik") << "\n";
|
||||
std::cout << "contains \n";
|
||||
std::cout << "pa in nikola: " << TextUtility::contains("nikola", "pa") << "\n";
|
||||
std::cout << "ol in nikola: " << TextUtility::contains("nikola", "ol") << "\n";
|
||||
std::cout << "addSpaces \n";
|
||||
std::cout << "nikola: " << TextUtility::addSpaces("nikola") << "\n";
|
||||
std::cout << "nikola hi how are you: " << TextUtility::removeDuplicatedSpaces("nikola hi how are you") << "\n";
|
||||
return 0;
|
||||
}
|
7
semester_2/programiranje_2/naloga0401/Artist.cpp
Normal file
7
semester_2/programiranje_2/naloga0401/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/naloga0401/Artist.h
Normal file
20
semester_2/programiranje_2/naloga0401/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
|
13
semester_2/programiranje_2/naloga0401/Artwork.cpp
Normal file
13
semester_2/programiranje_2/naloga0401/Artwork.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#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";
|
||||
}
|
23
semester_2/programiranje_2/naloga0401/Artwork.h
Normal file
23
semester_2/programiranje_2/naloga0401/Artwork.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef NALOGA0201_ARTWORK_H
|
||||
#define NALOGA0201_ARTWORK_H
|
||||
|
||||
#include "Artist.h"
|
||||
#include "Dimension.h"
|
||||
|
||||
class Artwork {
|
||||
private:
|
||||
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);
|
||||
|
||||
~Artwork() = default;
|
||||
|
||||
std::string toString() const;
|
||||
};
|
||||
|
||||
#endif //NALOGA0201_ARTWORK_H
|
7
semester_2/programiranje_2/naloga0401/Date.cpp
Normal file
7
semester_2/programiranje_2/naloga0401/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/naloga0401/Date.h
Normal file
19
semester_2/programiranje_2/naloga0401/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/naloga0401/Dimension.cpp
Normal file
9
semester_2/programiranje_2/naloga0401/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/naloga0401/Dimension.h
Normal file
18
semester_2/programiranje_2/naloga0401/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
|
20
semester_2/programiranje_2/naloga0401/Gallery.cpp
Normal file
20
semester_2/programiranje_2/naloga0401/Gallery.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#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;
|
||||
}
|
26
semester_2/programiranje_2/naloga0401/Gallery.h
Normal file
26
semester_2/programiranje_2/naloga0401/Gallery.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef NALOGA0201_GALLERY_H
|
||||
#define NALOGA0201_GALLERY_H
|
||||
|
||||
#include "Artwork.h"
|
||||
#include <vector>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
#endif //NALOGA0201_GALLERY_H
|
||||
|
19
semester_2/programiranje_2/naloga0401/README.md
Normal file
19
semester_2/programiranje_2/naloga0401/README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
Iz naloge 2.1 vzemite razred Artwork (datoteki Artwork.h in Artwork.cpp).
|
||||
Dodajte razred Date, ki naj ima:
|
||||
instančne spremenljivke day, month in year (vse tipa unsigned int),
|
||||
konstruktor s tremi parametri in
|
||||
metodo toString.
|
||||
Dodajte razred Artist, ki naj ima:
|
||||
instančne spremenljivke name (tipa string), biography (tipa string) in dateOfBirth (tipa Date),
|
||||
konstruktor s tremi parametri in
|
||||
metodo toString.
|
||||
V razredu Artwork dodajte instančno spremenljivko artist(tipa Artist*). Ustrezno popravite konstruktor in metode v razredu Artwork.
|
||||
Dodajte razred Gallery, ki naj ima:
|
||||
instančni spremenljivki name (string) in artworks (vector<Artwork*>).
|
||||
konstruktor z enim parametrom (samo name),
|
||||
metodo void addArtwork(Artwork* artwork), ki kot argument prejme kazalec na objekt tipa Artwork in ga doda v artworks,
|
||||
metodo printArtworks, ki izpiše vse umetnine, ki jih ima galerija,
|
||||
metodo toString.
|
||||
V glavnem programu zapišite oz. sestavite program, ki bo predstavljal eno galerijo z vsaj 5 umetninami.
|
||||
|
||||
Pri reševanju naloge upoštevajte vso dosedaj pridobljeno znanje (uporaba inicializacijskega seznama, konstantne metode, zapišite si metode get/set tam, kjer jih potrebujete itd.).
|
30
semester_2/programiranje_2/naloga0401/naloga0401.cpp
Normal file
30
semester_2/programiranje_2/naloga0401/naloga0401.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <iostream>
|
||||
#include "Gallery.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);
|
||||
|
||||
slo.printArtworks();
|
||||
//std::cout << slo.toString();
|
||||
return 0;
|
||||
}
|
25
semester_2/programiranje_2/naloga0402/Conference.cpp
Normal file
25
semester_2/programiranje_2/naloga0402/Conference.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "Conference.h"
|
||||
|
||||
Conference::Conference(std::string title, unsigned int Sday, unsigned int Smonth, unsigned int Syear, unsigned int Eday, unsigned int Emonth, unsigned int Eyear) :
|
||||
title(title), startDate(Sday, Smonth, Syear), endDate(Eday, Emonth, Eyear) {}
|
||||
|
||||
void Conference::addEvent(const Event &event) {
|
||||
events.push_back(event);
|
||||
}
|
||||
|
||||
std::string Conference::toString() {
|
||||
std::string ret;
|
||||
ret = title + " " + startDate.toString() + " " + endDate.toString() + "\n\n";
|
||||
for (auto &event: events) ret += event.toString() + "\n";
|
||||
return ret;
|
||||
}
|
||||
|
||||
Event Conference::biggestAudience() {
|
||||
Event maxAtendees = events[0];
|
||||
for (auto &event: events) {
|
||||
if (maxAtendees.getNumberOfAttendees() < event.getNumberOfAttendees()) {
|
||||
maxAtendees = event;
|
||||
}
|
||||
}
|
||||
return maxAtendees;
|
||||
}
|
26
semester_2/programiranje_2/naloga0402/Conference.h
Normal file
26
semester_2/programiranje_2/naloga0402/Conference.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef NALOGA0402_CONFERENCE_H
|
||||
#define NALOGA0402_CONFERENCE_H
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
class Conference {
|
||||
private:
|
||||
std::string title;
|
||||
Date startDate, endDate;
|
||||
std::vector<Event> events;
|
||||
public:
|
||||
Conference() = default;
|
||||
|
||||
Conference(std::string title, unsigned int Sday, unsigned int Smonth, unsigned int Syear, unsigned int Eday, unsigned int Emonth, unsigned int Eyear);
|
||||
|
||||
~Conference() = default;
|
||||
|
||||
void addEvent(const Event &event);
|
||||
|
||||
std::string toString();
|
||||
|
||||
Event biggestAudience();
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0402_CONFERENCE_H
|
7
semester_2/programiranje_2/naloga0402/Date.cpp
Normal file
7
semester_2/programiranje_2/naloga0402/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/naloga0402/Date.h
Normal file
19
semester_2/programiranje_2/naloga0402/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
|
21
semester_2/programiranje_2/naloga0402/Event.cpp
Normal file
21
semester_2/programiranje_2/naloga0402/Event.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "Event.h"
|
||||
|
||||
Event::Event(std::string title, std::string description, Person *presentor, unsigned int day, unsigned int month, unsigned int year) :
|
||||
title(title), description(description), presentor(presentor), date(day, month, year) {}
|
||||
|
||||
void Event::addAttendee(Person *person) {
|
||||
attendees.push_back(person);
|
||||
}
|
||||
|
||||
std::string Event::toString() {
|
||||
std::string ret;
|
||||
ret = title + " " + description + " " + presentor->toString() + " " + date.toString() + "\n";
|
||||
for (auto &attendee: attendees) ret += attendee->toString() + "\n";
|
||||
return ret;
|
||||
}
|
||||
|
||||
unsigned int Event::getNumberOfAttendees() {
|
||||
return attendees.size();
|
||||
}
|
||||
|
||||
|
29
semester_2/programiranje_2/naloga0402/Event.h
Normal file
29
semester_2/programiranje_2/naloga0402/Event.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef NALOGA0402_EVENT_H
|
||||
#define NALOGA0402_EVENT_H
|
||||
|
||||
#include "Person.h"
|
||||
#include "Date.h"
|
||||
#include <vector>
|
||||
|
||||
class Event {
|
||||
private:
|
||||
std::string title, description;
|
||||
Person *presentor;
|
||||
Date date;
|
||||
std::vector<Person *> attendees;
|
||||
public:
|
||||
Event() = default;
|
||||
|
||||
Event(std::string title, std::string description, Person *presentor, unsigned int day, unsigned int month, unsigned int year);
|
||||
|
||||
~Event() = default;
|
||||
|
||||
void addAttendee(Person *person);
|
||||
|
||||
std::string toString();
|
||||
|
||||
unsigned int getNumberOfAttendees();
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0402_EVENT_H
|
8
semester_2/programiranje_2/naloga0402/Person.cpp
Normal file
8
semester_2/programiranje_2/naloga0402/Person.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "Person.h"
|
||||
|
||||
Person::Person(std::string firstName, std::string lastName) : firstName(firstName), lastName(lastName) {
|
||||
}
|
||||
|
||||
std::string Person::toString() const {
|
||||
return firstName + " " + lastName;
|
||||
}
|
20
semester_2/programiranje_2/naloga0402/Person.h
Normal file
20
semester_2/programiranje_2/naloga0402/Person.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef NALOGA0402_PERSON_H
|
||||
#define NALOGA0402_PERSON_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class Person {
|
||||
private:
|
||||
std::string firstName, lastName;
|
||||
public:
|
||||
Person() = default;
|
||||
|
||||
Person(std::string firstName, std::string lastName);
|
||||
|
||||
~Person() = default;
|
||||
|
||||
std::string toString() const;
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0402_PERSON_H
|
26
semester_2/programiranje_2/naloga0402/README.md
Normal file
26
semester_2/programiranje_2/naloga0402/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
Zapišite razred Person, ki naj ima:
|
||||
instančni spremenljivki firstName in lastName,
|
||||
konstruktor z dvema parametroma in
|
||||
metodo toString.
|
||||
Zapišite razred Event, ki naj ima:
|
||||
instančne spremenljivke:
|
||||
title (tipa string),
|
||||
description (tipa string),
|
||||
presenter (tipa Person*),
|
||||
date (tipa Date, ta razred ste že zapisali v nalogi 4.1) in
|
||||
attendees (tipa vector<Person*>),
|
||||
konstruktor s 4 parametri (brez attendees),
|
||||
metodo addAttendee(Person* person), ki doda osebo v seznam udeležencev, in
|
||||
metodo toString.
|
||||
Zapišite razred Conference, ki naj ima:
|
||||
instančne spremenljivke:
|
||||
title (string),
|
||||
startDate (Date),
|
||||
endDate (Date) in
|
||||
events (vector<Event>),
|
||||
konstruktor s tremi parametri,
|
||||
metodo addEvent(const Event& event), ki doda dogodek v seznam dogodkov, in
|
||||
metodo toString.
|
||||
V glavnem programu zapišite oz. sestavite program, ki bo imel vsaj eno konferenco z vsaj 3 dogodki. Vsak dogodek naj ima vsaj 3 udeležence.
|
||||
|
||||
Pri reševanju naloge upoštevajte vso do sedaj pridobljeno znanje (uporaba inicializacijskega seznama, konstantne metode, zapišite si metode get/set tam, kjer jih potrebujete itd.).
|
44
semester_2/programiranje_2/naloga0402/naloga0402.cpp
Normal file
44
semester_2/programiranje_2/naloga0402/naloga0402.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <iostream>
|
||||
#include "Conference.h"
|
||||
|
||||
int main() {
|
||||
Person oseba1("nikola", "petrov");
|
||||
Person oseba2("rene", "rozman");
|
||||
Person oseba3("nik", "hazan");
|
||||
Person oseba4("hana", "karolina");
|
||||
|
||||
Event event1("111", "descri", &oseba1, 1,2,2022);
|
||||
event1.addAttendee(&oseba2);
|
||||
event1.addAttendee(&oseba3);
|
||||
event1.addAttendee(&oseba3);
|
||||
event1.addAttendee(&oseba3);
|
||||
event1.addAttendee(&oseba4);
|
||||
|
||||
Event event2("222", "descri", &oseba2, 1,2,2022);
|
||||
event2.addAttendee(&oseba1);
|
||||
event2.addAttendee(&oseba3);
|
||||
event2.addAttendee(&oseba4);
|
||||
|
||||
Event event3("333", "descri", &oseba3,2,2,2022);
|
||||
event3.addAttendee(&oseba2);
|
||||
event3.addAttendee(&oseba1);
|
||||
event3.addAttendee(&oseba4);
|
||||
|
||||
Event event4("444", "descri", &oseba4,2,2,2022);
|
||||
event4.addAttendee(&oseba2);
|
||||
event4.addAttendee(&oseba3);
|
||||
event4.addAttendee(&oseba1);
|
||||
|
||||
Conference confer("conf",1,2,2022,2,2,2022);
|
||||
confer.addEvent(event1);
|
||||
confer.addEvent(event2);
|
||||
confer.addEvent(event3);
|
||||
confer.addEvent(event4);
|
||||
|
||||
|
||||
std::cout << confer.toString();
|
||||
|
||||
std::cout << confer.biggestAudience().toString();
|
||||
|
||||
return 0;
|
||||
}
|
7
semester_2/programiranje_2/naloga0501/Artist.cpp
Normal file
7
semester_2/programiranje_2/naloga0501/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/naloga0501/Artist.h
Normal file
20
semester_2/programiranje_2/naloga0501/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
|
13
semester_2/programiranje_2/naloga0501/Artwork.cpp
Normal file
13
semester_2/programiranje_2/naloga0501/Artwork.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#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";
|
||||
}
|
23
semester_2/programiranje_2/naloga0501/Artwork.h
Normal file
23
semester_2/programiranje_2/naloga0501/Artwork.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#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);
|
||||
|
||||
~Artwork() = default;
|
||||
|
||||
virtual std::string toString() const;
|
||||
};
|
||||
|
||||
#endif //NALOGA0201_ARTWORK_H
|
7
semester_2/programiranje_2/naloga0501/Date.cpp
Normal file
7
semester_2/programiranje_2/naloga0501/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/naloga0501/Date.h
Normal file
19
semester_2/programiranje_2/naloga0501/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/naloga0501/Dimension.cpp
Normal file
9
semester_2/programiranje_2/naloga0501/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/naloga0501/Dimension.h
Normal file
18
semester_2/programiranje_2/naloga0501/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
|
20
semester_2/programiranje_2/naloga0501/Gallery.cpp
Normal file
20
semester_2/programiranje_2/naloga0501/Gallery.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#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;
|
||||
}
|
28
semester_2/programiranje_2/naloga0501/Gallery.h
Normal file
28
semester_2/programiranje_2/naloga0501/Gallery.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef NALOGA0201_GALLERY_H
|
||||
#define NALOGA0201_GALLERY_H
|
||||
|
||||
#include "Artwork.h"
|
||||
#include "Painting.h"
|
||||
#include "Literature.h"
|
||||
#include <vector>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
#endif //NALOGA0201_GALLERY_H
|
||||
|
47
semester_2/programiranje_2/naloga0501/Literature.cpp
Normal file
47
semester_2/programiranje_2/naloga0501/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/naloga0501/Literature.h
Normal file
22
semester_2/programiranje_2/naloga0501/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/naloga0501/Painting.cpp
Normal file
31
semester_2/programiranje_2/naloga0501/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/naloga0501/Painting.h
Normal file
28
semester_2/programiranje_2/naloga0501/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
|
15
semester_2/programiranje_2/naloga0501/README.md
Normal file
15
semester_2/programiranje_2/naloga0501/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
Vzemite nalogo 4.1.
|
||||
Dodajte razed Painting, ki deduje iz razreda Artwork. Nov razred naj ima:
|
||||
dodatno instančno spremenljivko technique tipa PaintingTechnique - dodajte enum class(https://en.cppreference.com/w/cpp/language/enum) PaintingTechnique, ki ima vrednosti Oil, Acrylic in Graphite. enum class PaintingTechnique naj bo napisan nad deklaracijo razreda Painting.
|
||||
konstruktor s 6 parametri,
|
||||
metodo toString in
|
||||
metodo print.
|
||||
V glavnem programu zapišite oz. sestavite program, ki bo predstavljal eno galerijo, ki ima znotraj artworks:
|
||||
2 primerka tipa Artwork in
|
||||
2 primerka tipa Painting.
|
||||
|
||||
Napotki pri reševanju naloge:
|
||||
|
||||
Pazite na uporabo protected, virtual in override.
|
||||
|
||||
Pri reševanju naloge upoštevajte vso dosedaj pridobljeno znanje (uporaba inicializacijskega seznama, konstantne metode, zapišite si metode get/set tam, kjer jih potrebujete itd.). uml_diagram_task0501.png
|
36
semester_2/programiranje_2/naloga0501/naloga0501.cpp
Normal file
36
semester_2/programiranje_2/naloga0501/naloga0501.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <iostream>
|
||||
#include "Gallery.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* Liter = new Literature("liter", "description", 597, 1590, &artist2, 56,86,15,LiteratureType::Biography);
|
||||
slo.addArtwork(Liter);
|
||||
|
||||
slo.printArtworks();
|
||||
//std::cout << slo.toString();
|
||||
return 0;
|
||||
}
|
BIN
semester_2/programiranje_2/naloga0501/uml_diagram_task0501.png
Normal file
BIN
semester_2/programiranje_2/naloga0501/uml_diagram_task0501.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
11
semester_2/programiranje_2/naloga0502/Blinds.cpp
Normal file
11
semester_2/programiranje_2/naloga0502/Blinds.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "Blinds.h"
|
||||
|
||||
Blinds::Blinds(std::string id, std::string name, bool shaded) : Device(id, name), shaded(shaded) {}
|
||||
|
||||
std::string Blinds::isShaded() const {
|
||||
return (shaded) ? "open" : "closed";
|
||||
}
|
||||
|
||||
std::string Blinds::toString() const {
|
||||
return " id: " + id + " name: " + name + " is shaded: " + isShaded() + "\n";
|
||||
}
|
19
semester_2/programiranje_2/naloga0502/Blinds.h
Normal file
19
semester_2/programiranje_2/naloga0502/Blinds.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef NALOGA0502_BLINDS_H
|
||||
#define NALOGA0502_BLINDS_H
|
||||
|
||||
#include "Device.h"
|
||||
|
||||
class Blinds : public Device{
|
||||
private:
|
||||
bool shaded;
|
||||
public:
|
||||
Blinds(std::string id, std::string name, bool shaded);
|
||||
|
||||
std::string isShaded() const;
|
||||
|
||||
std::string toString() const override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0502_BLINDS_H
|
9
semester_2/programiranje_2/naloga0502/Device.cpp
Normal file
9
semester_2/programiranje_2/naloga0502/Device.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "Device.h"
|
||||
|
||||
Device::Device(std::string id, std::string name) : id(id), name(name) {}
|
||||
|
||||
std::string Device::toString() const {
|
||||
return " id: " + id + " name: " + name + "\n";
|
||||
}
|
||||
|
||||
|
16
semester_2/programiranje_2/naloga0502/Device.h
Normal file
16
semester_2/programiranje_2/naloga0502/Device.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef NALOGA0502_DEVICE_H
|
||||
#define NALOGA0502_DEVICE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class Device {
|
||||
protected:
|
||||
std::string id, name;
|
||||
public:
|
||||
Device(std::string id, std::string name);
|
||||
|
||||
virtual std::string toString() const;
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0502_DEVICE_H
|
11
semester_2/programiranje_2/naloga0502/GarageDoor.cpp
Normal file
11
semester_2/programiranje_2/naloga0502/GarageDoor.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "GarageDoor.h"
|
||||
|
||||
GarageDoor::GarageDoor(std::string id, std::string name, bool open) :Device(id, name), open(open){}
|
||||
|
||||
std::string GarageDoor::isOpen() const {
|
||||
return (open) ? "open" : "closed";
|
||||
}
|
||||
|
||||
std::string GarageDoor::toString() const {
|
||||
return " id: " + id + " name: " + name + " is open: " + isOpen() + "\n";
|
||||
}
|
19
semester_2/programiranje_2/naloga0502/GarageDoor.h
Normal file
19
semester_2/programiranje_2/naloga0502/GarageDoor.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef NALOGA0502_GARAGEDOOR_H
|
||||
#define NALOGA0502_GARAGEDOOR_H
|
||||
|
||||
#include "Device.h"
|
||||
|
||||
class GarageDoor: public Device{
|
||||
private:
|
||||
bool open;
|
||||
public:
|
||||
GarageDoor(std::string id, std::string name, bool open);
|
||||
|
||||
std::string isOpen() const;
|
||||
|
||||
std::string toString() const override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0502_GARAGEDOOR_H
|
11
semester_2/programiranje_2/naloga0502/Light.cpp
Normal file
11
semester_2/programiranje_2/naloga0502/Light.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "Light.h"
|
||||
|
||||
Light::Light(std::string id, std::string name, bool turnedOn) : Device(id, name), turnedOn(turnedOn) {}
|
||||
|
||||
std::string Light::isOn() const {
|
||||
return (turnedOn) ? "on" : "off";
|
||||
}
|
||||
|
||||
std::string Light::toString() const {
|
||||
return " id: " + id + " name: " + name + " turnedOn: " + isOn() + "\n";
|
||||
}
|
19
semester_2/programiranje_2/naloga0502/Light.h
Normal file
19
semester_2/programiranje_2/naloga0502/Light.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef NALOGA0502_LIGHT_H
|
||||
#define NALOGA0502_LIGHT_H
|
||||
|
||||
#include "Device.h"
|
||||
|
||||
class Light: public Device{
|
||||
private:
|
||||
bool turnedOn;
|
||||
public:
|
||||
Light(std::string id, std::string name, bool turnedOn);
|
||||
|
||||
std::string isOn() const;
|
||||
|
||||
std::string toString() const override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0502_LIGHT_H
|
30
semester_2/programiranje_2/naloga0502/README.md
Normal file
30
semester_2/programiranje_2/naloga0502/README.md
Normal file
@@ -0,0 +1,30 @@
|
||||
Naslednja naloga predstavlja opis pametnega doma:
|
||||
|
||||
Napišite razred Device, ki ima:
|
||||
instančni spremenljivki id in name (oboje tipa string),
|
||||
konstruktor z 2 parametroma in
|
||||
metodo toString.
|
||||
|
||||
Napišite razred Light, ki deduje iz razreda Device. Nov razred naj ima:
|
||||
dodatno instančno spremenljivko turnedOn (bool),
|
||||
konstruktor s 3 parametri in
|
||||
metodo toString.
|
||||
|
||||
Napišite razred SmartHome, ki ima:
|
||||
instančni spremenljivki name (string) in devices (vector<Device*>),
|
||||
konstruktor z 1 parametrom (samo name),
|
||||
destruktor, ki izbriše objekte iz devices (gre za kompozicijo),
|
||||
metodo addDevice in
|
||||
metodo toString.
|
||||
|
||||
Sami dodajte še 2 smiselna razreda, ki bosta dedovala iz razreda Device.
|
||||
|
||||
V glavnem programu zapišite oz. sestavite program, ki bo predstavljal eno pametno hišo, ki ima znotraj devices nekaj primerkov naprav (Device, Light ...).
|
||||
|
||||
Za nalogo narišite diagram UML. Lahko na list papirja, vendar ga je treba slikati ali skenirati in tudi oddati na eštudij. Lahko pa ustvarite uml diagram s pomočjo https://app.diagrams.net/ ali s podobno aplikacijo.
|
||||
|
||||
Napotki pri reševanju naloge:
|
||||
|
||||
Pazite na uporabo protected, virtual in override.
|
||||
|
||||
Pri reševanju naloge upoštevajte vso dosedaj pridobljeno znanje (uporaba inicializacijskega seznama, konstantne metode, zapišite si metode get/set tam, kjer jih potrebujete itd.).
|
20
semester_2/programiranje_2/naloga0502/SmartHome.cpp
Normal file
20
semester_2/programiranje_2/naloga0502/SmartHome.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "SmartHome.h"
|
||||
|
||||
SmartHome::SmartHome(std::string name) : name(name){}
|
||||
|
||||
SmartHome::~SmartHome(){
|
||||
for (Device* device: devices) {
|
||||
delete device;
|
||||
}
|
||||
}
|
||||
|
||||
std::string SmartHome::toString() const {
|
||||
std::string str;
|
||||
str = "House name: " + name + "\n";
|
||||
for (auto device : devices) str += device->toString();
|
||||
return str;
|
||||
}
|
||||
|
||||
void SmartHome::addDevice(Device *device) {
|
||||
devices.push_back(device);
|
||||
}
|
26
semester_2/programiranje_2/naloga0502/SmartHome.h
Normal file
26
semester_2/programiranje_2/naloga0502/SmartHome.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef NALOGA0502_SMARTHOME_H
|
||||
#define NALOGA0502_SMARTHOME_H
|
||||
|
||||
#include <vector>
|
||||
#include "Device.h"
|
||||
#include "Light.h"
|
||||
#include "Blinds.h"
|
||||
#include "GarageDoor.h"
|
||||
#include "WateringSistem.h"
|
||||
|
||||
class SmartHome {
|
||||
private:
|
||||
std::string name;
|
||||
std::vector<Device*> devices;
|
||||
public:
|
||||
explicit SmartHome(std::string name);
|
||||
|
||||
~SmartHome();
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
void addDevice(Device *device);
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0502_SMARTHOME_H
|
7
semester_2/programiranje_2/naloga0502/WateringSistem.cpp
Normal file
7
semester_2/programiranje_2/naloga0502/WateringSistem.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "WateringSistem.h"
|
||||
|
||||
WateringSistem::WateringSistem(std::string id, std::string name, int startHour, int endHour) : Device(id,name), startHour(startHour), endHour(endHour) {}
|
||||
|
||||
std::string WateringSistem::toString() const {
|
||||
return " id: " + id + " name: " + name + " start hour: " + std::to_string(startHour) + " end hour: " + std::to_string(endHour) + "\n";
|
||||
}
|
16
semester_2/programiranje_2/naloga0502/WateringSistem.h
Normal file
16
semester_2/programiranje_2/naloga0502/WateringSistem.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef NALOGA0502_WATERINGSISTEM_H
|
||||
#define NALOGA0502_WATERINGSISTEM_H
|
||||
|
||||
#include "Device.h"
|
||||
|
||||
class WateringSistem : public Device {
|
||||
private:
|
||||
int startHour, endHour;
|
||||
public:
|
||||
WateringSistem(std::string id, std::string name, int startHour, int endHour);
|
||||
|
||||
std::string toString() const override;
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0502_WATERINGSISTEM_H
|
19
semester_2/programiranje_2/naloga0502/naloga0502.cpp
Normal file
19
semester_2/programiranje_2/naloga0502/naloga0502.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <iostream>
|
||||
#include "SmartHome.h"
|
||||
int main() {
|
||||
SmartHome* nik = new SmartHome("SH");
|
||||
Device* lig = new Light("ha","ja", true);
|
||||
Device* device = new Device("haja", "lada");
|
||||
Device* blind = new Blinds("bli", "ka", true);
|
||||
Device* garage = new GarageDoor("dor", "dore", false);
|
||||
Device* water = new WateringSistem("water", "sistem", 15698,12345);
|
||||
|
||||
nik->addDevice(lig);
|
||||
nik->addDevice(device);
|
||||
nik->addDevice(blind);
|
||||
nik->addDevice(garage);
|
||||
nik->addDevice(water);
|
||||
std::cout << nik->toString();
|
||||
delete nik;
|
||||
return 0;
|
||||
}
|
@@ -0,0 +1 @@
|
||||
<mxfile host="app.diagrams.net" modified="2022-03-28T12:31:55.235Z" agent="5.0 (Windows)" etag="QqLV9jsSKciBJbAK_OLZ" version="17.2.4" type="device"><diagram id="C5RBs43oDa-KdzZeNtuy" name="Page-1">7VpZb+M2EP41BtICNnT6ePSRo9mkza7TJtmXgLZoWY0kein6ykN/eymROknfVhx3awSIOOIhzjfzzQylit71FtcYTMb3yIJuRVOsRUXvVTRNNTStEv4p1pJJGiYX2NixeKdU0HfeIRcqXDp1LBjkOhKEXOJM8sIh8n04JDkZwBjN891GyM2vOgE2FAT9IXBF6ZNjkTGTNrVGKr+Bjj2OV1brLXbHA3FnvpNgDCw0z4j0y4rexQgRduUtutANlRfr5em35ZN791a/vv0a/AB/dr48/v5XlU12tcuQZAsY+mTvqV869zZuf+ncvfYfutjEt8PbH1WVqyEgy1hh0KL6402EyRjZyAfuZSrtYDT1LRhOq9BW2ucOoQkVqlT4NyRkyY0BTAmiojHxXH4XLhzynLl+CaeqmbzVW/CZo8YybvgEL5+jjopixgI2Utf1WJAOjlq50Q8QOx4kECdCqx1aGG1aDvCQbz2OHZ/duHJcl3cLCEZvifGokQRgEg/1kQ9jWWbUlphxbAM0xUO4DihulXQVG5J1HQ3WMYQx4wHcJq4hohrAS9oBQxcQZ5Z3E8C9zU76pRZFL7hR7WBgnCxmwJ3ylXpw5tCtFs0umDueCyJV7qa6GcQELtZuld81m9yTOZXFzXnKC5rCZeMMJyRCmXb4at8odwHfprtJltMa+eVa4nIN2Wp6fjHgUov1AYGd0O0CAZFkn/uDpAsgVTSKgsKguqAO4Pg2m0TrRrBxgQ88+EtFq7v02TsDTK9sEgEoSjoR8fejkRd0DPWRdmaqgjXMxw6B/QmIfGJOI1OeQIDr2NRRey4cEanBrLXFzQazjGPYlhairrOQg/zHkECjcygKKtwGBZ2Ddh7617ZUf7Ms7auiZ/Q9yvM3yDsJg7UamxlM/xkZTJX5SUg5CVwX+5LWP+kUO4wClsXZk/37NUyho6uU+2Yo9OIzIc/EFbb2XnNL41TN0tzXFKyiekoC3F2HMgaU6VAvTYUtQYXMjANBZXRLRK6lIVVLmHV3wo07tDZr8xueY1mspICB8w4G0VRh9jxBjk+ivZiditkL56JVRMAKCjVJyrvIRTjNwUc0/S6IymLiZj1PjWpDRKouZeKSgIonzjHg/6VdYgg71XRoAv3yazoO0OaSjvvg8Uo6PvQh9LLUphuF+kgt5lVsR3xU9qihMFGrodYoqyc/teAqrVrLaKW/QrrA9CGscqxUIfaLjKMotZr/c9OZAH1dpDOjJDr7fq/MXBhMHM9p39xWrxAMXqti5L5cEBhnjycitZTIXrI8tonUcpSmbqSzhLkGLhq+CdS1PwlJFb0tCWmlcBDdKlhmOnBHWUlR9YKd6kbh0HO3/vSCPcG+DLNOpRnbvYs85hRHXoU0xZCdaJiypNwoy7ObgnbCnJxMsQ+tP/wkLx8g5Aoay3vyoTn6WvAOStFlGi1NoXVJ4hcWjJHRbTi8YyKm6wSD45zo1YEXAuIPgkmi/U8OpSToSaE8xnmT9InjAvGswlvTaOQCXE1R6wfm7MeOfOD18fvMhu+LXhtefpt1nx8WN/x12ebIp5cS+cSkeRVVb8i+dw2hxTNEQ10fQov9N4XchtH6+JArOf9bly/egQF0y0vut+SnlcdBydtwvkol+8JZFuZp4dxQGnm1s9a+Rhl3QaNRAA+tw6S7180z5Dptp1x+hHzCn0RVT5Db69sm90enuIOioC5mNCd05iKIWzp3bN6HO3dVqal1Q895t/bpvVssgq4BBjbsIYQFGD+gEiq+yzLiU6nTVUK6+HYxLIXY4eMpa6AEvPMpgvRVLwBTq9ulFAox+K+UQbuj+ZF10LrUPANmx3Vk/C8Qh4Rut+OS1W96THm+/DHEIVWPKqgn5I3w+0RqSSUfoGxQ8Go4PwV3SB9PDFXMq5nN7UIbDIIzIY7jI1kib9Bm+qUtS1LS75X1y38B</diagram></mxfile>
|
23
semester_2/programiranje_2/naloga0601/Canvas.cpp
Normal file
23
semester_2/programiranje_2/naloga0601/Canvas.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Created by Nik on 10/04/2022.
|
||||
//
|
||||
|
||||
#include "Canvas.h"
|
||||
|
||||
void Canvas::addShape(Shape2D *s) {
|
||||
shapes.push_back(s);
|
||||
}
|
||||
|
||||
void Canvas::print() const {
|
||||
for (auto shape: shapes) {
|
||||
shape->draw();
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int Canvas::getTotalArea() const {
|
||||
unsigned int res = 0;
|
||||
for (auto shape: shapes) {
|
||||
res += shape->getSurfaceArea();
|
||||
}
|
||||
return res;
|
||||
}
|
24
semester_2/programiranje_2/naloga0601/Canvas.h
Normal file
24
semester_2/programiranje_2/naloga0601/Canvas.h
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by Nik on 10/04/2022.
|
||||
//
|
||||
|
||||
#ifndef NALOGA0601_CANVAS_H
|
||||
#define NALOGA0601_CANVAS_H
|
||||
|
||||
#include "Shape2D.h"
|
||||
#include "Triangle.h"
|
||||
#include "Rectangle.h"
|
||||
#include "Diamand.h"
|
||||
#include <vector>
|
||||
|
||||
class Canvas {
|
||||
private:
|
||||
std::vector<Shape2D*> shapes;
|
||||
public:
|
||||
void addShape(Shape2D *s);
|
||||
void print() const;
|
||||
unsigned int getTotalArea() const;
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0601_CANVAS_H
|
15
semester_2/programiranje_2/naloga0601/ColorCode.h
Normal file
15
semester_2/programiranje_2/naloga0601/ColorCode.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// Created by Nik on 10/04/2022.
|
||||
//
|
||||
|
||||
#ifndef NALOGA0601_COLORCODE_H
|
||||
#define NALOGA0601_COLORCODE_H
|
||||
|
||||
enum ColorCode{
|
||||
Red = 31,
|
||||
Green = 32,
|
||||
Blue = 34,
|
||||
Default = 39
|
||||
};
|
||||
|
||||
#endif //NALOGA0601_COLORCODE_H
|
66
semester_2/programiranje_2/naloga0601/Diamand.cpp
Normal file
66
semester_2/programiranje_2/naloga0601/Diamand.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// Created by Nik on 11/04/2022.
|
||||
//
|
||||
|
||||
#include "Diamand.h"
|
||||
|
||||
Diamand::Diamand(ColorCode color, unsigned int redius): Shape2D(color), redius(redius) {}
|
||||
|
||||
unsigned int Diamand::getSurfaceArea() const {
|
||||
return (redius*2+2)*2;
|
||||
}
|
||||
|
||||
void Diamand::draw() const {
|
||||
|
||||
int spacL1 = redius;
|
||||
int specR1 = 0;
|
||||
int spacL2 = 0;
|
||||
int specR2 = redius * 2;
|
||||
for (int i = 0; i < redius * 2 + 2; i++) {
|
||||
if (i <= redius) {
|
||||
for (int j = 0; j < spacL1; j++) std::cout << " ";
|
||||
PrintUtility::print(color, "*");
|
||||
for (int k = 0; k < specR1; k++) std::cout << " ";
|
||||
PrintUtility::print(color, "*");
|
||||
std::cout << "\n";
|
||||
specR1 += 2;
|
||||
spacL1 -= 1;
|
||||
}
|
||||
if (i > redius) {
|
||||
for (int j = 0; j < spacL2; j++) std::cout << " ";
|
||||
PrintUtility::print(color, "*");
|
||||
for (int k = 0; k < specR2; k++) std::cout << " ";
|
||||
PrintUtility::print(color, "*");
|
||||
std::cout << "\n";
|
||||
specR2 -= 2;
|
||||
spacL2 += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string Diamand::getString() const {
|
||||
std::string ret;
|
||||
int spacL1 = redius;
|
||||
int specR1 = 0;
|
||||
int spacL2 = 0;
|
||||
int specR2 = redius * 2;
|
||||
for (int i = 0; i < redius * 2 + 2; i++) {
|
||||
if (i <= redius) {
|
||||
for (int j = 0; j < spacL1; j++) ret+=" ";
|
||||
ret+="*";
|
||||
for (int k = 0; k < specR1; k++) ret+=" ";
|
||||
ret+="*\n";
|
||||
specR1 += 2;
|
||||
spacL1 -= 1;
|
||||
}
|
||||
if (i > redius) {
|
||||
for (int j = 0; j < spacL2; j++) ret+=" ";
|
||||
ret+="*";
|
||||
for (int k = 0; k < specR2; k++) ret+=" ";
|
||||
ret+="*\n";
|
||||
specR2 -= 2;
|
||||
spacL2 += 1;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
24
semester_2/programiranje_2/naloga0601/Diamand.h
Normal file
24
semester_2/programiranje_2/naloga0601/Diamand.h
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by Nik on 11/04/2022.
|
||||
//
|
||||
|
||||
#ifndef NALOGA0601_DIAMAND_H
|
||||
#define NALOGA0601_DIAMAND_H
|
||||
|
||||
#include "Shape2D.h"
|
||||
|
||||
class Diamand : public Shape2D{
|
||||
private:
|
||||
unsigned int redius;
|
||||
public:
|
||||
Diamand(ColorCode color, unsigned int redius);
|
||||
|
||||
unsigned int getSurfaceArea() const override;
|
||||
|
||||
void draw() const override;
|
||||
|
||||
std::string getString() const;
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0601_DIAMAND_H
|
14
semester_2/programiranje_2/naloga0601/PrintUtility.cpp
Normal file
14
semester_2/programiranje_2/naloga0601/PrintUtility.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by Dragana on 31. 03. 2022.
|
||||
//
|
||||
|
||||
#include "PrintUtility.h"
|
||||
|
||||
void PrintUtility::print(const ColorCode &color, const std::string& str) {
|
||||
std::cout << "\033[" << (int)color << "m" << str << "\033[0m";
|
||||
}
|
||||
|
||||
void PrintUtility::print(const ColorCode &color, unsigned int n) {
|
||||
for(int i = 0; i < n; i++)
|
||||
print(color, " *");
|
||||
}
|
21
semester_2/programiranje_2/naloga0601/PrintUtility.h
Normal file
21
semester_2/programiranje_2/naloga0601/PrintUtility.h
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Created by Dragana on 31. 03. 2022.
|
||||
//
|
||||
|
||||
#ifndef TASK0601_PRINTUTILITY_H
|
||||
#define TASK0601_PRINTUTILITY_H
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "ColorCode.h"
|
||||
|
||||
class PrintUtility {
|
||||
private:
|
||||
PrintUtility() = default;
|
||||
public:
|
||||
static void print(const ColorCode &color, const std::string& str);
|
||||
static void print(const ColorCode &color, unsigned int n);
|
||||
};
|
||||
|
||||
|
||||
#endif //TASK0601_PRINTUTILITY_H
|
56
semester_2/programiranje_2/naloga0601/README.md
Normal file
56
semester_2/programiranje_2/naloga0601/README.md
Normal file
@@ -0,0 +1,56 @@
|
||||
Napišite enum razred ColorCode, ki ima vrednost:
|
||||
Red = 31,
|
||||
Green = 32,
|
||||
Blue = 34
|
||||
Default = 39
|
||||
|
||||
Priložen imate razed PrintUtility, ki ga vključite v svoj projekt, saj ga boste pri tej nalogi uporabili. Le-ta nam bo omogočil, da izpisujemo lahko barvno besedilo v konzoli. Vendar, da bo to delovalo, je potrebno na začetek funkcije main dodati vrstico:
|
||||
system(("chcp "s + std::to_string(65001)).c_str());.
|
||||
Lahko se zgodi, da v primeru uporabe kakšnega drugega programa (kaj drugega kot CLion) ta funkcionalnost ne bo delala.
|
||||
|
||||
Napišite razred Shape2D, ki ima:
|
||||
instančno spremenljivko color (tip ColorCode),
|
||||
konstruktor z 1 parametrom,
|
||||
abstraktno metodo getSurfaceArea in
|
||||
abstraktno metodo draw.
|
||||
|
||||
Napišite razred Rectangle, ki deduje iz razreda Shape2D in ima:
|
||||
dodatni instančni spremenljivki width in height,
|
||||
konstruktor s 3 parametri,
|
||||
implementirani metodi getSurfaceArea in draw,
|
||||
metodo toString.
|
||||
|
||||
Z metodo getSurfaceArea želimo dobiti vrednost ploščine lika.
|
||||
|
||||
V metodi draw je pričakovano, da izrišemo lik (lahko s pomočjo zvezdic).
|
||||
|
||||
Napišite razred Canvas, ki ima:
|
||||
instančno spremenljivko shapes (tip vector<Shape2D*>),
|
||||
metodo addShape, ki doda lik v shapes, in
|
||||
metodo print, ki izriše vse like.
|
||||
|
||||
Dodajte še sami eni razred, ki bo dedoval iz razreda Shape2D.
|
||||
|
||||
V glavnem programu ustvarite en objekt tipa Canvas in ga napolnite z vsaj 5 liki.
|
||||
|
||||
Za nalogo narišite UML diagram. Lahko na list papirja, vendar ga je treba slikati ali skenirati in tudi oddati na eštudij. Lahko pa ga ustvarite s pomočjo https://app.diagrams.net/ ali s podobno aplikacijo.
|
||||
|
||||
Pri reševanju naloge upoštevajte vso dosedaj pridobljeno znanje (uporaba inicializacijskega seznama, konstantne metode, zapišite si metode get/set tam, kjer jih potrebujete itd.).
|
||||
|
||||
Primer izpisa glavnega programa.
|
||||
|
||||
int main() {
|
||||
system(("chcp "s + std::to_string(65001)).c_str());
|
||||
|
||||
Canvas c;
|
||||
c.addShape(new Rectangle(ColorCode(ColorCode::Green), 5, 2));
|
||||
c.addShape(new Rectangle(ColorCode(ColorCode::Blue), 10, 5));
|
||||
c.print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Uporabi:
|
||||
|
||||
PrintUtility.cpp
|
||||
PrintUtility.h
|
36
semester_2/programiranje_2/naloga0601/Rectangle.cpp
Normal file
36
semester_2/programiranje_2/naloga0601/Rectangle.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// Created by Nik on 10/04/2022.
|
||||
//
|
||||
|
||||
#include "Rectangle.h"
|
||||
#include <cmath>
|
||||
|
||||
Rectangle::Rectangle(ColorCode color, unsigned int width, unsigned int height) :
|
||||
Shape2D(color), width(width), height(height) {}
|
||||
|
||||
Rectangle::Rectangle(ColorCode color, unsigned int size) :
|
||||
Shape2D(color), width(size), height(size) {}
|
||||
|
||||
unsigned int Rectangle::getSurfaceArea() const {
|
||||
return width * height;
|
||||
}
|
||||
|
||||
void Rectangle::draw() const {
|
||||
for (int i = 0; i < height; i++) {
|
||||
PrintUtility::print(color, width);
|
||||
std::cout << "\n";
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
std::string Rectangle::getString() const {
|
||||
std::string ret;
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) ret += " *";
|
||||
ret += "\n";
|
||||
}
|
||||
ret += "\n";
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
24
semester_2/programiranje_2/naloga0601/Rectangle.h
Normal file
24
semester_2/programiranje_2/naloga0601/Rectangle.h
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by Nik on 10/04/2022.
|
||||
//
|
||||
|
||||
#ifndef NALOGA0601_RECTANGLE_H
|
||||
#define NALOGA0601_RECTANGLE_H
|
||||
|
||||
#include "Shape2D.h"
|
||||
|
||||
class Rectangle : public Shape2D{
|
||||
private:
|
||||
unsigned int width, height;
|
||||
public:
|
||||
Rectangle(ColorCode color, unsigned int width, unsigned int height);
|
||||
Rectangle(ColorCode color, unsigned int size);
|
||||
unsigned int getSurfaceArea() const override;
|
||||
void draw() const override;
|
||||
std::string getString() const;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0601_RECTANGLE_H
|
8
semester_2/programiranje_2/naloga0601/Shape2D.cpp
Normal file
8
semester_2/programiranje_2/naloga0601/Shape2D.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// Created by Nik on 10/04/2022.
|
||||
//
|
||||
|
||||
#include "Shape2D.h"
|
||||
|
||||
Shape2D::Shape2D(ColorCode color) : color(color){}
|
||||
|
20
semester_2/programiranje_2/naloga0601/Shape2D.h
Normal file
20
semester_2/programiranje_2/naloga0601/Shape2D.h
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Created by Nik on 10/04/2022.
|
||||
//
|
||||
|
||||
#ifndef NALOGA0601_SHAPE2D_H
|
||||
#define NALOGA0601_SHAPE2D_H
|
||||
|
||||
#include "PrintUtility.h"
|
||||
|
||||
class Shape2D {
|
||||
protected:
|
||||
ColorCode color;
|
||||
public:
|
||||
Shape2D(ColorCode color);
|
||||
virtual unsigned int getSurfaceArea() const = 0;
|
||||
virtual void draw() const = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif //NALOGA0601_SHAPE2D_H
|
40
semester_2/programiranje_2/naloga0601/Triangle.cpp
Normal file
40
semester_2/programiranje_2/naloga0601/Triangle.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// Created by Nik on 10/04/2022.
|
||||
//
|
||||
|
||||
#include "Triangle.h"
|
||||
|
||||
Triangle::Triangle(ColorCode color, unsigned int width) :
|
||||
Shape2D(color), width(width) {}
|
||||
|
||||
unsigned int Triangle::getSurfaceArea() const {
|
||||
unsigned int res = 0;
|
||||
unsigned int rec = 1;
|
||||
for (int i = 0; i < width; i++) {
|
||||
res += rec;
|
||||
rec++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void Triangle::draw() const {
|
||||
unsigned int rec = 1;
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < rec; j++) PrintUtility::print(color," *");
|
||||
rec++;
|
||||
std::cout << "\n";
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
std::string Triangle::getString() const {
|
||||
std::string ret;
|
||||
unsigned int rec = 1;
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < rec; j++) ret += " *";
|
||||
rec++;
|
||||
ret += "\n";
|
||||
}
|
||||
ret += "\n";
|
||||
return ret;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user