Zadatak

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

1.

Zadatak output<<"Povrsina je "<<povrsina(obj)<<endl;


output<<"Opseg je "<<opseg(obj)<<endl;
#include <bits/stdc++.h>
}
using namespace std;
static const double pi=3.13;
int main()
class Krug
{
{
Krug a,b,c;
private:
a.setR(10);
double r;
b.setR(5);
public:
c=a+b;
cout << povrsina(c) << endl << opseg(c);
friend double povrsina(Krug &obj);
cout << c;
friend double opseg(Krug &obj);
return 0;
friend ostream &operator<<(ostream &output,
}
Krug &obj);

void setR(double x)
{
this->r=x;
}
double getR()
{
return r;
}
Krug operator+(Krug const &obj)
{
Krug novi;
novi.r=this->r+obj.r;
return novi;
}
Krug operator-(Krug const &obj)
{
Krug novi;
novi.r=this->r-obj.r;
return novi;
}
};

double povrsina(Krug &obj)


{
return obj.r*obj.r*pi;
}

double opseg(Krug &obj)


{
return 2*obj.r*pi;
}

ostream &operator<<(ostream &output, Krug &obj)


{
output<<"Radijus je "<<obj.getR()<<endl;
polje = (T *)realloc(polje, sizeof(T)*velicina);
}
2. Zadatak Vector }
#include <iostream> void insert(int index,T broj)
#include <stdlib.h> {
//funkcionalnostima za: push_back(T), size(), velicina++;
capacity, [int], insert(int, T), erase(int), maxsize=velicina;
shrink_to_fit(). polje = (T *)realloc(polje, sizeof(T)*velicina);
using namespace std; for(int i=velicina-1;i>index;i--)
template<typename T> {
class MyVector{ polje[i]=polje[i-1];
public: }
int velicina; polje[index]=broj;
int maxsize; }
T *polje; void print()
MyVector() {
{ for(int i = 0; i < velicina; i++)
maxsize=50; {
velicina=0; cout << polje[i] << " " ;
polje = (T*)malloc(maxsize * sizeof(T)); }
} cout << endl;
void push_back(T broj) }
{ };
polje[velicina]=broj;
velicina++; int main() {
}
int size()
{ }
return velicina;
}
int capacity()
{
return maxsize;
}
void shrink_to_fit()
{
polje = (T *)realloc(polje, sizeof(T)*velicina);
maxsize=velicina;
}

T& operator[](int index)


{
return polje[index];
}
void erase(int index)
{
for(int i=index;i<velicina-1;i++)
{
polje[i]=polje[i+1];
polje[velicina-1]=0;
velicina--;
maxsize=velicina;
2. Zadatak Set sort(v.begin(),v.end());
#include <bits/stdc++.h> velicina--;
break;
using namespace std; }
}
template<class T> }
class myset
{ int getsize()
private: {
vector<T> v; return velicina;
unsigned int velicina=0;; }

public: void printall()


{
void insert(T x) for(auto& it:v)
{ {
int z=0; cout<<it<<endl;
for(int i=0; i<velicina; i++) }
{ }
if(v[i]==x)
{ };
z=1;
break;
}
} int main()
if(z==0) {
{
velicina++; return 0;
v.push_back(x); }
sort(v.begin(),v.end());
}
}

void clear()
{
v.erase(v.begin(),v.end());
v.clear();
velicina=0;
}

T print(T x)
{
return v[x];
}

void erase(T x)
{
for(int i=0; i<velicina; i++)
{
if(x==v[i])
{
v.erase (v.begin()+i);
}
3. Algoritam za najkraći put for (auto& adj_vertex : G[vertex])//ide u
#include <iostream> susjedne vrhove
#include <vector> {
#include<map>
#include <set>
using namespace std;
if (visited.count(adj_vertex.first) == 0)
typedef int vertexType; {
template<class T>
using Graph = map<vertexType, map<vertexType,
T>>; next_vertex.insert({ distance_from_src +
adj_vertex.second,adj_vertex.first });
int main() cout << vertex;
{
Graph<double>G; }
int n; //broj bridova
cin >> n; }
vertexType v1, v2;
for (int i = 0; i < n; i++) }
{ finish:
cin >> v1 >> v2;
cin >> G[v1][v2]; return 0;
} }
vertexType src, dst;
cin >> src >> dst;

