Advertisement
Dr4noel

EXERCITII POO - LAB

Mar 30th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.33 KB | None | 0 0
  1. ###########################################################################################
  2. TEMA 2 - PROBLEMA 1.1
  3. ###########################################################################################
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. class Point {
  9. private:
  10.     int x;
  11.     int y;
  12. public:
  13.     Point(int _x, int _y);
  14.     Point(Point& y);
  15.  
  16.     Point& operator=(Point& p);
  17.  
  18.     void setX(int _x);
  19.     void setY(int _y);
  20.     int getX();
  21.     int getY();
  22.  
  23.     void print();
  24. };
  25.  
  26. Point::Point(int _x, int _y) {
  27.     x = _x;
  28.     y = _y;
  29. }
  30.  
  31. Point::Point(Point& y) {
  32.     x = y.x;
  33.     this->y = y.y;
  34. }
  35.  
  36. Point& Point::operator=(Point& p) {
  37.     if (this != &p) {
  38.         this->x = p.x;
  39.         this->y = p.y;
  40.     }
  41.     return *this;
  42. }
  43.  
  44. void Point::setX(int _x) {
  45.     x = _x;
  46. }
  47.  
  48. void Point::setY(int _y) {
  49.     y = _y;
  50. }
  51.  
  52. int Point::getX() {
  53.     return x;
  54. }
  55.  
  56. int Point::getY() {
  57.     return y;
  58. }
  59.  
  60. void Point::print() {
  61.     cout << "\nx = " << x << "\n";
  62.     cout << "y = " << y << "\n";
  63. }
  64.  
  65. void main() {
  66.     Point a(5, 9);
  67.     Point b = a;
  68.  
  69.     a.print();
  70.     b.print();
  71.  
  72.     Point* pc = new Point(a.getY() * 2, a.getX() * 2);
  73.     pc->print();
  74.  
  75.     b.setX(99);
  76.     *pc = b;
  77.     pc->print();
  78.  
  79.     cin.get();
  80. }
  81. ############################################################################################
  82. TEMA 2 - PROBLEMA 1.2
  83. ############################################################################################
  84. #include <iostream>
  85. #include <math.h>
  86.  
  87. using namespace std;
  88.  
  89. class Triunghi {
  90. private:
  91.     float a;
  92.     float b;
  93.     float c;
  94.     static float checkA;
  95.     static float checkB;
  96.     static float checkC;
  97. public:
  98.     Triunghi(float a, float b, float c);
  99.  
  100.     static bool verifica();
  101.  
  102.     void arie();
  103.  
  104.     void perimetru();
  105.  
  106.     void esteDreptunghic();
  107. };
  108.  
  109. float Triunghi::checkA = 0;
  110. float Triunghi::checkB = 0;
  111. float Triunghi::checkC = 0;
  112.  
  113. Triunghi::Triunghi(float a, float b, float c) {
  114.     this->a = a;
  115.     this->b = b;
  116.     this->c = c;
  117.     checkA = a;
  118.     checkB = b;
  119.     checkC = c;
  120. }
  121.  
  122. void Triunghi::arie() {
  123.     float p = (a + b + c) / 2;
  124.  
  125.     cout << "Aria triunghiului este : " << sqrt(p*(p - a)*(p - b)*(p - c));
  126. }
  127.  
  128. void Triunghi::perimetru() {
  129.     cout << "\nPerimetrul triunghilui este : " << a + b + c;
  130. }
  131.  
  132. void Triunghi::esteDreptunghic() {
  133.     float x = pow(c,2);
  134.     float y = pow(a, 2) + pow(b, 2);
  135.     if (x == y) {
  136.         cout << "\nTriunghiul este dreptunghic!";
  137.     }
  138.     else {
  139.         cout << "\nTriunghiul nu este dreptunghic!";
  140.     }
  141. }
  142.  
  143. bool Triunghi::verifica() {
  144.     if ((checkA == 0) || (checkB == 0) || (checkC == 0)) {
  145.         return false;
  146.     }
  147.     else {
  148.         return true;
  149.     }
  150. }
  151.  
  152. void main() {
  153.     Triunghi a(3,4,5);
  154.  
  155.     if (a.verifica() == false) {
  156.         cout << "Laturile date nu pot forma un triunghi!\n";
  157.     }
  158.     else {
  159.         a.arie();
  160.  
  161.         a.perimetru();
  162.  
  163.         a.esteDreptunghic();
  164.     }
  165.     cin.get();
  166. }
  167. ###################################################################################
  168. TEMA 2 - PROBLEMA 1.3
  169. ###################################################################################
  170. #include <iostream>
  171. #include <conio.h>
  172.  
  173. using namespace std;
  174.  
  175. class Pacient {
  176. private:
  177.     char* nume;
  178.     char* prenume;
  179.     int varsta;
  180.     char *diagnostic;
  181.     static int nrPacienti;
  182. public:
  183.     Pacient(const char* nume = "NA", const char* prenume = "NA", int varsta = 0, const char* diagnostic = "NA");
  184.  
  185.     Pacient(Pacient& p);
  186.  
  187.     ~Pacient();
  188.  
  189.     void citire();
  190.    
  191.     void afisare();
  192.  
  193.     static void setNrPacienti(int one);
  194. };
  195.  
  196. int Pacient::nrPacienti = 1;
  197.  
  198. Pacient::Pacient(const char* nume,const char* prenume, int varsta,const char* diagnostic) {
  199.  
  200.     this->nume = new char[strlen(nume) + 1];
  201.     strcpy_s(this->nume, strlen(nume) + 1, nume);
  202.  
  203.     this->prenume = new char[strlen(prenume) + 1];
  204.     strcpy_s(this->prenume, strlen(prenume) + 1, prenume);
  205.  
  206.     this->varsta = varsta;
  207.  
  208.     this->diagnostic = new char[strlen(diagnostic) + 1];
  209.     strcpy_s(this->diagnostic, strlen(diagnostic) + 1, diagnostic);
  210.  
  211. }
  212.  
  213. Pacient::Pacient(Pacient& p) {
  214.     nume = p.nume;
  215.     prenume = p.prenume;
  216.     varsta = p.varsta;
  217.     diagnostic = p.diagnostic;
  218. }
  219.  
  220. Pacient::~Pacient() {
  221.     if (nume != NULL && prenume != NULL && diagnostic != NULL) {
  222.         delete nume;
  223.         delete prenume;
  224.         delete diagnostic;
  225.     }
  226. }
  227.  
  228. void Pacient::citire() {
  229.     nume = new char[25];
  230.     prenume = new char[30];
  231.     diagnostic = new char[40];
  232.     cout << "Pacient #" << nrPacienti << "\n";
  233.     cout << "Numele pacientului : ";
  234.     cin >> nume;
  235.     cout << "Prenumele pacientului : ";
  236.     cin >> prenume;
  237.     cout << "Varsta pacientului : ";
  238.     cin >> varsta;
  239.     cout << "Diagnosticul pacientului : ";
  240.     cin >> diagnostic;
  241.     nrPacienti++;
  242. }
  243.  
  244. void Pacient::afisare() {
  245.     cout << "Pacient #" << nrPacienti <<"\n";
  246.     cout << "  Nume : " << nume << "\n";
  247.     cout << "  Prenume : " << prenume << "\n";
  248.     cout << "  Varsta : " << varsta << "\n";
  249.     cout << "  Diagnostic : " << diagnostic << "\n";
  250.     nrPacienti++;
  251. }
  252.  
  253. void Pacient::setNrPacienti(int one) {
  254.     nrPacienti = one;
  255. }
  256.  
  257. //PROTOTIPURI DE FUNCTII
  258. void cicluCitire(Pacient pacient[], int& n);
  259. void cicluAfisare(Pacient pacient[], int& n);
  260. void callDestructors(Pacient pacient[], int& n);
  261.  
  262. void main(){
  263.     int n;
  264.     Pacient pacient[10];
  265.  
  266.     cicluCitire(pacient, n);
  267.  
  268.     Pacient::setNrPacienti(1);
  269.  
  270.     cicluAfisare(pacient, n);
  271.  
  272.     callDestructors(pacient, n);
  273.  
  274.     _getch();
  275. }
  276.  
  277. void cicluCitire(Pacient pacient[], int& n) {
  278.  
  279.     cout << "Introduceti numarul de pacienti : ";
  280.     cin >> n;
  281.  
  282.     for (int i = 0; i < n; i++) {
  283.         pacient[i].citire();
  284.     }
  285. }
  286.  
  287. void cicluAfisare(Pacient pacient[], int& n) {
  288.     for (int i = 0; i < n; i++) {
  289.         pacient[i].afisare();
  290.     }
  291. }
  292.  
  293. void callDestructors(Pacient pacient[], int& n) {
  294.     for (int i = 0; i < n; i++) {
  295.         pacient[i].~Pacient();
  296.     }
  297. }
  298. ###################################################################################
  299. TEMA 2 - PROBLEMA 1.4
  300. ###################################################################################
  301. #include <iostream>
  302. #include <conio.h>
  303.  
  304. using namespace std;
  305.  
  306. class DataCalendaristica {
  307. private:
  308.     int zi;
  309.     int luna;
  310.     int an;
  311. public:
  312.     DataCalendaristica(int _zi = 1, int _luna = 1, int _an = 1700);
  313.  
  314.     static bool isA_ValidDate(int _zi, int _luna, int _an);
  315.  
  316.     void readDate();
  317.  
  318.     void displayDate();
  319.  
  320.     static DataCalendaristica nextDay(DataCalendaristica& ob);
  321. };
  322.  
  323. //constructor de initializare
  324. DataCalendaristica::DataCalendaristica(int _zi, int _luna, int _an) {
  325.     zi = _zi;
  326.     luna = _luna;
  327.     an = _an;
  328. }
  329.  
  330. //Functie pentru verificare datei
  331. bool DataCalendaristica::isA_ValidDate(int _zi, int _luna, int _an) {
  332.     int nrZileLuna[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
  333.  
  334.     if (_an % 4 == 0) {
  335.         nrZileLuna[1] = 29;
  336.     }
  337.  
  338.     if (_luna > 12 || _zi > nrZileLuna[_luna - 1] || _luna < 1 || _zi < 1) {
  339.         return false;
  340.     }
  341.     else {
  342.         return true;
  343.     }
  344. }
  345.  
  346. void DataCalendaristica::readDate() {
  347.    
  348.     cout << "Zi : ";
  349.     cin >> zi;
  350.     cout << "Luna : ";
  351.     cin >> luna;
  352.     cout << "An : ";
  353.     cin >> an;
  354.  
  355. }
  356.  
  357. //afisarea unei date
  358. void DataCalendaristica::displayDate() {
  359.     int format;
  360.    
  361.     if (isA_ValidDate(zi, luna, an)) {
  362.         do {
  363.             cout << "Introduceti tipul formatului : \n";
  364.             cout << "1. zz/ll/aaaa \n";
  365.             cout << "2. ll/zz/aaaa \n";
  366.             cout << "3. aaaa/ll/zz \n";
  367.             cin >> format;
  368.        
  369.         } while (format < 1 || format > 3);
  370.  
  371.         switch (format) {
  372.         case 1:
  373.             cout << "\nData este : \n";
  374.             cout << "\n" << zi << "/" << luna << "/" << an << "\n";
  375.             break;
  376.         case 2:
  377.             cout << "\nData este : \n";
  378.             cout << "\n" << luna << "/" << zi << "/" << an << "\n";
  379.             break;
  380.         case 3:
  381.             cout << "\nData este : \n";
  382.             cout << "\n" << an << "/" << luna << "/" << zi << "\n";
  383.             break;
  384.         }
  385.     }
  386.     else {
  387.        
  388.         cout << "\nData introdusa nu este una valida!\n";
  389.     }
  390. }
  391.  
  392. DataCalendaristica DataCalendaristica::nextDay(DataCalendaristica& ob) {
  393.     int nrZileLuna[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
  394.     DataCalendaristica obiect;
  395.  
  396.     if (ob.an % 4 == 0) {
  397.         nrZileLuna[1] = 29;
  398.     }
  399.  
  400.     obiect.zi = ob.zi + 1;
  401.     obiect.luna = ob.luna;
  402.     obiect.an = ob.an;
  403.  
  404.     if ((ob.zi + 1) > nrZileLuna[ob.luna - 1] && ob.luna != 12) {
  405.         obiect.luna += 1;
  406.         obiect.zi = 1;
  407.     }
  408.     else
  409.         if ((ob.zi + 1) > nrZileLuna[ob.luna - 1] && ob.luna == 12) {
  410.             obiect.zi = 1;
  411.             obiect.luna = 1;
  412.             obiect.an += 1;
  413.         }
  414.     return obiect;
  415. }
  416.  
  417. void main() {
  418.     DataCalendaristica data, data1;
  419.  
  420.     data.displayDate();
  421.  
  422.     cout << "\nApasati o tasta pentru a continua...\n";
  423.     _getch();
  424.  
  425.     data.readDate();
  426.    
  427.     data.displayDate();
  428.    
  429.     cout << "\nApasati o tasta pentru a continua...\n";
  430.     _getch();
  431.  
  432.     data1 = data.nextDay(data);
  433.  
  434.     data1.displayDate();
  435.  
  436.     _getch();
  437. }
  438. ###################################################################################
  439. TEMA 2 - PROBLEMA 1.5
  440. ###################################################################################
  441. #include <iostream>
  442. #include <conio.h>
  443. using namespace std;
  444. #define MAX 500
  445.  
  446. class String {
  447.     char text[MAX];
  448. public:
  449.     String(const char tab[]);       //constructor
  450.     String(String& ob);             //constructor de copiere
  451.    
  452.     char chartAt(int index);        //intoarce caracterul de pe pozitia index
  453.     String concat(String& str);     //concateneaza sirul curent cu sirul str
  454.     void print();                   //afiseaza sirul de caractere curent
  455. };
  456.  
  457. String::String(const char tab[]) {
  458.     for (int i = 0; i < (strlen(tab)+1); i++) {
  459.         text[i] = tab[i];
  460.     }
  461. }
  462.  
  463. String::String(String& ob) {
  464.     for (int i = 0; text[i] != '\0'; i++) {
  465.         text[i] = ob.text[i];
  466.     }
  467. }
  468.  
  469. char String::chartAt(int index) {
  470.  
  471.     cout << "Pozitia caracterului: "; cin >> index;
  472.  
  473.     return text[index];
  474. }
  475.  
  476. String String::concat(String& str) {
  477.     int mem = 0;
  478.     for (int i = 0; text[i] != '\0'; i++) {
  479.         mem++;
  480.     }
  481.     int i;
  482.     for (i = 0; str.text[i] != '\0'; i++) {
  483.         text[mem + i] = str.text[i];
  484.     }
  485.     text[mem + i] = '\0';
  486.     return text;
  487. }
  488.  
  489. void String::print() {
  490.     for (int i = 0; text[i] != '\0'; i++) {
  491.         cout << text[i];
  492.     }
  493. }
  494.  
  495. int main() {
  496.     String str1("Luceafarul ");
  497.     String str2("de dimineata");
  498.  
  499.     str1.print();
  500.     str2.print();
  501.  
  502.     cout << "\n";
  503.  
  504.     str2 = str1.concat(str2);
  505.     str2.print();
  506.  
  507.     _getch();
  508.     return 0;
  509. }
  510.  
  511. ###################################################################################
  512. TEMA 2 - PROBLEMA 1.6
  513. ###################################################################################
  514.  
  515. #include <iostream>
  516. #include <conio.h>
  517. using namespace std;
  518. #define MAX 500
  519.  
  520. class String {
  521.     char text[MAX];
  522. public:
  523.     String(const char tab[]);                               //constructor
  524.     String(String& ob);                                     //constructor de copiere
  525.    
  526.     char operator[](int index);                             //intoarece caracterul de pe pozitia index;
  527.     String operator+(String& str);                          //concateneaza sirul curent cu stringul str
  528.  
  529.     friend ostream& operator<<(ostream& os, String& ob);    // afiseaza sirul de caractere curent
  530.  
  531.     String toLowerCase();                                   //intoarce situl transformat in litere mici
  532.     String substring(int start, int len);                   //returneaza un string ce incepe pe poztia
  533.                                                             //start si are len caractere
  534. };
  535.  
  536.  
  537. String::String(const char tab[]) {
  538.     for (int i = 0; i < (strlen(tab)+1); i++) {
  539.         text[i] = tab[i];
  540.     }
  541. }
  542.  
  543. String::String(String& ob) {
  544.     strcpy_s(text,ob.text);
  545. }
  546.  
  547. char String::operator[](int index) {
  548.     return text[index];
  549. }
  550.  
  551. String String::operator+(String& str) {
  552.     int mem = 0;
  553.     for (int i = 0; text[i] != '\0'; i++) {
  554.         mem++;
  555.     }
  556.     int i;
  557.     for (i = 0; str.text[i] != '\0'; i++) {
  558.         text[mem + i] = str.text[i];
  559.     }
  560.     text[mem + i] = '\0';
  561.     return text;
  562. }
  563.  
  564.  
  565. ostream& operator<<(ostream& os, String& ob) {
  566.     for (int i = 0; ob.text[i] != '\0'; i++) {
  567.         cout << ob.text[i];
  568.     }
  569.     return os;
  570. }
  571.  
  572. String String::toLowerCase() {
  573.     for (int i = 0; text[i] != '\0'; i++) {
  574.         if ((int)text[i] >= 64 && (int)text[i] <= 90) {
  575.             text[i] = (int)text[i] + 32;
  576.         }
  577.     }
  578.     return text;
  579. }
  580.  
  581. String String::substring(int start, int len) {
  582.     String str3("");
  583.     int k = 0;
  584.     for(int i = start; k < len;i++){
  585.         str3.text[k] = text[i];
  586.         k++;
  587.     }
  588.     str3.text[k] = '\0';
  589.     return str3;
  590. }
  591.  
  592. void main() {
  593.     String str1("Luceafarul ");
  594.     String str2("de dimineata");
  595.    
  596.     cout << str1;
  597.    
  598.     cout << "\n";
  599.  
  600.     cout << str1[6];
  601.     str1 = str1 + str2;
  602.     str1.toLowerCase();
  603.  
  604.     cout << "\n";
  605.  
  606.     cout << str1;
  607.    
  608.     cout << "\n";
  609.  
  610.     String str3("");
  611.  
  612.     str3 = str1.substring(2, 3);
  613.  
  614.     cout << str3;
  615.  
  616.     _getch();
  617. }
  618.  
  619. ###################################################################################
  620. TEMA 2 - PROBLEMA 1.7
  621. ###################################################################################
  622. #include <iostream>
  623. #include <conio.h>
  624.  
  625. using namespace std;
  626.  
  627. class String {
  628.     char* text;
  629. public:
  630.     String(const char tab[]);           //constructor
  631.     String(String& ob);                 //constructor de copiere
  632.  
  633.     String operator=(String& str);      //operatorul '=' supraincarcat
  634.     char chartAt(int index);            //intoarce caracterul de pe pozitia index
  635.     String concat(String& str);         //concateneaza sirul curent cu sirul str
  636.     int lenght();                       //intoarce lungimea sirului
  637.     void trim();                        //sterge spatiile de la capetele sirului
  638.     void print();                       // Am ales sa introduc functia de print doar pentru a putea verifica
  639. };
  640.  
  641. String::String(const char tab[]) {
  642.     text = new char[strlen(tab) + 1];
  643.     strcpy_s(text,strlen(tab) + 1,tab);
  644. }
  645.  
  646. String::String(String& ob) {
  647.     text = new char[strlen(ob.text)];
  648.     strcpy_s(text,strlen(ob.text) + 1,ob.text);
  649. }
  650.  
  651. String String::operator=(String& str) {
  652.     int k, max;
  653.  
  654.     k = strlen(text);
  655.     max = strlen(str.text);
  656.     if (max != k) {
  657.         if (k > max) {
  658.             max = k;
  659.         }
  660.         for (int i = 0; i < max; i++) {
  661.             strcpy_s(text + i,strlen(str.text) + 1,str.text + i);
  662.         }
  663.     }
  664.     return text;
  665. }
  666.  
  667. char String::chartAt(int index) {
  668.     return *(text + index);
  669. }
  670.  
  671. String String::concat(String& str) {
  672.     int c1, c2;                         //contori
  673.     c1 = strlen(text);
  674.     c2 = strlen(str.text);
  675.     for (int i = 0; i < c2; i++) {
  676.         *(text + c1 + i) = str.text[i];
  677.     }
  678.     text[c1 + c2] = '\0';
  679.     return text;
  680. }
  681.  
  682. void String::print() {
  683.     int n = strlen(text);
  684.     for (int i = 0; i < n; i++) {
  685.         cout << *(text + i);
  686.     }
  687. }
  688.  
  689. int String::lenght() {
  690.     return strlen(text) + 1;
  691. }
  692.  
  693. void String::trim() {
  694.     for (int i = strlen(text) + 1; i >= 0; i--) {
  695.         if (text + i == '\0') {
  696.             delete (text + i);
  697.         }
  698.     }
  699. }
  700.  
  701. void main() {
  702.     String str1("Lucifer");
  703.     String str2(" Morningstar");
  704.  
  705.     str1.print();
  706.  
  707.     cout << "\n";
  708.  
  709.     cout << str1.chartAt(0);
  710.  
  711.     cout << "\n";
  712.  
  713.     str1.concat(str2);
  714.  
  715.     str1.print();
  716.  
  717.     str1.trim();
  718.  
  719.     int k1 = str1.lenght();
  720.  
  721.     cout << "\n" << k1;
  722.  
  723.     _getch();
  724. }
  725. ###################################################################################
  726. TEMA 2 - PROBLEMA 1.8
  727. ###################################################################################
  728. #include <iostream>
  729. #include <conio.h>
  730.  
  731. using namespace std;
  732.  
  733. class Polinom {
  734. private:
  735.     int grad;
  736.     int* coef;
  737. public:
  738.     Polinom(int n);
  739.     Polinom(Polinom& ob);
  740.     ~Polinom();
  741.     int operator[](int i);
  742.     Polinom& operator+(Polinom& p);
  743.     friend Polinom& operator*(Polinom& p1, Polinom& p2);
  744.     friend istream& operator>>(istream& is, Polinom& p);
  745.     friend ostream& operator<<(ostream& os, Polinom& p);
  746. };
  747.  
  748. Polinom::Polinom(int n) {
  749.     grad = n;
  750.     coef = new int[grad + 1];
  751.     memset(coef, 0, sizeof(int) * (n + 1));
  752. }
  753.  
  754. Polinom::Polinom(Polinom& ob) {
  755.     grad = ob.grad;
  756.     coef = new int[grad + 1];
  757.     for (int i = 0; i <= grad; i++) {
  758.         *(coef + i) = *(ob.coef + i);
  759.     }
  760. }
  761.  
  762. Polinom::~Polinom() {
  763.     delete[] coef;
  764. }
  765.  
  766. int max(int x, int y) {
  767.     return ((x > y) ? x : y);
  768. }
  769.  
  770. int Polinom::operator[](int i) {
  771.     return((i >= 0 && i <= grad) ? *(coef + i) : 0);
  772. }
  773.  
  774. Polinom& Polinom::operator+(Polinom& p) {
  775.     Polinom *T;
  776.     T = new Polinom(max(grad, p.grad));
  777.     for (int i = 0; i <= T->grad; i++) {
  778.         *(T->coef + i) = (*this)[i] + p[i];
  779.     }
  780.  
  781.     return *T;
  782. }
  783.  
  784. Polinom& operator *(Polinom& P1, Polinom& P2) {
  785.     Polinom *T;
  786.     T = new Polinom(P1.grad + P2.grad);
  787.     for (int i = 0; i <= P1.grad; i++)
  788.         for (int j = 0; j <= P2.grad; j++)
  789.             T->coef[i + j] += P1[i] * P2[j];
  790.     return *T;
  791. }
  792.  
  793. istream& operator>>(istream& is, Polinom& p) {
  794.     for (int i = 0; i <= p.grad; i++) {
  795.         cout << "Coef[" << i << "] = ";
  796.         is >> *(p.coef + i);
  797.     }
  798.     return is;
  799. }
  800.  
  801. ostream& operator<<(ostream& os, Polinom& p) {
  802.     os << "P(x) = ";
  803.     for (int i = p.grad; i >= 0; i--) {
  804.         if ((p.coef + i)) {
  805.             if (i != p.grad) {
  806.                 os << ((*(p.coef + i) > 0) ? '+' : ' ');
  807.             }
  808.             os << *(p.coef + i) << "*x^" << i;
  809.         }
  810.     }
  811.     os << endl;
  812.     return os;
  813. }
  814.  
  815. void main() {
  816.     Polinom P(1), Q(2);
  817.     cout << "Dati valorile primului polinom : \n";
  818.     cin >> P;
  819.     cout << "Dati valorile pentru al doilea polinom: \n";
  820.     cin >> Q;
  821.  
  822.     Polinom R = P + Q;
  823.  
  824.     cout << "Suma : \n";
  825.     cout << R;
  826.     R = P * Q;
  827.     cout << "Produsul : \n";
  828.     cout << R;
  829.  
  830.     _getch();
  831. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement