chiva13

Untitled

Aug 29th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 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 = 50;
  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 create_array(int a, int b)
  25. {
  26.     srand(unsigned int (time(NULL)));
  27.     b++;
  28.     for (short i=0; i<array_lenght; ++i)
  29.     {
  30.         array_num[i]=( a + ((rand()+rand()) % (b - a)));   
  31.     }
  32. };
  33.  
  34. void print_array()
  35. {
  36.     for (short i=0; i<array_lenght; ++i) {
  37.         std::cout << array_num[i] << std::endl;
  38.         for (short j=15; j>-1; --j) {
  39.             std::cout << ( (array_num[i] >> j) & 1);
  40.         }
  41.         std::cout <<"\n" << array_flag[i] << std::endl;
  42.         std::cout << std::endl;
  43.     }  
  44.     std::cout << std::endl;
  45. }
  46.  
  47. void searching()       
  48. {
  49.     int count = 0;
  50.     for (short i=0; i<array_lenght; ++i) {
  51.         if ((array_num[i] & 20) == 20) {
  52.             count = count + 1;
  53.             array_flag[i]=true;
  54.         }
  55.         else{
  56.             array_flag[i]=false;
  57.         }
  58.     }
  59.     cout<<"counter = "<<count << std::endl;
  60. }
  61.  
  62. };
  63.  
  64. class SubClass:public BaseClass
  65. {
  66. private:
  67.     std::string line;
  68. public:
  69. void read_file()
  70. {
  71.    
  72.     std::ifstream ist("input.txt");
  73.     std::getline (ist,line);
  74.     std::cout << "line: " << line <<"\n";
  75. }
  76.  
  77. void remove_vowel()
  78. {
  79.     for (unsigned int i = 0; i < line.length(); i++)
  80.     {
  81.         if ( line[i]=='a' || line[i]=='e' || line[i]=='y' || line[i]=='u' || line[i]=='i' || line[i]=='o')
  82.         {
  83.             for (unsigned int j = (0+i); j < line.length(); j++)
  84.             {
  85.                 line[j]=line[j+1];
  86.             }
  87.             line.pop_back();
  88.             i--;
  89.         }
  90.     }
  91. }
  92.  
  93. void write_file()
  94. {
  95.     std::ofstream ost("output.txt");
  96.     cout<<"line after remove: ";
  97.     for(unsigned int i=0;i<line.length();++i)
  98.     {
  99.         ost<<line[i];  
  100.         cout<<line[i];
  101.     }
  102. }
  103.  
  104. };
  105.  
  106. int main()
  107. {
  108.     BaseClass x;
  109.     x.create_array();  
  110.     x.searching();
  111.     x.print_array();
  112.  
  113.     SubClass y;
  114.     y.read_file();
  115.     y.remove_vowel();
  116.     y.write_file();
  117.  
  118.     return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment