By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,148 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,148 IT Pros & Developers. It's quick & easy.

Drawing box in c++

P: 3
Write a C++ program which displays boxes with the following pattern on the screen (here with a width of 9 symbols and a height of 7 symbols). After each box is shown the user is asks if another box is required and the answer read in. The program stops when the answer is not the letter 'Y' (in upper or lowercase).

Expand|Select|Wrap|Line Numbers
  1. #########
  2. #   *   #
  3. #   *   #
  4. #*******#
  5. #   *   #
  6. #   *   #
  7. #########
For each box, the program asks the user for the width and height required. It checks that the values read in are valid (i.e., an odd number between 5 and 25). For each dimension if the data read is invalid a validating function, called getValidDimension, displays an appropriate error message and asks the user for another one until a valid value is read in.
The aims of the exercise are to practice with while & for loops and parameter passing in C++

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>            //for cin >> and cout <<
  2. #include <cassert>            //for assert
  3. #include <conio.h>            //for kbhit
  4. using namespace std;
  5. //declare constants: symbols used for the drawing
  6. const char BLANK = ' ';
  7. const char BOX   = '#';
  8. const char CROSS = '*';
  9. const char EOL   = '\n';
  10. int main()                     //drawCrossedBox
  11. {
  12.     //declare functions used
  13.     //TO BE COMPLETED
  14.     //declare variables
  15.     //TO BE COMPLETED
  16.     while ( answer == 'Y') 
  17.     {
  18.         cout << "\nEnter the width of the box: ";
  19.         width = getValidDimension();
  20.         cout << "\nEnter the height of the box: ";
  21.         height = getValidDimension();
  22.         cout << "\n\n";
  23.         drawHorisontalBoxBorder( width);     //TO BE DEFINED
  24.         drawVerticalCrossBranche( width, height);     //TO BE DEFINED
  25.         drawHorisontalCrossBranches( width);     //TO BE DEFINED
  26.         drawVerticalCrossBranche( width, height);
  27.         drawHorisontalBoxBorder( width);
  28.         checkIfWantAnotherBox( answer);
  29.         answer = toupper(answer);
  30.     }
  31.     cout << "\nEND OF PROGRAM\nPress a key to continue... ";
  32.     while ( !kbhit());        //hold the screen until a key is pressed
  33.     return( 0);
  34. }
Any help plz? i hav tried many wayz n cudnt do it.....
Feb 18 '07 #1
Share this Question
Share on Google+
2 Replies


Ganon11
Expert 2.5K+
P: 3,652
Have you written any of the functions? Have you thought of any ideas to do this?
Feb 18 '07 #2

P: 3
Have you written any of the functions? Have you thought of any ideas to do this?
no...just finkin now
Feb 18 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.