Question

In: Computer Science

Draw a simplified star-stripe flag using star (*) and equal (=) characters, such as: ****====== ****======...

Draw a simplified star-stripe flag using star (*) and equal (=) characters, such as:

****======
****======
****======
****======
==========
========== 
  

The user can choose how the flag should look like. But there are following restrictions:

  • The width of the flag is between 5 and 70 (inclusive);
  • The height of the flag is between 5 and the width of the flag (inclusive);
  • The star area is placed at the upper left corner of the flag;
  • The star area is a square and its width must be smaller than the height of the flag;
  • There must be at least one star.

Your task:

Design and implement a C++ program that performs the following steps:

  • keep asking user to enter the width of a flag until a valid width is entered;
  • keep asking user to enter the height of a flag until a valid height is entered;
  • keep asking user to enter the width of the star area until a valid number is entered;
  • draw (display) the flag based on the user input.

One of the purpose of this assignment is to practice the modular design. Your program should have at least one function that can be used by the first 3 steps of above tasks.

Solutions

Expert Solution

Answer.

Step 1

Program Code:

#include<iostream>
#include<math.h>
using namespace std;
class Flag
{
int flagWidth, flagHeight;
int starArea;
public:
void read() // function to read flag height, width and star area
{
bool valid = false;
do {
// prompt user to enter an int between 5 and 70
cout<<"Enter the flag width (between 5-70): ";
cin>>flagWidth;
// if the number entered is valid, set done to exit the loop   
if (flagWidth >=5 && flagWidth <= 70) {
valid = true;
}
} while (!valid);
valid = false;
do {
// prompt user to enter an int between 5 and flagWidth
cout<<"Enter the flag height (between 5-flagwidth): ";
cin>>flagHeight;
// if the number entered is valid, set done to exit the loop
if (flagHeight >=5 && flagHeight <= flagWidth) {
valid = true;
}
} while (!valid);
valid = false;
do {
// prompt user to enter star area
cout<<"Enter the star area (must be square and smaller than flagHeight): ";
cin>>starArea;
// if the number entered is valid, set done to exit the loop
if (starArea < flagHeight) {
valid = true;
}
} while (!valid);
}
  
void display() // display the output
{
for(int i=1; i<=flagHeight;i++)
{
for(int j=1; j<=flagWidth;j++)
{
if(i<=starArea&&j<=starArea)
cout<<"*";
else
cout<<"=";
}
cout<<endl;
}
}
};
int main()
{
Flag d;
d.read();
d.display();
}

Step 2

Screenshot of code:



Output:

Thank you.


Related Solutions

Draw a simplified star-stripe flag using star (*) and equal (=) characters, such as: ****====== ****======...
Draw a simplified star-stripe flag using star (*) and equal (=) characters, such as: ****====== ****====== ****====== ****====== ========== ========== The user can choose how the flag should look like. But there are following restrictions: The width of the flag is between 5 and 70 (inclusive); The height of the flag is between 5 and the width of the flag (inclusive); The star area is placed at the upper left corner of the flag; The star area is a square...
Draw an American Flag in Python turtle Height A=1 Width B=1.9 Blue C=0.5385 D=0.76 Star Pattern...
Draw an American Flag in Python turtle Height A=1 Width B=1.9 Blue C=0.5385 D=0.76 Star Pattern E=F=0.0538 G=H=0.0633 Strips K=0.0633 L=0.0769
Why was Eio eager to promote the subsidiary initiative of licensing Star Wars characters for LEGO...
Why was Eio eager to promote the subsidiary initiative of licensing Star Wars characters for LEGO toys? Why was there so much resistance from the headquarters initially? If you were a subsidiary manager at a multinational, what are the lessons you can draw from this case that can help you successfully convince the headquarters that your ideas deserve to be supported?
Question 2. a) What are the differences between element, crystal and mineral? Draw the simplified crystal...
Question 2. a) What are the differences between element, crystal and mineral? Draw the simplified crystal system shapes. b) Write the physical properties of minerals and mohs hardness scale.
Q. Given a document with 32 distinct characters, with equal number of occurrences of each, what...
Q. Given a document with 32 distinct characters, with equal number of occurrences of each, what would be the ratio of the length of the Huffman coded document to the original, if each character in the input was coded in 8 bits? Show your analysis.
What is the gravitational lensing signature of a planet orbiting a star? Draw a picture of...
What is the gravitational lensing signature of a planet orbiting a star? Draw a picture of the spatial relationship between the star being lensed, the planet, and the star around which the planet is orbiting. Also, draw a typical light curve showing how the planet manifests itself.
Which, if any, of the following is an advantage of using the simplified method for determining...
Which, if any, of the following is an advantage of using the simplified method for determining the office use of a home deduction compared to using the regular method? a. No depreciation on computer equipment used in the office has to be computed using the simplified method. b. The exclusive use requirement does not have to be met if the simplified method is used. c. The simplified method allows the taxpayer to avoid issues that arise in allocating expenses of...
You are to construct a star schema for Simplified Automobile Insurance Company. The relevant dimensions, dimension attributes, and dimension sizes are as follows:
Modern Database Management, 13th EditionJeff Hoffer9-39. You are to construct a star schema for Simplified Automobile Insurance Company. The relevant dimensions, dimension attributes, and dimension sizes are as follows:InsuredPartyAttributes: InsuredPartyID and Name. There is an average of two insured parties for each policy and covered item.CoverageItemAttributes: CoverageKey and Description. There is an average of 10 covered items per policy.AgentAttributes: AgentID and AgentName. There is one agent for each policy and covered item.PolicyAttributes: PolicyID and Type. The company has approximately 1...
1-a)List the defining characteristics of the Chondrichthyes. b) Draw a simplified phylogenetic tree for cartilaginous fishes...
1-a)List the defining characteristics of the Chondrichthyes. b) Draw a simplified phylogenetic tree for cartilaginous fishes and outline the characteristics of the three main types. 2- Describe the main evolutionary steps involved in the conquest of landmasses by vertebrate organisms during the Devonian period.
In our class example, I simplified the “annuity” prize option by assuming level, equal annual payments....
In our class example, I simplified the “annuity” prize option by assuming level, equal annual payments. Actually, this annuity prize option us now on an annuitized prize payment schedule with 26 beginning of year payments that start at a lower amount with each successive payment being 5% higher than the previous annual payment. The sum of these 26 annuitized payments equal the announced estimated jackpot amount with a lower one-time lump-sum payment also being available as the Cash Option. A...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT