koyukix

lab 6

Jan 11th, 2020
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. using namespace std;
  5.  
  6. class element {
  7. protected:
  8. double prad;
  9. double napiecie;
  10. double moc;
  11. double czestotliwosc;
  12. std::string nazwa;
  13. public:
  14. element() {nazwa = "element"; czestotliwosc = 1.0; napiecie = prad = moc = 0.0;}
  15. element(const std::string arg) {nazwa = arg; napiecie = czestotliwosc = 1.0; prad = moc = 0.0;}
  16. virtual void wymuszenieU(double) = 0;
  17. virtual void wymuszenieI(double) = 0;
  18. friend int obwod(element*, element*);
  19. };
  20.  
  21. int obwod(element *e1, element *e2) {
  22. bool pradMatch = false;
  23. bool napiecieMatch = false;
  24. int matchType;
  25. if (e1->prad == e2->prad) {
  26. pradMatch = true;
  27. }
  28. if (e1->napiecie == e2->napiecie) {
  29. napiecieMatch = true;
  30. }
  31. if ((pradMatch && !napiecieMatch) || (!pradMatch && napiecieMatch)) {
  32. //std::string matchType = (pradMatch)?"prad":"napiecie";
  33. if (pradMatch) {
  34. matchType = 1;
  35. } else {
  36. matchType = 2;
  37. }
  38. } else {
  39. if (pradMatch && napiecieMatch) {
  40. matchType=3;
  41. } else {
  42. matchType=0;
  43. }
  44. }
  45. cout<<matchType;
  46. return matchType;
  47. }
  48.  
  49.  
  50. class cewka : public element {
  51. protected:
  52. double L;
  53. public:
  54. cewka() {nazwa = "cewka"; L = 1.0;}
  55. cewka(const std::string arg) {nazwa = arg; L = 1.0;}
  56. cewka(const std::string arg, double argL) {nazwa = arg; L = argL;}
  57. void wymuszenieU(double);
  58. void wymuszenieI(double);
  59. string getName(){return nazwa;}
  60. };
  61.  
  62. void cewka::wymuszenieU(double u) {
  63. napiecie = u;
  64. if (czestotliwosc > 0.0) {
  65. prad = u/(6.28*czestotliwosc*L);
  66. }
  67. }
  68. void cewka::wymuszenieI(double i) {
  69. prad = i;
  70. napiecie = i*6.28*czestotliwosc*L;
  71. }
  72.  
  73. int main() {
  74.  
  75. element* tab[2];
  76. tab[0] = new cewka("cewka1");
  77. tab[1] = new cewka("cewka2", 3.0);
  78. tab[0]->wymuszenieU(5);
  79. tab[1]->wymuszenieU(5);
  80. tab[0]->wymuszenieI(5);
  81. tab[1]->wymuszenieI(5);
  82. obwod(tab[0], tab[1]);
  83. delete tab[0];
  84. delete tab[1];
  85. return 0;
  86. }
Add Comment
Please, Sign In to add comment