consolidate all repos to one for archive
This commit is contained in:
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
|
Reference in New Issue
Block a user