This is the code so far #include // for cin and cout #include // for setw() and setfill() using namespace std; // so that we don't need to preface every cin and cout with std:: void printSpaces(int n, int end) { for (int j = n; j > end; j--) { cout << " "; } } void printFirstTwoBuildingSection(int n, int startSpacing) { int start = 2 * ((n / 2) - 1), end = 0; for (int i = 0; i < n; i++) { printSpaces(startSpacing, 0); cout << "|"; if (i < (n / 2)) { printSpaces(i, 0); cout << "\\"; printSpaces(start, 0); cout << "/"; start -= (2); printSpaces(i, 0); cout << "|" << endl; } else { printSpaces(n - i - 1, 0); cout << "/"; printSpaces(end, 0); cout << "\\"; end += (2); printSpaces(n - i - 1, 0); cout << "|" << endl; } } printSpaces(startSpacing, 0); cout << "/"; for (int i = 0; i < n; i++) { cout << "-"; } cout << "\\" << endl; } int main() { int menuOption = 0; cout << "Choose from among the following options:\n" << "1. Exit the program\n" << "2. Display building\n" << "Your choice -> "; cin >> menuOption; cout << endl; // Leave a blank line after getting the user input for the menu option. // See if exit was chosen if (menuOption == 1) { exit(0); } // Menu 2 if (menuOption == 2) { int sections; cout << "Number of building sections -> "; cin >> sections; int n = 1 - (sections - 2) + sections * 2; int sizeOfBuild = 2; cout << setw(n) << " /\\ " << endl; cout << setw(n) << " || " << endl; cout << setw(n) << " || " << endl; cout << setw(n) << " -- " << endl; cout << setw(n) << "|++|" << endl; cout << setw(n) << "====" << endl; for (int i = 1; i <= sections; i++, sizeOfBuild += 2) { printFirstTwoBuildingSection(sizeOfBuild, sections - i); } } cout << endl; return 0; }

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter16: Graphics
Section: Chapter Questions
Problem 5PE
icon
Related questions
Question

This is the code so far

#include <iostream> // for cin and cout
#include <iomanip> // for setw() and setfill()
using namespace std; // so that we don't need to preface every cin and cout with std::


void printSpaces(int n, int end)
{
for (int j = n; j > end; j--)
{
cout << " ";
}
}
void printFirstTwoBuildingSection(int n, int startSpacing)
{
int start = 2 * ((n / 2) - 1), end = 0;
for (int i = 0; i < n; i++)
{
printSpaces(startSpacing, 0);
cout << "|";
if (i < (n / 2))
{
printSpaces(i, 0);
cout << "\\";
printSpaces(start, 0);
cout << "/";
start -= (2);
printSpaces(i, 0);
cout << "|" << endl;
}
else
{
printSpaces(n - i - 1, 0);
cout << "/";
printSpaces(end, 0);
cout << "\\";
end += (2);
printSpaces(n - i - 1, 0);
cout << "|" << endl;
}
}
printSpaces(startSpacing, 0);
cout << "/";
for (int i = 0; i < n; i++)
{
cout << "-";
}
cout << "\\" << endl;
}
int main()
{
int menuOption = 0;

cout << "Choose from among the following options:\n"
<< "1. Exit the program\n"
<< "2. Display building\n"
<< "Your choice -> ";
cin >> menuOption;
cout << endl; // Leave a blank line after getting the user input for the menu option.

// See if exit was chosen
if (menuOption == 1)
{
exit(0);
}

// Menu 2

if (menuOption == 2)
{
int sections;
cout << "Number of building sections -> ";
cin >> sections;
int n = 1 - (sections - 2) + sections * 2;
int sizeOfBuild = 2;
cout << setw(n) << " /\\ " << endl;
cout << setw(n) << " || " << endl;
cout << setw(n) << " || " << endl;
cout << setw(n) << " -- " << endl;
cout << setw(n) << "|++|" << endl;
cout << setw(n) << "====" << endl;
for (int i = 1; i <= sections; i++, sizeOfBuild += 2)
{
printFirstTwoBuildingSection(sizeOfBuild, sections - i);
}
}

cout << endl;
return 0;
}

5. Add the code to also display the tower base. The tower base width should be two
characters wider on each edge than the bottom-most building section, with the sections
above it centered above the base. Running your program again choosing 3 sections
should now look like the following:
Choose from among the following options:
1. Display original graphic
2. Display building
3. Exit the program
Your choice -> 2
Number of building sections -> 3
|++|
|--\
|\ /|
| V |
|ハ|
|/ \|
/----\
|
|
| /\|
\|
|------\
+++
Transcribed Image Text:5. Add the code to also display the tower base. The tower base width should be two characters wider on each edge than the bottom-most building section, with the sections above it centered above the base. Running your program again choosing 3 sections should now look like the following: Choose from among the following options: 1. Display original graphic 2. Display building 3. Exit the program Your choice -> 2 Number of building sections -> 3 |++| |--\ |\ /| | V | |ハ| |/ \| /----\ | | | /\| \| |------\ +++
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning