Skip to content
Snippets Groups Projects
Commit 352c42e7 authored by Tomáš Pachman's avatar Tomáš Pachman
Browse files

edit

parent 674a166c
No related branches found
No related tags found
No related merge requests found
#ifndef RANDDOUBLE_H_HDR
#define RANDDOUBLE_H_HDR
#include <iostream>
class RandDouble{
private:
double val;
public:
RandDouble(){
val=(4.0*rand()/RAND_MAX);
std::cout<<"RandDouble()= "<<val;
std::cout<<std::endl;
}
double getValue(void){
return val;
}
friend std::ostream& operator<<(std::ostream &os, RandDouble &r){
os<<r.getValue();
return os;
}
};
#endif //RANDDOUBLE_H_HDR
\ No newline at end of file
#include <iostream>
#include <vector>
#include <algorithm> // std::generate, etc.
#include <functional> // std::function
int randInt(void)
{
return (rand() % 10) - 5; // generuj cisla od -5 do 4
}
void print_vec(std::vector<int> &v)
{
for(int val : v)
{
std::cout << val << ", ";
}
std::cout << std::endl;
}
int main(void)
{
std::vector<int> v(10), w(10), f(10);
int first, second;
first = 0; second = 1;
std::generate(v.begin(), v.end(), randInt);
std::cout << "v = ";
print_vec(v);
std::generate(w.begin(), w.end(),
[](void) -> int { return (rand() % 20) - 10; });
std::cout << "w = ";
print_vec(w);
// v lambda fci potrebuje cist promenne "first" a "second"
// potrebujeme do nich i zapisovat (proto '&')
std::generate(f.begin(), f.end(),
[&first, &second](void) -> int
{
int ret = first + second;
first = second;
second = ret;
return ret;
} );
std::cout << "f = ";
print_vec(f);
// Priklad pouziti lambda fce
// dtb->query(strSelect, fParamSet, fProcess)
// dtb->query(strSelect, []()-> string { sprintf(); },
// [](dtbrow) -> int { v.push_back(dtbrow); });
std::cout << "Vektor v vzestupne = ";
std::sort(v.begin(), v.end());
print_vec(v);
std::cout << "Vector v sestupne = ";
//std::sort(v.rbegin(), v.rend());
std::sort(v.begin(), v.end(),
[](int& a, int& b) -> bool { return a > b; });
print_vec(v);
// auto fIsPositive
// std::function, typ je sablonou, kompilator vetsinou tipne jake typy se pouzivaji
std::function<bool(int&)> fIsPositive=[](int& value) -> bool { return value > 0; };
std::cout << "Pocet kladnych cisel ve w: ";
std::cout << count_if(w.begin(), w.end(), fIsPositive);
std::cout << std::endl;
return 0;
}
#ifndef STACK_H_HDR
#define STACK_H_HDR
#include <vector>
template<class T>
class Stack{
private:
std::vector<T> v;
public:
Stack(){}
Stack(int size){v.resize(size);}
Stack(std::vector<T> &w){v=w;}
void push(T val){v.push_back(val);}
T pop(void){
T ret = v.back();
v.pop_back();
return ret;
}
};
#endif //*STACK_H_HDR
\ No newline at end of file
#include <iostream>
#include <vector>
#include <algorithm>
#include "stack.h"
#include "RandDouble.h"
//*dva zpusoby zapisu
//template<typename MujTyp>
template<class MujTyp>
MujTyp getMax( MujTyp a, MujTyp b){
return(a>b)?a:b;
}
template<class T>
void print_vec(std::vector<T> &v){
for(T val : v){
std::cout << val << ", ";
}
std::cout << std::endl;
}
int main(){
int a=5, b=-2;
std::cout<<"getMax(" << a<<", "<< b <<") = " << getMax(a,b) << std::endl;
double d=2.7, f= 1.602e-19;
std::cout<<"getMax(" << d<<", "<< f <<") = " << getMax(d,f) << std::endl;
std::cout<<"getMax(" << d<<", "<< a <<") = " << getMax<double>(d,a) << std::endl;
srand(123412);
std::vector<int> u(10);
std::generate(u.begin(), u.end(), [](void)->int{return rand()%20-10;});
print_vec(u);
Stack<int> s(u);
for(int idx=0; idx<10; ++idx){
std::cout<<"s.pop() = "<< s.pop() << std::endl;
}
std::vector<RandDouble> rv(10);
std::sort(rv.begin(), rv.end(), [](RandDouble &a, RandDouble &b)->bool{
return a.getValue()<b.getValue();
});
print_vec(rv);
return 0;
}
\ No newline at end of file
git status -> zjistim jestli jestli jsou zmeny commitnute git status -> zjistim jestli jestli jsou zmeny commitnute
git commit -m "editovaci zprava" -> commitnu zmeny(jenom lokalne) git commit -m "editovaci zprava" -> commitnu zmeny(jenom lokalne)
git push origin main -> upload na server git push origin main -> upload na server
do souboru .gitignore pisu vsechny soubory co chci ignorovat do souboru .gitignore pisu vsechny soubory co chci ignorovat
\ No newline at end of file git add . -> prida vsechnz souboy
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment