Assignment #1
Due: Fri, Sept 16
Objectives
- To practice with writing a small C++ main() program, along with
compiling and running it
- To practice with basic C++ input/output features, along with some
simple decimal formatting
- To practice with basic arithmetic operators in C++
Task
Create a program (Filename: paint.cpp) that will
calculate the amount of paint needed to cover
one side of a house with a sloped roof.
- Assume that this side wall of the house is generally shaped as in the
diagram below (with rectangular lower section, and triangular section
where the roof slopes to a point) and that it contains one rectangular
window, which does not get painted (obviously).
- As you can see in the sample execution, you should ask the user for
the dimensions of the wall (width, height to the bottom of the slanted
roof, height up to the tip of the slanted roof) and the dimensions of the
window (width and height) -- in this order. All of these dimensions
should be of type
double
- Assume that a can of paint will cover 400 square feet of wall
(make this a constant integer variable, so that it's simple to change
this value in the program -- for example, to represent larger cans of
paint in future versions).
- After collecting all of the dimensions, your program should produce
the output demonstrated in the sample execution. Also note that:
- The user-entered dimensions should be displayed in default format
(only using a decimal point and digits to the right when needed)
- The paintable area should be displayed to 1 decimal place
- The required number of cans should be displayed to 2 decimal
places
- Write your program so that the output looks EXACTLY like
the sample execution shown below (this means same wording, spacing,
and formatting of numbers)
- Note: The underlining in the sample execution below is used to
illustrate what the user is typing in -- obviously the underlining
will not appear on the console.
- You may assume that user input will be correct (i.e. numeric entries
and valid dimensions)
General Requirements
- No global variables
- All input and output must be done with streams, using the library
iostream
- You may only use the iostream library (you do not need
any others for these tasks)
- Your program should only use standard ANSI header files (make sure to
follow the directions exactly on the handout for creating Visual C++
projects, so that Windows-specific headers like stdafx.h and conio.h are
not placed into your file)
- When you write source code, it should be readable and
well-documented.
Style Guidelines for Programs
Sample run 1: (user input underlined)
Welcome to Paint Calculator 2011!!
How wide is the wall (in feet)? 40
and how high is the wall to the bottom of the roof? 15.7
and how high is the wall to the top of the roof? 21.5
How wide is the window (in feet)? 3
and what is the window's height? 2.75
A side wall that is
40' wide and
15.7' tall to the roof bottom and
21.5' tall to the roof top,
containing a window that is
3' wide and
2.75' tall,
has 735.8 square feet of paintable wall
and would require 1.84 cans of paint
(assuming that each can will cover 400 square feet of wall).
Thanks for using Paint Calculator 2011. Goodbye!!
Sample run 2: (user input underlined)
Welcome to Paint Calculator 2011!!
How wide is the wall (in feet)? 38.5
and how high is the wall to the bottom of the roof? 14.85
and how high is the wall to the top of the roof? 18.123
How wide is the window (in feet)? 2.75
and what is the window's height? 1.4
A side wall that is
38.5' wide and
14.85' tall to the roof bottom and
18.123' tall to the roof top,
containing a window that is
2.75' wide and
1.4' tall,
has 630.9 square feet of paintable wall
and would require 1.58 cans of paint
(assuming that each can will cover 400 square feet of wall).
Thanks for using Paint Calculator 2011. Goodbye!!
Compiling and Running:
This code only uses a standard library (iostream), so it will
compile with any C++ compiler. Make sure you practice with MS Visual
C++ 2010 Express Edition (and make sure it reports no compile errors!)
before you submit the program.
Be sure to follow the instruction file on the course web page, on
building console projects in Visual C++
Submitting:
Program submissions should be done through the submission web page, linked
from the main course web site. You will need your submission password --
these were handed out in the first recitation class (May 17 - 21). If you
missed class, see me or the TA who teaches your recitation section ASAP
(or e-mail, if you can't come see me) to obtain your password. Do
not send program submissions through e-mail -- e-mail attachments
will not be accepted as valid submissions.
General Advice - always keep an untouched copy of your finished
homework files on your computer science account. These files will have a
time-stamp which will show when they were last worked on (a timestamp from
the CS servers) and will serve as a backup in case you ever have
legitimate problems with submitting files through the web site.
Do this for ALL programs.