SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
I/o Streams As An Introduction To Objects And Classes
Exercise:
Programming Projects
Question:18 | ISBN:9780321531346 | Edition: 7

Question

To complete this problem you must have a computer that is capable of

viewing Scalable Vector Graphics (SVG) files. Your Web browser may

already be able to view these files. To test to see if your browser can display

SVG files, type in the rectline.svg file below and see if you can

open it in your Web browser. If your Web browser cannot view the file,

then you can search on the Web and download a free SVG viewer.

The graphics screen to draw an image uses a coordinate system in which

(0, 0) is located in the upper-left corner. The x coordinate increases to the

right, and the y coordinate increases to the bottom. Consequently,

coordinate (100,0) would be located 100 pixels directly toward the right

from upper-left corner, and coordinate (0,100) would be located 100

pixels directly toward the bottom from the upper-left corner. This is

illustrated in the figure below.

The SVG format defines a graphics image using XML. The specification for

the image is stored in a text file and can be displayed by an SVG viewer.

Here is a sample SVG file that draws two rectangles and a line. To view it,

save it to a text file with the “.svg” extension, such as rectline.svg, and

open it with your SVG viewer. <?xml version="1.0" standalone="no"?>

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"

"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg width="500" height="500"

xmlns="http://www.w3.org/2000/svg">

<rect x="20" y="20" width="50" height="250"

style="fill:blue;"/>

<rect x="75" y="100" width="150" height="50"

style="fill:rgb(0,255,0);"/>

<line x1="0" y1="0" x2="300" y2="300"

style="stroke:purple;stroke-width:2"/>

</svg>

For purposes of this problem, you can ignore the first five lines and the last

line and consider them “boilerplate” that must be inserted to properly

create the image.

The lines that begins with <rect x="20" … draw a blue rectangle whose

upper-left corner is at coordinate (20, 20) and whose width is 50 pixels and

height is 250 pixels.

The lines that begin with <rect x="75" … draw a green rectangle (RGB

color value of 0,255,0 is all green) whose upper-left corner is at coordinate

(75, 100) and whose width is 150 pixels and height is 50 pixels.

Finally, the <line> tag draws a purple line from (0,0) to (300,300) with a

width of 2.

Based on this example, write a program that inputs four nonnegative

integer values and creates the SVG file that displays a simple bar chart that

depicts the integer values. Your program should scale the values so they are

always drawn with a maximum height of 400 pixels. For example, if your

input values to graph were 20, 40, 60, 120, you might generate a SVG

file that would display as follows:

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.