473,385 Members | 1,427 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,385 software developers and data experts.

A fun but difficult program

10
For this assignment you will write a function which takes as parameters the upper left corner of a button and a string representing the "label" of the button. The function will write the label to the screen with a rectangle drawn around it. The upper left hand corner of the rectangle will be the point sent to the function as a parameter. The declaration of the function is as follows:
//! \brief Draw a button in the drawing window at the specified
//! location with the specified label.
//! \param upper_left The upper left hand corner of the button.
//! \param label The text which appears inside the button.
//! \return Void.
void draw_button( const Point & upper_left, const std::string label );


You will then write a main ( ccc_win_main ) program which tests your function. The main function will set up the graphic window so the upper left hand corner is at the point ( 0, 0 ) and the lower right hand corner is at the point ( 100, 100 ). It will then prompt the user to click on a point in the window where they want the button to be drawn. After a point is entered by the user, the program will prompt the user to enter a string that should be the label of the button. You do not have to be able to handle multiple word strings, a single word is sufficient.

Once the position and label of the button have been obtained from the user, the screen should be cleared and the new button should be displayed in the graphic window by calling the draw_button function. Your program should continue prompting the user for a new location and a label for the button, and drawing the button in the graphic window until the user types "quit" as the button label.

When the user types "quit" as the button label, the program will draw the button with "quit" as its label and terminate. It is OK if the graphic window remains displayed on the computer screen.
Button Specification

When a Message object is displayed in the graphic window it is always the same size regardless of the coordinate system that has been set up with the cwin.coord( ... ) function. This makes it quite difficult to draw objects and text together in a way that is independent of the coordinate system being used. For this reason, amoung others, in every remaining assignment which uses the graphic window we will fix the graphic windows upper left hand corner at the point ( 0, 0 ) and its lower right hand corner at the point ( 100, 100 ).

Since we are permanently setting the size of the graphic window, we can define some constants which represent how wide and how tall a letter is when it is written in the graphic window. These constants are defined in the file global_const.h which is being provided to you. The constants defined in global_const.h that you will be interested in for this assignment are:

WINDOW_WIDTH
The width of the graphic window.
WINDOW_HEIGHT
The height of the graphic window.
UPPER_LEFT
The upper left coordinate of the graphic window.
LOWER_RIGHT
The lower right coordinate of the graphic window.
LETTER_WIDTH
The width of a letter in the graphic window.
LETTER_HEIGHT
The height of a letter in the graphic window.

To use these constants you simply need to sharp include "global_const.h" at the top of your file.

Since we know the width and height of an individial letter, we can draw the border of the button so that the label is completely contained within the border regardless of the length of the label. When the program draws the rectangle that is the border of the button, the rectangle should be a total of 1 LETTER_WIDTH wider than the label, and 1 LETTER_HEIGHTs higher than the label. The label should be centered in the rectangle. Placing the upper left hand conter of the label half a LETTER_WIDTH to the right, and a quarter of a LETTER_HEIGHT lower than the upper left hand corner of the border of the button centers the label quite nicely.

Assignment Framework
main.cpp
Use this file to implement the draw_button( ... ) function and your main function.
Makefile
Your makefile must use the options specified in the class coding standard. The first rule in the makefile shall have a target name of "all" and will compile the program with the default executable name of "a.out". Your makefile must also have a rule with a target name of "clean" which removes the executable and any backup files that were generated by your editor. You should always "make clean" before turning in your assignment.
global_const.h
Oct 17 '06 #1
0 1849

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

Similar topics

54
by: Spammay Blockay | last post by:
I've been tasked with doing technical interviews at my company, and I have generally ask a range of OO, Java, and "good programming technique" concepts. However, one of my favorite exercises I...
12
by: Mike Dee | last post by:
A very very basic UTF-8 question that's driving me nuts: If I have this in the beginning of my Python script in Linux: #!/usr/bin/env python # -*- coding: UTF-8 -*- should I - or should I...
5
by: Nick Keighley | last post by:
Hi, In the beginning the code was:- BRUSHH new_brush = create_brush() BRUSHH old_brush = select_brush (new_brush) draw(...) select_brush (old_brush) destroy_brush (new_brush)
8
by: shan | last post by:
I have tried writing a program which should 1)get a number from user 2)calculate the following for e.g if the input is 3 then 3 3 3 and the answer should be 19683. 3)similarly when the...
7
by: Manu | last post by:
Hi! All I was wondering what is the most difficult part of windows programming Is it Network Programming Etc..
0
by: tom | last post by:
Hallo, I need help on MIDI file, and precisely about retrieving few note values (mainly the "Velocity" value, corrisponding to the intensity of a played note) while the MIDI is playing.
2
by: Eniac | last post by:
*argh* ... *pull hairs* I've recently started developing from ASP to ASP.NET The switch was fairly smooth since i had done some VB.net before ... then came...FORMS! :) I find it astounding...
4
by: Laserson | last post by:
Hi all! I have a very difficult task for me and i can't so it. My task: I have created an application. But how to determine that it is not responding??? You can see it when windows add "Not...
6
by: Jacob Rael | last post by:
Hello, I have a simple script to parse a text file (a visual basic program) and convert key parts to tcl. Since I am only working on specific sections and I need it quick, I decided not to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.