Starting from:

$30

CSCI160 Computer Science I  Program 2 -Solved

s. 
Part 1 
Design a program that asks for the number of credits you have earned to date (this may be zero 
for freshman). Then ask for the number of credits you are taking this semester. Make sure all 
inputs have an appropriate prompt. By appropriate, I mean a prompt anyone would understand, 
not just someone who is writing the program. Do not ask for the number of credits required for 
graduation, assume it is 120. 
Print to the display, using the regular print function: 
1) the number of credits you have completed. 
2) the number of credits you will have completed after this semester. 
3) the number of credits you have left to complete to graduate. 
Then add some graphics to the program. Using SimpleGraphics, create a horizontal bar chart, 
in three parts, showing how far you are toward tentative graduation. When working with 
graphics, we would like the content to work regardless of the screen size. To help with this, use 
the getWidth() function to determine the width of the screen. 
For this example, I will enter 30 for the number of credits already completed and 12 as the 
number of credits attempted this semester. 
The first rectangle will show how far you are percentage-wise toward graduation. For example, 
in the following image, the red rectangle starts at the left edge and covers 25% of the screen (30 
/ 120). Make sure to figure out the percentage of the screen to be drawn, AND THEN draw the 
rectangle covering that much of the current screen. 25% of the current screen (800 pixels wide) 
is 200 pixels. 
My second part was in white, showing how far you are toward graduation, percentage-wise, 
after this semester. This will start immediately to the right of the previous rectangle. In the 
following image, the white rectangle covers 10% of the screen, or 80 pixels. 12 / 120 is 10%. 
10% of the screen width is 80 pixels. 
My third part was in blue, and shows the percentage of credits left to be taken after this 
semester. In the following example the blue rectangle takes up 65% of the screen, or 520 pixels. 
You should also include a legend. Place this in the area above bar graph. To create a legend, 
draw a square of the specified color. Don’t do any math to figure out where to place it. I placed 
the first rectangle at 50, 50, and then the following two rectangles spaced out by 50 pixels on 
the y axis. To draw text use the showText() command in SimpleGraphics. showText accepts 
three arguments, x, y, and the text to display. x, y will be the upper left hand corner of the 
text. showText will write the text using the color set by setOutline.I don't care about the colors, but make sure that you use three colors different from the 
background and that the legend accurately represents the colors in the graph. 
The point behind using getWidth() is to accurately redraw the screen if the screen width is 
changed. 
I set the text in the title bar using the setWindowTitle() command. 
I've included some sample code and an image of a bar graph. 
from SimpleGraphics import * 
setSize (800, 400) 
setBackground ("light gray") 
setWindowTitle ("Progress toward graduation") 
... 
#start of the legend 
rect (50, 50, 30, 30) 
showText (100, 50, "Classes taken") 
Output: 
Credits taken so far: 30 
Credits this semester: 12 
Credits needed to graduate: 78Part 2 
Write a program that asks the user their first name, last name, current address, city, state, and 
zip code. Then write a mailing label to the screen exactly as laid out below. This will require 
some work with spacing. Understanding the sep= and end= print options will be helpful. 
The required format is: 
<first name> <last name> 
<address> 
<city>, <state> <zip code> 
Challenge: 
Write the label to the screen three times. The first time as described above is required. The 
second time use only one print statement. The third time use exactly six print statements. 
Make sure the output is identical in each label.

More products