473,321 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Drawing box in c++

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
2 2855
Ganon11
3,652 Expert 2GB
Have you written any of the functions? Have you thought of any ideas to do this?
Feb 18 '07 #2
Have you written any of the functions? Have you thought of any ideas to do this?
no...just finkin now
Feb 18 '07 #3

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

Similar topics

0
by: Tomi Holger Engdahl | last post by:
I am looking for a solution to add on-line drawing tool to a phpBB discussion board. The idea would be that the users can draw their own simple drawings with the tool and attach them easily as...
2
by: Champika Nirosh | last post by:
Hi, I want to create drawing board application that can draw Line, rectagle, circle and free hand drawing. Each drawing need to be transparent, moveable (draggable), have bring to front and...
1
by: Hadar | last post by:
Hi, I'm getting "object is currently in use elsewhere" when I use System.Drawing.Graphics.MesureString. This is what I do: My controls use a utility class the helps it to mesure strings. To...
7
by: Marc Pelletier | last post by:
Hello all, I have a class which includes a method to create a chart. I want to be able to call this method from asp.net code as well as windows application code, so I have sketched it out as...
2
by: active | last post by:
I find Bitmap.Save works for WMF files but Bitmap.FromFile does not. If I use FromFile on a WMF file that came with VS I get an exception. If I use it on a WMF file created with Bitmap.Save I...
3
by: Chris Saunders | last post by:
I am fairly new to .Net and C# but am familiar with the Win32 API. I wish to set the pixels of the client area of a window one at a time with a specific color. I have so far discovered that...
5
by: Jerry J | last post by:
I want to use the System.Drawing.Image class. According to the help file, this is an abstract base class. Because it is supposedly abstract, I created another class that inherits from it. However,...
1
by: YouPoP | last post by:
I am doing an app (C# 2.0) where you can draw in a panel with your mouse in "real time". I actually have 2 problems; 1- it does not really is "real time", if your mouse move fast or very fast the...
2
by: ThatsIT.net.au | last post by:
I have this code that writes a pie chart in a asp.net page, but I want to use it in a server control. When I try I get a error on the last line "Response.OutputStream" Obviously there is no...
7
by: raylopez99 | last post by:
I have a logical drawing space much bigger than the viewport (the screen) and I'd like to center the viewport (the screen) to be at the center of the logical drawing space. After following the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.