All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Ask a Question
Search
Search
Sign In
Register
study help
computer science
programming principles and practice
Questions and Answers of
Programming Principles and Practice
Find the average maximum temperatures for each month of the year for two or more locations (e.g., Cambridge, England, and Cambridge, Massachusetts; there are lots of towns called “Cambridge”) and
Define a class Arrow, which draws a line with an arrowhead.
Why would you sketch out the layout of a graph before writing the code to draw it?
What kind of data is unsuitable for a line graph or a bar graph? Find an example and find a way of displaying it (e.g., as a collection of labeled points).
What do we mean when we say that a series approximates a function?
Find another data set of heights (an inch is 2.54cm) and graph them with your program from the previous exercise. For example, search the web for “height distribution” or “height of people in
How do you color and label a graphed function?
Here is a collection of heights in centimeters together with the number of people in a group of that height (rounded to the nearest 5cm): (170,7), (175,9), (180,23), (185,17), (190,6), (195,1). How
How do you add functions together?
Elaborate the bar graph class to allow labeling of the graph itself and its individual bars. Allow the use of color.
What is a default argument and when would you use one?
Design and implement a bar graph class. Its basic data is a vector holding N values, and each value should be represented by a “bar” that is a rectangle where the height represents the value.
How do you make an x axis? A y axis?
“Animate” (as in §15.5) the series 1–1/3+1/5–1/7+1/9–1/11+ . . . . It is known as Leibniz’s series and converges to pi/4.
What is a parabola?
Graph a sine (sin()), a cosine (cos()), the sum of those (sin(x)+cos(x)), and the sum of the squares of those (sin(x)*sin(x)+cos(x)*cos(x)) on a single graph. Do provide axes and labels.
What function (mathematical formula) defines a slope?
Modify Fct from the previous exercise to take an extra argument to control precision or whatever. Make the type of that argument a template parameter for extra flexibility.
When would you use a (continuous) line to represent data? When do you use (discrete) points?
Define a class Fct that is just like Function except that it stores its constructor arguments. Provide Fct with “reset” operations, so that you can use it repeatedly for different ranges,
What is a function of one argument?
Here is another way of defining a factorial function:int fac(int n) { return n>1 ? n*fac(n–1) : 1; } // factorial n!It will d o fac(4) by first deciding that since 4>1 it must be 4*fac(3),
What is object-oriented programming?
How does interface inheritance differ from implementation inheritance?
What does overriding mean?
Why would you make a virtual member function pure?
Why would you make a member function virtual?
The exceptions defined in the C++ standard library, such as exception, runtime_error, and out_of_range (§5.6.3), are organized into a class hierarchy (with a useful virtual function what() returning
How does a pure virtual function differ from other virtual functions?
Define a class Controller with four virtual functions on(), off(), set_level(int), and show(). Derive at least two classes from Controller. One should be a simple test class where show() prints out
What members of a class can be accessed from a class derived from it?
Most class hierarchies have nothing to do with graphics. Define a class Iterator with a pure virtual function next() that returns a double* (see Chapter 17). Now derive Vector_iterator and
What is the difference between a protected member and a private one?
Add an operation to Binary_tree that adds text to a node. You may have to modify the design of Binary_tree to implement this elegantly. Choose a way to identify a node; for example, you might give a
What is an inheritance diagram?
Modify Binary_tree to take a parameter (or parameters) to indicate what kind of line to use to connect the nodes (e.g., an arrow pointing down or a red arrow pointing up). Note how this exercise and
Modify Binary_tree to draw its nodes using a virtual function. Then, derive a new class from Binary_tree that overrides that virtual function to use a different representation for a node (e.g., a
Define a Binary_tree class derived from Shape. Give the number of levels as a parameter (levels==0 means no nodes, levels==1 means one node, levels==2 means one top node with two sub-nodes, levels==3
Define a class Pseudo_window that looks as much like a Window as you can make it without heroic efforts. It should have rounded corners, a label, and control icons. Maybe you could add some fake
Define a Group to be a container of Shapes with suitable operations applied to the various members of the Group.
Define a class Octagon to be a regular octagon. Write a test that exercises all of its functions (as defined by you or inherited from Shape).
Define a Striped_closed_polyline using the technique from Striped_rectangle (this requires some algorithmic inventiveness).
Define a Striped_circle using the technique from Striped_rectangle.
Define a Striped_rectangle where instead of fill, the rectangle is “filled” by drawing one-pixel-wide horizontal lines across the inside of the rectangle (say, draw every second line like that).
Define a class Immobile_Circle, which is just like Circle but can’t be moved.
Define an abstract class and try to define an object of that type. What happens?
Try to copy a Shape. What happens?
Define two classes Smiley and Frowny, which are both derived from class Circle and have two eyes and a mouth. Next, derive classes from Smiley and Frowny which add an appropriate hat to each.
How do you display part of an image?
What happens if you try to display an Image given a file name that doesn’t refer to a file containing an image?
What is the difference between a Circle and an Ellipse?
What is Vector_ref for and how do we use it?
What is a font and why do we care?
What properties can you set for a text string in a Text?
Define a class Star. One parameter should be the number of points. Draw a few stars with differing numbers of points, differing line colors, and differing fill colors.
Define a class Poly that represents a polygon but checks that its points really do make a polygon in its constructor.
Do the previous exercise, but using hexagons of a few different colors.Data from Previous Exercise“Tile” a window with small right triangles.
Do the previous exercise, but with hexagons.Data from Previous Exercise“Tile” a window with small right triangles.
“Tile” a window with small right triangles.
Define a right triangle class. Make an octagonal shape out of eight right triangles of different colors.
Draw the color matrix from §13.10, but without lines around each color.
Draw a circle. Move a mark around on the circle (let it move a bit each time you hit the “Next” button).
Draw a 300-by-200-pixel ellipse. Draw a 400-pixel-long x axis and a 300-pixel-long y axis through the center of the ellipse. Mark the foci. Mark a point on the ellipse that is not on one of the axes.
Define a class Regular_polygon. Use the center, the number of sides (>2), and the distance from the center to a corner as constructor arguments.
Tile a part of a window with Regular_hexagons (use at least eight hexagons).
Define a class Regular_hexagon (a regular hexagon is a six-sided polygon with all sides of equal length). Use the center and the distance from the center to a corner point as constructor arguments.
Make an RGB color chart (e.g., search the web for “RGB color chart”).
Write a program that draws a class diagram like the one in §12.6. It will simplify matters if you start by defining a Box class that is a rectangle with a text label.
Define the functions from exercise 4 for a Circle and an Ellipse. Place the connection points on or outside the shape but not outside the bounding rectangle.Data from Exercise 4Define functions n(),
Define functions n(), s(), e(), w(), center(), ne(), se(), sw(), and nw(). Each takes a Rectangle argument and returns a Point. These functions define “connection points” on and in the rectangle.
Draw a box with rounded corners. Define a class Box, consisting of four lines and four arcs.
Define a class Arc, which draws a part of an ellipse.
You have made a shape, but it doesn’t appear in the window. What are some possible reasons for that?
You made a Window object, but nothing appears on your screen. What are some possible reasons for that?
How would you put a photo of your best friend in a window (using a program you wrote yourself)?
How do you write text somewhere in a window?
Which basic shape would you use to draw a hexagon?
Find a way to add color to the lines from the previous exercise. Make some lines one color and other lines another color or other colors.Data from Previous ExerciseA superellipse is a two-dimensional
What command attaches a shape to a window?
A superellipse is a two-dimensional shape defined by the equationLook up superellipse on the web to get a better idea of what such shapes look like. Write a program that draws “starlike” patterns
What are examples of simple “shapes” that we can display?
Draw a series of regular polygons, one inside the other. The innermost should be an equilateral triangle, enclosed by a square, enclosed by a pentagon, etc. For the mathematically adept only: let all
How do screen coordinates work? Window coordinates? Mathematical coordinates?
Draw the file diagram from §12.8.
How do you label a window?
Display an image on the screen, e.g., a photo of a friend. Label the image both with a title on the window and with a caption in the window.
What’s a window label?
Draw the Olympic five rings. If you can’t remember the colors, look them up.
What is the minimal window?
Draw a two-dimensional house seen from the front, the way a child would: with a door, two windows, and a roof with a chimney. Feel free to add details; maybe have “smoke” come out of the chimney.
What is the simplest window to use?
What happens when you draw a Shape that doesn’t fit inside its window? What happens when you draw a Window that doesn’t fit on your screen? Write two programs that illustrate these two phenomena.
What header files do you need to do basic graphics using our graphics library?
Draw a red ¼-inch frame around a rectangle that is three-quarters the height of your screen and two-thirds the width.
In which namespace do we keep our graphics interface classes (our graphics library)?
Draw a 3-by-3 tic-tac-toe board of alternating white and red squares.
What is a window?
Draw your initials 150 pixels high. Use a thick line. Draw each initial in a different color.
Draw a 100-by-30 Rectangle and place the text “Howdy!” inside it.
Draw a rectangle as a Rectangle and as a Polygon. Make the lines of the Polygon red and the lines of the Rectangle blue.
Showing 200 - 300
of 628
1
2
3
4
5
6
7