set<vertexType> visited;
set<pair<double, vertexType>> next_vertex;
next_vertex.insert({ 0,src });

while (!next_vertex.empty())
{
double distance_from_src =
next_vertex.begin()->first;

vertexType vertex = next_vertex.begin()-


>second;

next_vertex.erase(next_vertex.begin());
if (visited.count(vertex) > 0)
{
continue;
}
visited.insert(vertex);

if (vertex == dst)
{

cout << distance_from_src;


goto finish;//ovdje je oke koristiti
4. ZADATAK  SAMO 5 BODOVA while(st.top() != 'N') {
#include<bits/stdc++.h> char c = st.top();
using namespace std; st.pop();
ns += c; }
class ToNormal cFormula=ns;
{ private: cout << ns << endl;
string cFormula; }
public: void showstack(stack <double> s)
int prec(char c) {
{ while (!s.empty()) {
if(c == '^') { cout <<s.top()<<" ";
return 3; } s.pop(); }
else if(c == '*' || c == '/') { cout <<"\n";
return 2; } }
else if(c == '+' || c == '-') {
return 1; } void evaluatePostfix(string s){
else { s = cFormula;
return -1; stack<double> mystack;
}} for (int i=0; i<s[i]; ++i)
void infixToPostfix(string s) {
{ if(isdigit(s[i])){
cFormula=s; mystack.push(s[i] - 48);
std::stack<char> st; }
st.push('N'); else {
string ns; double val1 = mystack.top();
for(int i = 0; i < s[i]; i++) mystack.pop();
{ double val2 = mystack.top();
if((s[i] >= '0' && s[i] <= '9')) mystack.pop();
ns+=s[i]; switch(s[i])
else if(s[i] == '(') {
st.push('('); case '+': mystack.push(val2+val1); break;
else if(s[i] == ')') case '-': mystack.push(val2-val1); break;
{ case '*': mystack.push(val2*val1); break;
while(st.top() != 'N' && st.top()!= '(') { case '/': mystack.push(val2/val1); break;
char c = st.top(); case '^': mystack.push(pow(val2, val1));
st.pop(); break;
ns += c; } } }
} cout<<mystack.top();
if(st.top() == '('){ } };
char c = st.top(); int main()
st.pop(); {
}} string formula;
else cin>>formula;
{ ToNormal form;
while(st.top() != 'N' && prec(s[i]) <= form.infixToPostfix(formula);
prec(st.top())) { form.evaluatePostfix(formula);
char c = st.top(); return 0;
st.pop(); }
ns += c;
}
st.push(s[i]);
}}
IZBACIVAČ vektor.clear();
#include <iostream> for (char const &i: lista)
#include <bits/stdc++.h> {
using namespace std; vektor.push_back(i);
}
int main()
{ for(int i=0; i<vektor.size(); i++)
vector<int> vektor; {
list<int> lista; cout << vektor[i] << " ";
int n, br; }
cin >> n; return 0;
for(int i=0; i<n; i++) }
{
cin >> br;
vektor.push_back(br);
}
for(int i=0; i<n; i++)
{
cout << vektor[i] << " ";
}
cout << endl;
std::copy(vektor.begin(), vektor.end(),
back_inserter(lista));
for (auto const& i: lista)
{
cout << i << " ";
}
cout << endl;
sort(vektor.begin(), vektor.end());
for(int i=0; i<n; i++)
{
cout << vektor[i] << " ";
}
cout << endl;
for(int i=0; i<n; i++)
{

if((upper_bound(vektor.begin(),vektor.end(),ve
ktor[i])-
lower_bound(vektor.begin(),vektor.end(),vekto
r[i]))%2==1)
{
lista.remove(vektor[i]);
}
}

for (auto const& i: lista)


{
cout << i << " ";
}
cout << endl;

You might also like