How to Print Hollow shapes
Sep 13, 2014 at 3:32am UTC
As the title says, what is the concept of printing out hollow shapes?
Sep 13, 2014 at 4:34am UTC
You need to be way more specific.
Sep 13, 2014 at 4:36am UTC
sorry about that, how would i print out a hollow diamond, rectangle, etc.
Sep 13, 2014 at 5:15am UTC
LOL....
I'm sorry is this what you mean?
this is a hollow square:
1 2 3 4 5
cout << "***************" << endl;
for (int i = 0; i < 6; i++){
cout << "* *" << endl;
}
cout << "***************" << endl;
Last edited on Sep 13, 2014 at 6:17am UTC
Sep 13, 2014 at 6:18am UTC
Sorry for laughing at this post...It was just way to vague...Please refer to my previous post in regards to your question.
Sep 13, 2014 at 6:59am UTC
The concept of printing hollowed out shapes is to print only outline, filling inside of your shape with whitespace characters.
Sep 13, 2014 at 4:06pm UTC
nice, yours was the first was that actually worked for me. what about a vertical diamond?
Sep 13, 2014 at 4:12pm UTC
Vertical diamond like:
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
You might notice that on each line there is two things you need to know/calculate: amount of whitespaces before first star and amount of whitespaces between first and second star.
Also you need to handle first and last lines (where only on star present).
FOr starters fugure out how to get amount of whitespaces from diamond size and line number.
Sep 13, 2014 at 7:40pm UTC
okay im getting the hang of this. i just need to know how i could put different shapes side by side. instead of one below the other?
Sep 13, 2014 at 8:02pm UTC
That's going to be a bit more difficult. You are going to need to output the row for all the shapes.
So if you wanted 2 square for instance it would be something like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Example program
#include <iostream>
#include <string>
int main()
{
int width = 4;
int height = 4;
std::cout << std::string(width, '*' ) + std::string(width, '*' ) << '\n' ;
for (int i = 0; i < height - 2; ++i)
{
std::string row = std::string(width, ' ' );
row[0] = '*' ;
row[width-1] = '*' ;
std::cout << row + row << '\n' ;
}
std::cout << std::string(width, '*' ) + std::string(width, '*' ) << std::endl;
}
********
* ** *
* ** *
********
Sep 13, 2014 at 8:41pm UTC
ok thanks everyone , i ended up finishing it
Topic archived. No new replies allowed.