Thread: hollowing squares

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    7

    hollowing squares

    Foa a bonus question. /*My professior asked us to write a program which outputs a hollow square*/

    Example: ****
    ****
    ****
    ****

    OR ******
    * *
    * *
    * *
    ******

  2. #2
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    /* uhh, like this? */

    Code:
    for(int i = 0; i < 5; i ++)
        for(int t = 0; t < 5; t ++)
              cout << '*';
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    No, more like this:
    Code:
    #include <iostream>
    #include <iomanip>
    
    using std::cout;
    using std::endl;
    using std::setw;
    using std::setfill;
    
    int main()
    {
      int h = 5;
    
      cout<< setw ( h * 2 ) << setfill ( '*' ) <<""<<endl;
    
      for ( int i = 0; i < h; i++ )
        cout<<'*'<< setw ( h * 2 - 1 ) << setfill ( ' ' ) <<'*'<<endl;
    
      cout<< setw ( h * 2 ) << setfill ( '*' ) <<""<<endl;
    }
    -Prelude
    My best code is written with the delete key.

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    here is a more noobie type approach...

    Code:
    int main()
    {
                    int size;
    	cout << "Enter the box size ";
    	cin >> size;
    	cout << endl;
    	for(int i = 0; i < size; i++)
    		cout << "* ";
    	cout << endl;
    	for(int i = 0;i < size-2; i++) {
    		for(int j = 0;j <= size; j++) {
    			if(j%size == 0)
    				cout << '*';
    			else if(j == size-1)
    				cout << ' ';
    			else
    				cout << "  ";
    		}
    		cout << endl;
    	}
    	for(int i = 0; i < size; i++)
    		cout << "* ";
    		
    	return 0;
    }

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    so have we resorted to doing people's homework for them?

    I don't mind helping if code is posted with an attempt

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >so have we resorted to doing people's homework for them?
    Only if I'm sure that their instructor would refuse to take my code (ie. too sophisticated of a solution, uses features that haven't been taught yet, uses restricted features, obviously not written by the student).

    -Prelude
    My best code is written with the delete key.

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by Prelude
    >so have we resorted to doing people's homework for them?
    Only if I'm sure that their instructor would refuse to take my code (ie. too sophisticated of a solution, uses features that haven't been taught yet, uses restricted features, obviously not written by the student).

    -Prelude
    okay, that makes sense.

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    Originally posted by Prelude

    Only if I'm sure that their instructor would refuse to take my code (ie. too sophisticated of a solution, uses features that haven't been taught yet, uses restricted features, obviously not written by the student).
    Still have your "triangle" code somewhere on a CD and I confess to doing some "scrambling" on that one. Very sweet.

    This one's playing it a little "closer to the vest", though, isn't it?

    Not a criticism, but more an opportunity to say that it's great having you back! And, you didn't return the optional zero. (Pardon me for waxing nostalgic... )

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  9. #9
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Originally posted by Prelude
    >so have we resorted to doing people's homework for them?
    Only if I'm sure that their instructor would refuse to take my code (ie. too sophisticated of a solution, uses features that haven't been taught yet, uses restricted features, obviously not written by the student).

    -Prelude
    Or maybe he'll (she'll) get a better grade for the advanced concepts, heh.

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generating an image of squares?
    By vopo in forum C# Programming
    Replies: 3
    Last Post: 10-21-2008, 10:15 AM
  2. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  3. pass error before char
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 03-26-2006, 12:00 PM
  4. Magic Squares!
    By ZAM777 in forum C++ Programming
    Replies: 1
    Last Post: 04-28-2004, 03:34 PM
  5. perfect squares?
    By ahalya in forum C++ Programming
    Replies: 2
    Last Post: 10-14-2001, 09:38 PM