consolidate all repos to one for archive

This commit is contained in:
2025-01-28 13:46:42 +01:00
commit a6610fbc7a
5350 changed files with 2705721 additions and 0 deletions

View 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

View 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, " *");
}

View 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

View File

@@ -0,0 +1,6 @@
Dopišite in demonstrirajte naslednje šablone funkcij:
Šablono printColor, ki prejme vektor (uporabite razred PrintUtil iz 6.1), in privzeto izpiše v zeleni barvi. Šablona ima tudi parameter color.
Šablono slice, ki prejme vektor in število n, vrne pa vektor vektorjev, kjer je po n elementov v posameznih vektorjih (razen zadnji lahko ima manj).
Šablono toSafeString, ki prejme vektor objektov in vektor prepovedanih besed (string), vrne pa en string, kjer so vse prepovedane besede zamenjane z ***** (število * mora biti enake dolžine, kot je prepovedana beseda). Uporabite toString nad objekti.
Izmislite si še dve (izvirni) šabloni.

View File

@@ -0,0 +1,11 @@
//
// Created by Nik on 22/04/2022.
//
#include "Racunalnik.h"
Racunalnik::Racunalnik(int poraba, int volumen) : poraba(poraba), volumen(volumen) {}
std::string Racunalnik::toString() const {
return "Poraba: " + std::to_string(poraba) + "W Volumen: " + std::to_string(volumen) + " \n";
}

View File

@@ -0,0 +1,20 @@
//
// Created by Nik on 22/04/2022.
//
#ifndef NALOGA0701_RACUNALNIK_H
#define NALOGA0701_RACUNALNIK_H
#include <string>
class Racunalnik {
private:
int poraba = 600;
int volumen = 7;
public:
Racunalnik() = default;
Racunalnik(int poraba, int volumen);
std::string toString() const;
};
#endif //NALOGA0701_RACUNALNIK_H

View File

@@ -0,0 +1,106 @@
#ifndef NALOGA0702_SABLONE_H
#define NALOGA0702_SABLONE_H
#include "PrintUtility.h"
#include <vector>
#include <sstream>
template<ColorCode C = ColorCode::Green, typename T>
void print(const std::vector<T> vector) {
for (int i = 0; i < vector.size(); ++i) {
PrintUtility::print(C, vector[i].toString());
}
std::cout << "\n";
}
template<ColorCode C = ColorCode::Green>
void print(const std::vector<int> vector) {
for (int i = 0; i < vector.size(); ++i) {
PrintUtility::print(C, std::to_string(vector[i]));
std::cout << " ";
}
std::cout << "\n";
}
template<unsigned int N, typename T>
std::vector<std::vector<T>> slice(std::vector<T> vector) {
std::vector<std::vector<T>> retVec;
std::vector<T> ret;
int count = 0;
for (int i = 0; i < vector.size(); ++i) {
if (count < N) {
ret.push_back(vector[i]);
count++;
}
if (count == N) {
retVec.push_back(ret);
ret.clear();
count = 0;
}
}
retVec.push_back(ret);
return retVec;
}
template<typename T>
std::string toSafeString(std::vector<T> vector, std::vector<T> prepovedano) {
std::string ret;
bool prepoved = false;
for (int i = 0; i < vector.size(); ++i) {
for (int j = 0; j < prepovedano.size(); ++j) {
if (vector[i] == prepovedano[j]) {
prepoved = true;
}
}
if (prepoved) {
for (int k = 0; k < vector[i].length(); k++)
ret += "*";
} else {
ret += vector[i];
}
ret += " ";
prepoved = false;
}
ret += "\n";
return ret;
}
template<typename T>
std::vector<T> reverse(std::vector<T> vector) {
std::vector<T> ret;
for (int i = vector.size() - 1; i >= 0; i--) ret.push_back(vector[i]);
return ret;
}
template<typename T>
double sum(std::vector<T> num) {
double ret = 0;
for (int i = 1; i < num.size(); ++i) ret += num[i];
return ret;
}
template<typename T>
void printSelectedWordInColor(std::vector<T> vector, std::string printColor) {
for (int i = 0; i < vector.size(); ++i) {
std::string str = vector[i].toString();
std::string word;
std::stringstream iss(str);
while (iss >> word) {
if (word == printColor) {
PrintUtility::print(ColorCode::Blue, word + " ");
} else {
std::cout << word << " ";
}
}
std::cout << "\n";
}
}
#endif //NALOGA0702_SABLONE_H
/*
* std::size_t pos = word.find(printColor);
std::string str1 = word.substr (0,pos);
std::string str2 = word.substr(pos,printColor.length());
std::cout << str1 << "||||" << str2 << "\n";
*/

View File

@@ -0,0 +1,48 @@
#include <iostream>
#include "Racunalnik.h"
#include "Sablone.h"
int main() {
system(("chcp " + std::to_string(65001)).c_str());
std::cout << "--------Print color------------------------------------------\n";
std::vector<Racunalnik> rac;
rac.emplace_back();
rac.emplace_back();
print<ColorCode::Red>(rac);
std::cout << "------Vector v vectorju--------------------------------------------\n";
std::vector<int> st;
for (int i = 0; i < 20; ++i) {
st.push_back(rand());
}
print<ColorCode::Blue>(st);
std::vector<std::vector<int>> slic = slice<3>(st);
for (int i = 0; i < slic.size(); ++i) {
print(slic[i]);
}
std::cout << "---------Prepoveadni znaki-----------------------------------------\n";
std::vector<std::string> besede;
std::vector<std::string> prepovedano;
besede.emplace_back("ena");
besede.emplace_back("dva");
besede.emplace_back("tri");
besede.emplace_back("stiri");
besede.emplace_back("pet");
prepovedano.emplace_back("dva");
prepovedano.emplace_back("stiri");
std::cout << toSafeString(besede,prepovedano);
std::cout << "---------Reverse-----------------------------------------\n";
std::vector<int> rev = reverse(st);
print(rev);
std::cout << "---------Sestevanje-----------------------------------------\n";
double num = sum(st);
std::cout << num << "\n";
std::cout << "---------printSelectedWordInColor-----------------------------------------\n";
std::string t = "600W";
printSelectedWordInColor(rac,t);
return 0;
}