fork download
  1. #include <vector>
  2. #include <cstdio>
  3.  
  4. class ABC
  5. {
  6.  
  7. protected:
  8.  
  9. std::vector<char> ABCs;
  10.  
  11. int currentLetter;
  12.  
  13. public:
  14.  
  15. ABC():currentLetter( 0 ){}
  16.  
  17. void AddLetter( char Letter )
  18. {
  19. ABCs.push_back( Letter );
  20. }
  21.  
  22. char getLetter( int position )
  23. {
  24. return ABCs.at( position );
  25. }
  26.  
  27. int getLetterPosition()
  28. {
  29. return currentLetter;
  30. }
  31.  
  32. void setLetterPosition( int newPosition )
  33. {
  34. currentLetter = newPosition;
  35. }
  36.  
  37. };
  38.  
  39. void printSentence( ABC * alphabet, int limit )
  40. {
  41. for( int i = 0; i < limit; i += 2 )
  42. {
  43. printf( "The current letter is %c, the letter after is %c \n", alphabet->getLetter( alphabet->getLetterPosition() ), alphabet->getLetter( alphabet->getLetterPosition() + 1 ) );
  44.  
  45. alphabet->setLetterPosition( alphabet->getLetterPosition() + 2 );
  46. }
  47. }
  48.  
  49. int main()
  50. {
  51. ABC alphabet;
  52. ABC * alphabetPointer = &alphabet;
  53.  
  54. for( char letter = 'a'; letter < 'z'; letter++ )
  55. {
  56. alphabet.AddLetter( letter );
  57. }
  58.  
  59. printf( "%s\n" , "printSentence() with param of four letters." );
  60. printSentence( alphabetPointer, 4 );
  61.  
  62. //again
  63. printf( "%s\n" , "printSentence() with param of six letters." );
  64. printSentence( alphabetPointer, 6 );
  65.  
  66. return 0;
  67. }
Success #stdin #stdout 0.02s 2812KB
stdin
Standard input is empty
stdout
printSentence() with param of four letters.
The current letter is a, the letter after is b 
The current letter is c, the letter after is d 
printSentence() with param of six letters.
The current letter is e, the letter after is f 
The current letter is g, the letter after is h 
The current letter is i, the letter after is j