Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //otpornik.hpp
- #ifndef OTPORNIK_DEF
- #define OTPORNIK_DEF
- #include <iostream>
- using namespace std;
- class Otpornik{
- private:
- double r;
- public:
- Otpornik();
- Otpornik(double);
- Otpornik(const Otpornik&);
- void setR(double);
- double getR()const;
- Otpornik& operator=(const Otpornik&);
- friend Otpornik operator+(const Otpornik&, const Otpornik&);
- friend Otpornik operator||(const Otpornik&, const Otpornik&);
- friend ostream& operator<<(ostream&, const Otpornik&);
- friend istream& operator>>(istream&, Otpornik&);
- };
- #endif
- //otpornik.cpp
- #include "otpornik.hpp"
- Otpornik:: Otpornik() {r = 0;}
- Otpornik:: Otpornik(double rr) {r = rr;}
- Otpornik:: Otpornik(const Otpornik &x){r = x.r;}
- void Otpornik:: setR(double rr){r = rr;}
- double Otpornik::getR()const{return r;}
- Otpornik& Otpornik::operator=(const Otpornik &x){r = x.r;}
- Otpornik operator+(const Otpornik &x, const Otpornik &y){
- Otpornik z( x.r + y.r);
- return z;
- }
- Otpornik operator||(const Otpornik &x, const Otpornik&y){
- Otpornik z((x.r * y.r)/ (x.r+y.r)) ;
- return z;
- }
- ostream& operator<<(ostream &out, const Otpornik &x){
- out<<x.r;
- return out;
- }
- istream& operator>>(istream &in, Otpornik &x){
- in>>x.r;
- return in;
- }
- //main.cpp
- #include "otpornik.hpp"
- int main(){
- Otpornik r1,r2;
- cout<<"r1,r2?"<<endl;
- cin>>r1;
- cin>>r2;
- cout<<"serijska veza:"<<(r1+r2)<<endl;
- cout<<"paralelna veza:"<<(r1||r2)<<endl;
- r1=r2;
- cout<<r1<<"="<<r2;
- return 0;
- }
Add Comment
Please, Sign In to add comment