Advertisement
xTheEc0

6. Practice.

Apr 14th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 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 <iomanip>  // Input/Output manipulator
  5. #include <fstream>  // File input and output
  6. #include <ctime>    // Date and time information
  7. #include <cmath>    // Mathematical operations and transformations
  8.  
  9. using namespace std;
  10.  
  11. #define CMax 100
  12.  
  13. // Class
  14. class skaiciai {
  15. private:
  16.     int a, b, c;
  17. public:
  18.     void priskirti();
  19.     int suma();
  20.     void spausdinti();
  21.  
  22.     // constructors
  23.     skaiciai();
  24.     skaiciai(int);
  25.     skaiciai(int, int, int);
  26. };
  27.  
  28. void skaiciai::priskirti() {
  29.     cin >> a >> b >> c;
  30. }
  31.  
  32. int skaiciai::suma() {
  33.     return a + b + c;
  34. }
  35.  
  36. void skaiciai::spausdinti() {
  37.     cout << "a = " << a << ", b = " << b << ", c = " << c << endl;
  38. }
  39.  
  40. // Class constructors
  41. skaiciai::skaiciai() {
  42.     a = 0;
  43.     b = 0;
  44.     c = 0;
  45. }
  46.  
  47. skaiciai::skaiciai(int var1, int var2, int var3) {
  48.     a = var1;
  49.     b = var2;
  50.     c = var3;
  51. }
  52.  
  53. // Class
  54. class nauja: public skaiciai {
  55. public:
  56.     double vidurkis();
  57.  
  58.     nauja() {};
  59.     nauja(int var1, int var2, int var3): skaiciai(var1, var2, var3) {};
  60. };
  61.  
  62. double nauja::vidurkis() {
  63.     return suma() / 3.0;
  64. }
  65.  
  66.  
  67. // Main program
  68. int main(int argc, char *argv[]) {
  69.  
  70.     nauja C[5];
  71.     double vidurkis = 0;
  72.  
  73.     for (int i = 0; i < 5; i++)
  74.     {
  75.         cout << "Iveskite " << i + 1 << " masyvo a, b ir c reiksmes" << endl;
  76.         int v1, v2, v3;
  77.         cin >> v1, v2, v3;
  78.         C[i] = nauja(v1, v2, v3);
  79.         C[i].spausdinti();
  80.  
  81.         vidurkis += C[i].vidurkis();
  82.     }
  83.  
  84.     vidurkis /= 5;
  85.     cout << "Masyvu vidurkis: " << vidurkis << endl;
  86.  
  87.  
  88.    return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement