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;
|
||||
}
|
Reference in New Issue
Block a user