fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. #include <iostream>
  5. #include <cstdlib>
  6. #include <vector>
  7. #include <list>
  8. #include <set>
  9. #include <deque>
  10. #include <utility>
  11. #include <cmath>
  12. #include <string>
  13. #include <cstring>
  14. #include <iomanip>
  15. #include <cctype>
  16. #include <algorithm>
  17. #include <numeric>
  18. #include <queue>
  19. #include <any>
  20. #define Yellow_Flash \
  21.   ios_base::sync_with_stdio(0); \
  22.   cin.tie(0); \
  23.   cout.tie(0)
  24. #define pi 3.14159265358979323
  25. #define el "\n"
  26. #define ll long long
  27. #define sp ' '
  28. #define MAXI INT_MAX
  29. #define MAXL LLONG_MAX
  30. #define MINI INT_MIN
  31. #define MINL LLONG_MIN
  32. #define all(_) _.begin(), _.end()
  33. #define rall(_) _.rbegin(), _.rend()
  34. #define input(_) \
  35.   for (auto &i : _) \
  36.   cin >> i;
  37. #define output(_) \
  38.   for (auto &i : _) \
  39.   cout << i << sp;
  40. #define uniq(_) _.erase(unique(all(_)), _.end())
  41.  
  42. using namespace std;
  43. using namespace __gnu_pbds;
  44.  
  45. typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
  46.  
  47. void YelloW_Flash()
  48. {
  49. #ifndef ONLINE_JUDGE
  50. freopen("input.txt", "r", stdin);
  51. freopen("output.txt", "w", stdout);
  52. #endif
  53. Yellow_Flash;
  54. }
  55.  
  56. class Array {
  57. private :
  58. int size;
  59. int len;
  60. int * myarray;
  61. public :
  62. Array(int arrsize){
  63. size=arrsize;
  64. len=0;
  65. myarray= new int [arrsize];
  66. }
  67. void Fill(){
  68. cout << "Enter number of items you will insert" << el;
  69. int n;
  70. cin >> n;
  71. if(n>size) {
  72. cout << "Unvalid number , you can not exceed the size" << el;
  73. return;
  74. }
  75. for(int i=0; i<n; ++i) cin >> myarray[i], len++;
  76. }
  77. void Display(){
  78. for(int i=0; i<len; ++i) cout << myarray[i] << sp;
  79. cout << el;
  80. }
  81. int getlength(){
  82. return len;
  83. }
  84. int getsize(){
  85. return size;
  86. }
  87. };
  88.  
  89.  
  90. int main()
  91. {
  92. Yellow_Flash;
  93. Array a(3);
  94. a.Fill();
  95. a.Display();
  96. cout << "the array length = " << a.getlength() << el;
  97. cout << "the array size = " << a.getsize() << el;
  98. return 0;
  99. }
  100. /* Fight not to be the Winner ,but to be the last one to lose */
  101.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Enter number of items you will insert
Unvalid number , you can not exceed the size

the array length = 0
the array size = 3