CS160 Computer Science I Program 5a and 5b

$35.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (6 votes)

CS160 Computer Science I
Program 5a:
Objective
Practice if statements
Practice with loops
Practice with formatted output
Assignment
In this lab we will ask the user for information about the classes they are taking this semester,
and then determine their grade point average (GPA) for that semester. To determine a student’s
GPA, you divide the number of honor points by the number of attempted (not passed) credits.
To determine honor points, for each class multiple the number of credits by the grade’s honor
points; 4 for an A, 3 for a B, 2 for a C, 1 for a D, or 0 for an F. This program will ignore grades of
pass, fail, or incomplete.
The program will ask the user for the number of classes they are taking this semester. For each
class, ask for the name of the class, the number of credits and the letter grade. DO NOT ask for
honor points for each class, that will be determined from the letter grade. Continue to ask for
this information for each class. No error checking of the data is required; you can safely assume
all data entered will be valid.
For example, if you received a 4 credit A and a 3 credit B in a semester, this is how you
determine the honor points:
4 (credits) * 4 (determined from the entered A) = 16
3 (credits) * 3 (determined from the entered B) = 9
This input would result in 25 honor points / 7 attempted credits = 3.571429, which would be
truncated in the output to 3.5714.
Requirements/Assumptions
You can safely assume that no grade other than A, B, C, D, or F will be entered.
The grade MUST be entered as a letter grade; it cannot be entered as a number.
You can assume that the grade will be entered as an upper-case letter.
If the GPA cannot be calculated do not generate any output, just end the program.
Output
Once the user is done entering their classes, print out the following:
Grade point average, with 4 places after the decimal point
Number of credits attempts
Number of credits passed (any grade other than an F)
Number of classes attempted
Number of classes passed (any grade other than an F)
Ensure that the final output it in table format, using aligned columns with the text left justified
and all the numbers right justified.
Sample output (this is typed, not captured from a run)
An example of running the program might be:
Enter the number of classes this semester: 2
Enter a class: CS160
Enter the number of credits: 4
Enter your grade: A
Enter the next class: Math 208
Enter the number of credits: 3
Enter your grade: B
GPA: 3.5714
Credits attempts 7
Credits passed 7
Classes attempted 2
Classes passed 2

CS160 Computer Science I
Program 5b:
Objective
Work with loops
Work with graphics
Assignment
This assignment will have you create an image that will show your initials in the display. As a
demonstration, I’ve including my initials, with a variation on how I could draw the M. In order to
ensure practice using loops, the only graphics command that can be used to draw in the display
is point. You CANNOT use the line command, or any other command other than point. This
will require a loop in conjunction with the point command to draw each line in each letter.
Specifics
Write your initials, or any other combination of 3 unique letters, to the display. Before starting
each letter, write a comment stating the letter to be displayed and then give the variables
startX and startY a value. The startX and startY variables will be the upper left hand
corner of the letter. These variables do not have to be called startX and startY, the point is to
have variables which store the starting location of that letter.
Use relative locations, using the startX and startY variables, to create your letter using the
point command. ALL commands used to draw the letter MUST use startX and/or startY or
distances from startX or startY, such as startX + 100 or startY + 60.
To simplify the drawing of the letters, set the width of the line from the default of 1 to something
larger using setLineWidth(). I set the width in my example to 15.You can draw block letters,
as I did with the leftmost M, or figure out how to include the slope to draw angled lines. Either
approach is valid, you will not be graded on artistic style. However, each letter must include at
least 2 lines/for loops.
I decided to make each letter 100 pixels by 100 pixels. You do not have to use these
dimensions. I think it will be easier if all of your letters have the same width and the same
height. I would also draw the letters by hand on a graph, noting the starting and ending points of
each line, and how they relate to the starting x and y.
Challenge
If you look at the letter “O” you will find 4 lines. In the simplest solution you will have 4 for loops.
However, the letter can be created with less than 4 loops, since several of the loops will have
some of their coordinates in common. Nothing says that two lines (parallel lines) can’t be draw
with a single loop. I was also able to use a single loop to draw the diagonal lines in the second
M.
Starter code
from SimpleGraphics import *
setSize (700, 300)
setBackground (“light gray”)
setOutline (“dark blue”)
setLineWidth (15)
setWindowTitle (“Drawing TOM”)
#drawing T
startX = 100
startY = 100
#I’ll give you the top line of the T
for x in range (startX, startX + 100):
point (x, startY)

#drawing O
setOutline (“white”)
startX = 220
startY = 100
#now draw the lines for the O

#drawing M – approach 1
setOutline (“dark red”)
startX = 340
startY = 100
#now draw the lines for the first M

#drawing M – approach 2
startX = 460
startY = 100
#now draw the lines for the second M