Advertisement
xTheEc0

3. OOP Test.

Mar 17th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <cstdlib>  // Standard General Utilities Library
  2. #include <cstdio>   // Input/Output operations (C)
  3. #include <iostream> // Input/Output stream objects
  4. #include <fstream>  // File input and output
  5. #include <ctime>    // Date and time information
  6. #include <cmath>    // Mathematical operations and transformations
  7. using namespace std;
  8.  
  9. // Classes
  10. class opkontrolinis {
  11. private:
  12.     int a, b;
  13.     double c, d;
  14. public:
  15.     opkontrolinis();
  16.     opkontrolinis(int, int, double, double);
  17.  
  18.     void print();
  19.     double suma();
  20. };
  21.  
  22. // Methods
  23. opkontrolinis::opkontrolinis() {
  24.     a = 1;
  25.     b = 1;
  26.     c = 1;
  27.     d = 1;
  28. }
  29.  
  30. opkontrolinis::opkontrolinis(int p1, int p2, double p3, double p4) {
  31.     a = p1;
  32.     b = p2;
  33.     c = p3;
  34.     d = p4;
  35. }
  36.  
  37. void opkontrolinis::print() {
  38.     cout << a << " " << b << " " << c << " " << d << endl;
  39. }
  40.  
  41. double opkontrolinis::suma() {
  42.     return a + b + c + d;
  43. }
  44.  
  45. // Main program
  46. int main(int argc, char *argv[]) {
  47.  
  48.     opkontrolinis obj1;
  49.     opkontrolinis obj2(5, 10, 15.5, 20.3);
  50.  
  51.     obj1.print();
  52.     cout << "Suma = " << obj1.suma() << endl << endl;
  53.  
  54.     obj2.print();
  55.     cout << "Suma = " << obj2.suma() << endl << endl;
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement