chiva13

Untitled

Aug 29th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 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. class BaseClass
  10. {
  11. private:
  12. short array_num[array_lenght];
  13. bool array_flag[array_lenght];
  14. public:
  15.  
  16. void create_array()
  17. {
  18. srand(unsigned int (time(NULL)));
  19. for (short i=0; i<array_lenght; ++i) {
  20. array_num[i] = rand()+rand()- 32768;
  21. }
  22. }
  23.  
  24. void print_array()
  25. {
  26. for (short i=0; i<array_lenght; ++i) {
  27. std::cout << array_num[i] << std::endl;
  28. for (short j=15; j>-1; --j) {
  29. std::cout << ( (array_num[i] >> j) & 1);
  30. }
  31. std::cout <<"\n" << array_flag[i] << std::endl;
  32. std::cout << std::endl;
  33. }
  34. std::cout << std::endl;
  35. }
  36.  
  37. void searching()
  38. {
  39. int count = 0;
  40. for (short i=0; i<array_lenght; ++i) {
  41. if ((array_num[i]&14) == 14) {
  42. count = count + 1;
  43. array_flag[i]=true;
  44. }
  45. else{
  46. array_flag[i]=false;
  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. x.create_array();
  66. x.print_array();
  67. x.searching();
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment