Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class element {
- protected:
- double prad;
- double napiecie;
- double moc;
- double czestotliwosc;
- std::string nazwa;
- public:
- element() {nazwa = "element"; czestotliwosc = 1.0; napiecie = prad = moc = 0.0;}
- element(const std::string arg) {nazwa = arg; napiecie = czestotliwosc = 1.0; prad = moc = 0.0;}
- virtual void wymuszenieU(double) = 0;
- virtual void wymuszenieI(double) = 0;
- friend int obwod(element*, element*);
- };
- int obwod(element *e1, element *e2) {
- bool pradMatch = false;
- bool napiecieMatch = false;
- int matchType;
- if (e1->prad == e2->prad) {
- pradMatch = true;
- }
- if (e1->napiecie == e2->napiecie) {
- napiecieMatch = true;
- }
- if ((pradMatch && !napiecieMatch) || (!pradMatch && napiecieMatch)) {
- //std::string matchType = (pradMatch)?"prad":"napiecie";
- if (pradMatch) {
- matchType = 1;
- } else {
- matchType = 2;
- }
- } else {
- if (pradMatch && napiecieMatch) {
- matchType=3;
- } else {
- matchType=0;
- }
- }
- cout<<matchType;
- return matchType;
- }
- class cewka : public element {
- protected:
- double L;
- public:
- cewka() {nazwa = "cewka"; L = 1.0;}
- cewka(const std::string arg) {nazwa = arg; L = 1.0;}
- cewka(const std::string arg, double argL) {nazwa = arg; L = argL;}
- void wymuszenieU(double);
- void wymuszenieI(double);
- string getName(){return nazwa;}
- };
- void cewka::wymuszenieU(double u) {
- napiecie = u;
- if (czestotliwosc > 0.0) {
- prad = u/(6.28*czestotliwosc*L);
- }
- }
- void cewka::wymuszenieI(double i) {
- prad = i;
- napiecie = i*6.28*czestotliwosc*L;
- }
- int main() {
- element* tab[2];
- tab[0] = new cewka("cewka1");
- tab[1] = new cewka("cewka2", 3.0);
- tab[0]->wymuszenieU(5);
- tab[1]->wymuszenieU(5);
- tab[0]->wymuszenieI(5);
- tab[1]->wymuszenieI(5);
- obwod(tab[0], tab[1]);
- delete tab[0];
- delete tab[1];
- return 0;
- }
Add Comment
Please, Sign In to add comment