Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. void drawAChristmasTree();
  7.  
  8. cout << "Peter Fletcher - Adams - Due 11 December 2018 \n \n";
  9. drawAChristmasTree();
  10.  
  11. system("pause");
  12. return 0;
  13. }
  14.  
  15. void drawAChristmasTree()
  16. {
  17. void getValidHeight(int&);
  18. void drawFoliage(int&, int&);
  19. void drawTrunk(int&);
  20.  
  21. int treeHeight, branch;
  22.  
  23. getValidHeight(treeHeight);
  24. drawFoliage(treeHeight, branch);
  25. drawTrunk(branch);
  26. }
  27.  
  28. void getValidHeight(int& height)
  29. {
  30. const int MinSize = 4;
  31. const int MaxSize = 20;
  32. cout << "Enter the size of the tree (4-20): ";
  33. cin >> height;
  34. while ((height > MaxSize) || (height < MinSize))
  35. {
  36. cout << "Invalid height! Enter the size of the tree (4-20): ";
  37. cin >> height;
  38. }
  39. }
  40.  
  41. void drawFoliage(int& height, int& branch)
  42. {
  43. void drawALineOfFoliage(int& ,int&);
  44.  
  45. int branchLine(1);
  46.  
  47. do
  48. {
  49. drawALineOfFoliage(height, branch);
  50. branchLine = branchLine + 1;
  51. }
  52. while (branchLine <= (height - 2));
  53. }
  54.  
  55. void drawALineOfFoliage(int& height, int& branch)
  56. {
  57. const char LEAF = '#';
  58. //char randomDecoration;
  59.  
  60. int width(1 + (branch * 2));
  61.  
  62. for (int f = 0; f < (height - branch - 2); f++)
  63. {
  64. cout << " ";
  65. }
  66. for (int f = 0; f < width; f++)
  67. {
  68. cout << "#";
  69. }
  70. cout << "\n";
  71. }
  72.  
  73. void drawTrunk(int& height)
  74. {
  75. int trunkLine, spaces;
  76. const char BLANK = ' ';
  77. const char WOOD = '|';
  78.  
  79. trunkLine = 1;
  80.  
  81. do
  82. {
  83. spaces = 1;
  84. do
  85. {
  86. cout << BLANK;
  87. } while (spaces <= height - 2);
  88. cout << WOOD << "\n";
  89. trunkLine = trunkLine + 1;
  90. } while (trunkLine <= 2);
  91. }
  92.  
  93. /*char randomDecoration()
  94. {
  95.  
  96. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement