DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 31

Thread: function to draw a rectangle

  1. #16
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    What is your logic for the Draw_Rectangle function, using Draw_Top_Bottom and Draw_Middle? [explain in words how your program will determine what character to draw]

  2. #17
    Join Date
    Mar 2008
    Posts
    62
    all that info is my first post of this subject

  3. #18
    Join Date
    Aug 2005
    Location
    Melbourne...Australia
    Posts
    279
    You have a discrepancy between your Draw_Middle declaration and definition! You will need to make sure you define it as taking one parameter!

  4. #19
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    jim -

    What I was asking you to put into words is how you are going to code your Draw_Rectangle function, which drives the drawing of the rectangle. This function has to decide what character to output to the console, whether "-" or "|" or the character input by the user, based on the value of width and height and "where" (which row, which column) the output is in that box. You have to code the logic or approach which permits your program to do it properly. This information is not in the specifications ... it is the part that you have to implement.

  5. #20
    Join Date
    Mar 2008
    Posts
    62
    I am really not sure how I am going to cdoe the draw rectangle part yet. Functions are very new to me and having a hard time with this problem as it is. All I know is we are not allowed to use arrays yet. But to answer your question this may or may not be the answer to what you asked but it all depends on the character

  6. #21
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    No need for arrays for this. What you will need is a loop - the sentinel value being the number of rows If the row is either the first or the last, the code should call Draw_Top_Bottom, passing in the width of the row; otherwise the code should call Draw_Middle passing in all required arguments.

  7. #22
    Join Date
    Mar 2008
    Posts
    62
    I got my parameters to match up if I did them right but I am kinda confused on how to set up the loop

    #include <iostream>
    using namespace std;
    char Get_Character();
    int Get_Number();
    void Draw_Rectangle(int height, int width, char symbol);
    void Draw_Top_Bottom(int width);
    void Draw_Middle(char symbol);

    int main()
    {

    int height, width;
    char symbol;


    cout << "Programmed by Jim Johnson";
    cout << endl << endl;

    cout << "Type a negative for the height to exit!";
    cout << endl;

    cout << "Enter the height: ";
    height = Get_Number();

    if (height < 0)
    {
    exit(1);
    }

    else

    cout << "Enter the width: ";
    width = Get_Number();

    cout << "Enter the character to fill the rectangle with: ";
    symbol = Get_Character();

    Draw_Rectangle(height, width, symbol);

    return 0;
    }


    int Get_Number()
    {
    int x;
    bool inputInvalid = true;
    while (inputInvalid)
    {

    cin >> x;


    if (x == 0 || x == 1 || x == 2)
    {
    cout << "Invalid!! Height can not be less than 3." << endl << "Type a negative height to exit! Try Again !!!" << endl << "Enter the height: ";
    }
    else
    {
    inputInvalid = false;
    }
    }
    return x;
    }

    void Draw_Rectangle(int width, int height, char symbol)
    {
    Draw_Top_Bottom(width);

    }

    {
    Draw_Middle(symbol)
    }

    void Draw_Top_Bottom(int width)
    {

    for (int count = 1; count <= width; count++)
    cout << '-';
    }

    void Draw_Middle(char symbol)

    {


    }



    char Get_Character()
    {


    for(int col = 0; col < width; ++ col)
    {

    cout << symbol;
    }
    }

  8. #23
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    The specifications for the project, which you posted, requires:

    Draw_Rectangle – The height, width and character are passed into this function. It calls the functions Draw_Top_Bottom and Draw_Middle. Nothing is returned from this function.

    Draw_Top_Bottom – This function accepts an integer as the formal parameter and draws the top (or bottom) of the rectangle. Nothing is returned from this function.

    Draw_Middle – This function accepts the height, width and the filler character as the parameters and prints the rows of the rectangle. Nothing is returned from this function.

    So you need to declare each function with the required number and data types of parameters/arguments - Draw_Rectangle with two ints and a char, Draw_Top_Bottom with one int, and Draw_Middle with two ints and a char.

    Each of these methods needs to have a loop, counting through either rows or columns, from 0 and incrementing the counter as long as it is less than some number. Based on what that counter is, a character passed to cout.

  9. #24
    Join Date
    Aug 2005
    Location
    Melbourne...Australia
    Posts
    279
    Jim it really does appear as if you are making no effort with this at all!

    you have posted basically the same piece of code in every post you have made!

    You haven't made an attempt with the two main functions?

  10. #25
    Join Date
    Mar 2008
    Posts
    62
    code nerd r u f****** kidding me. I have gotten everything done until the function part which I am confused and all you do is make one liner comments being half a world away. Yea real man.

  11. #26
    Join Date
    Mar 2008
    Posts
    62
    instead of using void for draw rectangle, draw middle, and draw top bottom, dont u think string would be a better solution

  12. #27
    Join Date
    Aug 2005
    Location
    Melbourne...Australia
    Posts
    279
    Quote Originally Posted by jimJohnson
    instead of using void for draw rectangle, draw middle, and draw top bottom, dont u think string would be a better solution
    You have been given the specifications of how it should be done by your teacher, so that it how it probably should be done!

    Quote Originally Posted by jimJohnson
    code nerd r u f****** kidding me. I have gotten everything done until the function part which I am confused and all you do is make one liner comments being half a world away. Yea real man.
    Funny stuff dude.. How about you try and code the functions you have left blank for the last 2 pages and we will guide you along the way! Because we are the point where we cannot help you anymore until you provide more code..

    Or are you still waiting for someone to do it for you?

  13. #28
    Join Date
    Mar 2008
    Posts
    62
    ok look this is what I did...I moved the get character after the get number instead of at the end and this is the code I changed it too...

    char Get_Character()
    {
    int height = 0, width = 0;
    char symbol;



    if ((height >= 3) & (width >= 3))
    {

    cout << symbol;
    }
    return symbol;
    }

    I ran a debugging and a break point after the return symbol...it stopped at the line of the return symbol so I know the error has something to do with the return symbol....I checked the instructions and it says for me to return the fill character which is the symbol I believe from in the main....does this show u I am making as good of an effort as I can?

  14. #29
    Join Date
    Mar 2008
    Posts
    62
    I realized I didn't need to check if it is greater than 3 or equal to because this is done in main

    char Get_Character()
    {
    char symbol;

    cout << symbol;

    return symbol;
    }

    Still however debugging at the same place I know I have to initialize it but I thought that is always done with integers unless I use a 0 for it too

  15. #30
    Join Date
    Mar 2008
    Posts
    62
    significant changes....I only need help with the height...do I make these changes in the rectangle?

    #include <iostream>
    using namespace std;
    char Get_Character();
    int Get_Number();
    void Draw_Rectangle(int height, int width, char symbol);
    void Draw_Top_Bottom(int width);
    void Draw_Middle(int height, int width, char symbol);

    int main()
    {
    int height, width;
    char symbol;

    cout << "Programmed by Jim Johnson";
    cout << endl << endl;
    cout << "Type a negative for the height to exit!";
    cout << endl;
    cout << "Enter the height: ";

    height = Get_Number();

    if (height < 0)
    {
    exit(1);
    }

    else

    cout << "Enter the width: ";
    width = Get_Number();

    cout << "Enter the character to fill the rectangle with: ";
    symbol = Get_Character();
    cout << endl;

    Draw_Rectangle(height, width, symbol);
    Draw_Top_Bottom(width);
    cout << endl;
    Draw_Middle(height, width, symbol);
    cout << endl;
    Draw_Top_Bottom(width);
    cout << endl << endl;

    return 0;
    }


    int Get_Number()
    {
    int x;
    bool inputInvalid = true;
    while (inputInvalid)
    {

    cin >> x;


    if (x == 0 || x == 1 || x == 2)
    {
    cout << "Invalid!! Height can not be less than 3." << endl << "Type a negative height to exit! Try Again !!!" << endl << "Enter the height: ";
    }
    else
    {
    inputInvalid = false;
    }
    }
    return x;
    }

    char Get_Character()
    {
    char symbol = 0;

    cin >> symbol;

    return symbol;
    }

    void Draw_Rectangle(int width, int height, char symbol)
    {




    }

    void Draw_Top_Bottom(int width)
    {

    for (int count = 1; count <= width; count++)
    cout << '-';
    }

    void Draw_Middle(int height, int width, char symbol)

    {
    for (int count = 1; count <= height; count++)
    cout << symbol;

    }

Similar Threads

  1. Replies: 8
    Last Post: 03-08-2003, 07:25 PM
  2. Replies: 2
    Last Post: 06-05-2001, 01:55 PM
  3. calling ping thru vb
    By Michael Shutt in forum VB Classic
    Replies: 6
    Last Post: 04-05-2001, 02:25 AM
  4. How do I detect an FTP timeout?
    By Julian Milano in forum VB Classic
    Replies: 0
    Last Post: 08-10-2000, 09:16 PM
  5. Trying to print a PDF File from VB
    By Kunal Sharma in forum VB Classic
    Replies: 2
    Last Post: 04-25-2000, 03:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center