recursion

This is a discussion on recursion within the C++ Programming forums, part of the General Programming Boards category; how can i draw a square using a recursive function???...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    80

    Post recursion

    how can i draw a square using a recursive function???

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    80

    like that

    Code:
    *****
    *   *
    *   *
    *   *
    *****
    ????
    Last edited by condorx; 11-30-2002 at 07:38 AM.

  3. #3
    Spanky devour89's Avatar
    Join Date
    Nov 2002
    Posts
    148
    this is how i draw sqaures:

    Code:
     
    
     #include <iostream>
    
     
    
     // Rectangle class declaration
    
     class Rectangle
    
     {
    
     public:
    
         // constructors
    
         Rectangle(int width, int height);
    
         ~Rectangle(){}
    
     
    
         // overloaded class function DrawShape
    
         void DrawShape() const;
    
         void DrawShape(int aWidth, int aHeight) const;
    
     
    
     private:
    
         int itsWidth;
    
         int itsHeight;
    
     };
    
     
    
     //Constructor implementation
    
     Rectangle::Rectangle(int width, int height)
    
     {
    
         itsWidth = width;
    
         itsHeight = height;
    
     }
    
     
    
     
    
     // Overloaded DrawShape - takes no values
    
     // Draws based on current class member values
    
     void Rectangle::DrawShape() const
    
     {
    
         DrawShape( itsWidth, itsHeight);
    
     }
    
     
    
     
    
     // overloaded DrawShape - takes two values
    
     // draws shape based on the parameters
    
     void Rectangle::DrawShape(int width, int height) const
    
     {
    
         for (int i = 0; i<height; i++)
    
         {
    
             for (int j = 0; j< width; j++)
    
             {
    
                 std::cout << "*";
    
             }
    
             std::cout << "\n";
    
         }
    
     }
    
     
    
     // Driver program to demonstrate overloaded functions
    
     int main()
    
     {
    
         // initialize a rectangle to 30,5
    
         Rectangle theRect(30,5);
    
         std::cout << "DrawShape(): \n";
    
         theRect.DrawShape();
    
         std::cout << "\nDrawShape(40,2): \n";
    
         theRect.DrawShape(40,2);
    
         return 0;
    
     }
    Dev C++
    Win XP/2k/98

    I DO NOT TAKE CLASSES I DONT GET HOMEWORK THIS IS NOT A HOMEWORK QUESTION!!!

    He's lean he's keen... He's the spank machine!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Template Recursion Pickle
    By SevenThunders in forum C++ Programming
    Replies: 20
    Last Post: 02-05-2009, 09:45 PM
  2. Recursion... why?
    By swgh in forum C++ Programming
    Replies: 4
    Last Post: 06-09-2008, 10:37 AM
  3. a simple recursion question
    By tetra in forum C++ Programming
    Replies: 6
    Last Post: 10-27-2002, 10:56 AM
  4. To Recur(sion) or to Iterate?That is the question
    By jasrajva in forum C Programming
    Replies: 4
    Last Post: 11-07-2001, 09:24 AM
  5. selection sorting using going-down and going-up recursion
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-02-2001, 02:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21