3. Now prompt for user input for the number of building sections. For now assume the user types in 2 in response to this prompt, as shown below: Choose from among the following options: 1. Exit the program 2. Display building Your choice -> 2 Number of building sections -> 2 Modify your program so that instead of hard-coding each line of output for each section, you use a for or while loop to display the lines in each section. Think of each line as having the following pieces: 1. Number of leading spaces (so that it ends up being centered) 2. The left wall ' 3. Some number of spaces 4. The first angle piece, which should be ' if you are in the top half of the section or should be '" if you are in the bottom half of the section. 5. Some number of spaces 6. The second angle piece, which should be '/' if you are in the top half of the section or should be "' if you are in the bottom half of the section. 7. Some number of spaces 8. The right wall ' Some of the above steps involve displaying multiple spaces. You can do this using a loop, or you can use, for example cout <« setw( 5) <« "|"; which would display the ' |' character right-justified within a field width of 5 characters. Running your program should now give the following output, where all building sections are centered above the bottom section:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Code so far is this.

 

// @brief Program 1 - ASCII Building
// REPLACE ME AND THE LINES AROUND ME!
// Adapted from prior programs developed by Professor Reed.

/* Running the program looks like:
Choose from among the following options:
1. Exit the program
2. Display building
Your choice -> 1
*/

#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 printFirstTwoBuildingSection(int n, int startSpacing)
{
int start = n / 2, end = 0;
if (n <= 2)
{
start = 0;
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < startSpacing; j++)
{
cout << " ";
}
cout << "|";
if (i < (n / 2))
{
for (int k = 0; k < i; k++)
{
cout << " ";
}
cout << "\\";
for (int k = 0; k < start; k++)
{
cout << " ";
}
cout << "/";
start -= (n / 2);
for (int k = 0; k < i; k++)
{
cout << " ";
}
cout << "|" << endl;
}
else
{
for (int k = n - i - 1; k > 0; k--)
{
cout << " ";
}
cout << "/";
for (int k = 0; k < end; k++)
{
cout << " ";
}
cout << "\\";
end += (n / 2);
for (int k = n - i - 1; k > 0; k--)
{
cout << " ";
}
cout << "|" << endl;
}
}
for (int j = 0; j < startSpacing; j++)
{
cout << " ";
}
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)
{
cout << " /\\ " << endl;
cout << " || " << endl;
cout << " || " << endl;
cout << " -- " << endl;
cout << " |++|" << endl;
cout << " ====" << endl;
printFirstTwoBuildingSection(2, 1);
printFirstTwoBuildingSection(4, 0);
}

cout << endl;
return 0;
}

 

 

3. Now prompt for user input for the number of building sections. For now assume the user
types in 2 in response to this prompt, as shown below:
Choose from among the following options:
1. Exit the program
2. Display building
Your choice -> 2
Number of building sections -> 2
Modify your program so that instead of hard-coding each line of output for each section,
you use a for or while loop to display the lines in each section. Think of each line as
having the following pieces:
1. Number of leading spaces (so that it ends up being centered)
2. The left wall '"
3. Some number of spaces
4. The first angle piece, which should be ' if you are in the top half of the section or
should be '/' if you are in the bottom half of the section.
5. Some number of spaces
6. The second angle piece, which should be '/' if you are in the top half of the section
or should be "' if you are in the bottom half of the section.
7. Some number of spaces
8. The right wall 'T
Some of the above steps involve displaying multiple spaces. You can do this using a
loop, or you can use, for example
cout <« setw ( 5) << " |";
which would display the '|' character right-justified within a field width of 5
characters.
Running your program should now give the following output, where all building
sections are centered above the bottom section:
Transcribed Image Text:3. Now prompt for user input for the number of building sections. For now assume the user types in 2 in response to this prompt, as shown below: Choose from among the following options: 1. Exit the program 2. Display building Your choice -> 2 Number of building sections -> 2 Modify your program so that instead of hard-coding each line of output for each section, you use a for or while loop to display the lines in each section. Think of each line as having the following pieces: 1. Number of leading spaces (so that it ends up being centered) 2. The left wall '" 3. Some number of spaces 4. The first angle piece, which should be ' if you are in the top half of the section or should be '/' if you are in the bottom half of the section. 5. Some number of spaces 6. The second angle piece, which should be '/' if you are in the top half of the section or should be "' if you are in the bottom half of the section. 7. Some number of spaces 8. The right wall 'T Some of the above steps involve displaying multiple spaces. You can do this using a loop, or you can use, for example cout <« setw ( 5) << " |"; which would display the '|' character right-justified within a field width of 5 characters. Running your program should now give the following output, where all building sections are centered above the bottom section:
Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Concept of memory addresses in pointers
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education