Vladislav_Bezruk

Some task

Sep 24th, 2021 (edited)
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class vektor {
  5.   int n;
  6.     float *x;
  7.     public:
  8.       vektor () {
  9.         cout<<"Default object."<<endl;
  10.       }
  11.       vektor (vektor & src) {
  12.         cout<<"Copied object:"<<endl;
  13.        
  14.         n = src.n;
  15.        
  16.         x = new float[n];
  17.         int i;
  18.         for (i = 0; i < n; i++) {
  19.           x[i] = src.x[i];
  20.       }
  21.       }
  22.       void input(int n, string s) {
  23.         int i;
  24.         x = new float[n];
  25.         cout<<"Enter new elements of the array "<<s<<":"<<endl;
  26.         for (i = 0; i < n; i++) {
  27.           cin>>x[i];
  28.         }
  29.       }
  30.       void set (int number) {
  31.         n = number;
  32.     }
  33.       float maximum () {
  34.         int i;
  35.         float max = x[0];
  36.         for (i = 1; i < n; i++) {
  37.           if (x[i] > max) {
  38.             max = x[i];
  39.           }
  40.         }
  41.         return max;
  42.       }
  43.       void output(string s);
  44. };
  45.  
  46. void vektor::output(string s) {
  47.   int i;
  48.   cout<<n<<endl;
  49.   cout<<"Array "<<s<<":"<<endl;
  50.     for (i = 0; i < n; i++) {
  51.       cout<<x[i]<<" ";
  52.     }
  53. }
  54.  
  55. int main () {
  56.   vektor vec1;
  57.   int n;
  58.   cout<<"Enter the amount of elements of the array: ";
  59.   cin>>n;
  60.   vec1.input(n, "vec1");
  61.   vec1.set(n);
  62.   cout<<"The maximal element of the array in vektor vec1 is equal to "<<vec1.maximum()<<"."<<endl;
  63.  
  64.   vektor vec2(vec1);
  65.   vec2.output("vec2");
  66.   return 0;
  67. }
Add Comment
Please, Sign In to add comment