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

edit

parent f26d27a6
No related branches found
No related tags found
No related merge requests found
#include <iostream>
#include <map>
//#include <unordered_map>
int main(void){
std::map<std::string, int> D;
D["Tokyo"] = 37833000;
D["Dilli"] = 24953000;
D["Sanghaj"] = 22991000;
D["Maxico City"] = 20843000;
D["Sao Paulo"] = 20831000;
std::cout <<"Zadej mesto: "<<std::endl;
std::string city;
std::cin>>city;
if(D.find(city)==D.end()){
std::cerr<<"takove mesto neznam"<<std::endl;
}
else{
std::cout<<city<<" ma populaci "<<D[city]<<std::endl;
}
std::map<std::string, std::string>mapSQL;
mapSQL["getTemperatureById"] = "SELECT *FROM TEMPERATURE WHERE TEMP_SEND_ID =%id";
mapSQL["getTemperature"] = "SELECT *FROM TEMPERATURE";
return 0;
}
\ No newline at end of file
#include <iostream>
#include <vector>
#include <algorithm> //*pro funkci sort
#include <ctime>
void print_vec_int(std::vector<int> vec){
for(auto it=vec.begin(); it!=vec.end(); ++it){
std::cout<<*it<<", ";
}
std::cout<<std::endl;
}
int main(void){
//*vytvoreni vektoru
std::vector<int> vint;
std::vector<float> vfloat(10);
std::vector<char> vchar = {'a', 'h', 'o', 'j'};
//*rezervovani mista pro 16 prvku
vchar.reserve(16);
std::cout<<"vint.size() = "<<vint.size()<<std::endl;
std::cout<<"vfloat.size() = "<<vfloat.size()<<std::endl;
std::cout<<"vchar.size() = "<<vchar.size()<<" ,vchar.capacity() = "<<vchar.capacity()<<std::endl;
vint.reserve(10);
//*resize vektoru na 10 prvku
vint.resize(10);
for(int idx=0; idx < vint.capacity(); ++ idx){
//std::cout<<vint[idx] << ", ";
try{
vint.at(idx) = idx;
std::cout<<vint.at(idx) << ", ";
}
catch(std::out_of_range e){
std::cout<<"odchyceno out of range:"<<e.what()<<std::endl;
}
catch(const std::exception e){
std::cout<<"odchycena vyjimka:"<<e.what()<<std::endl;
}
catch(...){
std::cout<<"odchycena vyjimka ale nevim jaka"<<std::endl;
}
}
std::cout<<std::endl;
std::cout<< "vfloat = ";
//*for each cyklus
for(float f:vfloat){
std::cout<<f<<", ";
}
std::cout<<std::endl;
std::cout<< "vchar = ";
//*iterator (++it se posune na dalsi prvek)
///iterujeme od zacatku do konce pole
//for(std::vector<char>::iterator it = vchar.begin(); it != vchar.end(); ++it){
//*auto - kompilator si vybere spravny typ
for(auto it = vchar.begin(); it != vchar.end(); ++it){
std::cout<<*it<<", ";
}
std::cout<<std::endl;
//*randomizace vektoru
srand(time(NULL));
for(int idx=0; idx<vint.size(); ++idx){
int temp, randomidx=vint.at(randomidx);
vint.at(idx)=vint.at(randomidx);
vint.at(randomidx)=temp;
}
std::cout<< "vint = ";
print_vec_int(vint);
//*serazeni vektoru
std::sort(vint.begin(), vint.end());
std::cout<< "vint = ";
print_vec_int(vint);
return 0;
}
\ 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