Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <string>
  4. #include <sstream>
  5.  
  6. using namespace std;
  7.  
  8. void drawChars(int size, char character){
  9. for(int j = 1; j <= size; ++j)
  10. {
  11. cout << character;
  12. }
  13. }
  14.  
  15. // size from 2 to 20
  16. void drawTriangle(int size){
  17.  
  18. for(int i = 1; i <= size; ++i)
  19. {
  20. drawChars(i,'X');
  21. cout << "\n";
  22. }
  23. }
  24.  
  25. // size from 2 to 20
  26. void drawSquare(int size){
  27. drawChars(size, 'X');
  28. cout << "\n";
  29.  
  30. for(int i = 2; i < size; ++i)
  31. {
  32. cout << 'X';
  33. for(int j = 2; j < size; ++j)
  34. {
  35. cout << ' ';
  36. }
  37. cout << 'X';
  38.  
  39. cout << "\n";
  40. }
  41.  
  42. drawChars(size, 'X');
  43. cout << "\n";
  44. }
  45.  
  46. // size from 1 to 20
  47. void drawPyramid(int size){
  48. for(int i = 2; i < size; ++i)
  49. {
  50. }
  51. }
  52.  
  53. // size from 1 to 20
  54. void drawChristmasTree(int size){
  55. }
  56.  
  57. // size from 2 to 20
  58. void drawFigureX(int size){
  59. }
  60.  
  61. // size from 2 to 20
  62. void drawFigureY(int size){
  63. }
  64.  
  65. // size from 3 to 20
  66. void drawFigureZ(int size){
  67. }
  68.  
  69. // size from 2 to 20
  70. void drawFigureW(int size){
  71. }
  72.  
  73. bool isCommand(const string command,const char *mnemonic){
  74. return command==mnemonic;
  75. }
  76.  
  77. int main(){
  78. string line;
  79. string command;
  80. int value;
  81. cout << "START" << endl;
  82. while(true){
  83. // cin.getline(line, MAXLINE);
  84. getline(cin,line);
  85. std::stringstream stream(line);
  86. stream >> command;
  87. if(line=="" || command[0]=='#')
  88. {
  89. // ignore empty line and comment
  90. continue;
  91. }
  92.  
  93. // copy line on output with exclamation mark
  94. cout << "!" << line << endl;;
  95.  
  96. // change to uppercase
  97. command[0]=toupper(command[0]);
  98. command[1]=toupper(command[1]);
  99.  
  100. if(isCommand(command,"HA")){
  101. cout << "END OF EXECUTION" << endl;
  102. break;
  103. }
  104.  
  105. // read next argument, one int value
  106. stream >> value;
  107.  
  108. if(isCommand(command,"TR"))
  109. {
  110. drawTriangle(value);
  111. continue;
  112. }
  113. if(isCommand(command,"SQ"))
  114. {
  115. drawSquare(value);
  116. continue;
  117. }
  118. if(isCommand(command,"PY"))
  119. {
  120. drawPyramid(value);
  121. continue;
  122. }
  123. if(isCommand(command,"CT"))
  124. {
  125. drawChristmasTree(value);
  126. continue;
  127. }
  128. if(isCommand(command,"FX"))
  129. {
  130. drawFigureX(value);
  131. continue;
  132. }
  133. if(isCommand(command,"FY"))
  134. {
  135. drawFigureY(value);
  136. continue;
  137. }
  138. if(isCommand(command,"FZ"))
  139. {
  140. drawFigureZ(value);
  141. continue;
  142. }
  143. if(isCommand(command,"FW"))
  144. {
  145. drawFigureW(value);
  146. continue;
  147. }
  148.  
  149. cout << "wrong argument in test: " << command << endl;
  150. }
  151.  
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement