chiva13

Untitled

Aug 29th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <fstream>
  4. #include <string>
  5. #include <ctime>
  6. #include <vector>
  7. using namespace std;
  8. short const array_lenght = 10;  
  9.  
  10. class BaseClass
  11. {
  12. private:
  13.  
  14.     bool array_flag[array_lenght];
  15. public:
  16.  
  17. void create_array(short * array,short const lenght)
  18. {  
  19.     srand(unsigned int (time(NULL)));
  20.     for (short i=0; i<lenght; ++i) {
  21.         array[i] = rand()+rand()- 32768;
  22.     }
  23. }
  24.  
  25. void print_array(short * array, short const array_lenght)
  26. {
  27.     for (short i=0; i<array_lenght; ++i) {
  28.         std::cout << array[i] << std::endl;
  29.         for (short j=15; j>-1; --j) {
  30.             std::cout << ( (array[i] >> j) & 1);
  31.         }
  32.         std::cout << std::endl;
  33.     }  
  34.     std::cout << std::endl;
  35. }
  36.  
  37. void searching( short * array, short const array_lenght )      
  38. {
  39.     int count = 0;
  40.     for (short i=0; i<array_lenght; ++i) {
  41.         if ((array[i]&14) == 14) {
  42.             count = count + 1;
  43.             //bool array_flag[i]=1;
  44.         }
  45.         //else{
  46.             //bool array_flag[i]=0;
  47.         //}
  48.     }
  49.     cout<<"counter = "<<count;
  50. }
  51.  
  52. };
  53.  
  54.  
  55.  
  56. class SubClass:public BaseClass
  57. {
  58. protected:
  59. public:
  60. };
  61.  
  62. int main()
  63. {
  64.     BaseClass x;
  65.     short array[array_lenght];
  66.     x.create_array(array,array_lenght);
  67.     x.print_array(array,array_lenght);
  68.     x.searching(array,array_lenght);
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment