Lab 1:
Input, Processing, and Output

This lab accompanies
Chapter 2 of Starting Out with
Programming Logic & Design.

We Will Write a Custom Essay Specifically
For You For Only \$13.90/page!

order now

Name:     Gagandeep
Sharma_________________

Lab 1.1 – Algorithms

This lab requires you to think about the
steps that take place in a program by writing algorithms.  Read the following program prior to
completing the lab.

Write a
program that will take in basic information from a student, including student
name, degree name, number of credits taken so far, and the total number of
credits required in the degree program.
The program will then calculate how many credits are needed to
student name, the degree name, and credits left to graduate.

Step 1:  Examine the following algorithm. (Reference:
Designing a Program, page 31).

Get the student name.
Get the degree program name.
Subtract the number of credits taken so far from the
required credits for the degree.
Get the number of credits required for the degree
program.
Get the number of credits the student has taken so far.
Display the input information in Step 1 and 2.
Display the calculated information.

Step 2:  What logic error do you spot and how would
you fix it?

Step1>Step>2>step4>step5>step3>step6>step7

Step 3:  What steps require user interaction (Ex:
user must type in some input)?

Step1,2,4 and5

Lab 1.2 – Pseudocode

This lab requires you to think about the steps that take
place in a program by writing pseudocode.
Read the following program prior to completing the lab.

Write a
program that will take in basic information from a student, including student
name, degree name, number of credits taken so far, and the total number of
credits required in the degree program.
The program will then calculate how many credits are needed to
student name, the degree name, and credits left to graduate.

Step 1:  This program is most easily solved using just
five variables.  Identify potential
problems with the following variables declared in the pseudocode. Assume that
the college has the ability to offer half credits.  (Reference: Variable Names, page 39-40).

Variable Name

Problem (Yes or No)

If Yes, what’s
wrong?

Declare Real creditsTaken

No

Declare Real credits Degree

Yes

Declare  real credits degree

Declare Int creditsLeft

Declare real
credits left

Declare Real studentName

Should be a
string, Declare String student Name

Declare
String degreeName

No

Step 2:  Complete the pseudocode by writing the two
missing lines. (Reference: Prompting the User, page 42).

Display
“Enter student name.”

Input Student name

Display
“Enter degree program.”

Input
degreeName

Display “Enter the number of credits required to graduate

Input
creditsDegree

Display “Enter the number of credits taken so
far.”

Input
credit taken

Step 3:  What two things are wrong with the following
calculation? (Reference: Variable Assignment and Calculations, page 43).

creditsLeft =
creditsTaken – creditsDegree

Set credits left= credits degree-credits taken

Step 4:  Write the exact output you would expect from
the following line of code if the user of the program enters “Bill Jones”.  (Reference: Displaying Items, page 40 – 41).

Display “The
student’s name is “, studentName

Bill Jones

Step 5:  Write the exact output you would expect
from the following line of code if the user of the program enters a degree that
is 63 credits in total and they have taken 40 credits.  (Reference: Displaying Items, page 40 – 41).

Display “This
program requires “, creditsDegree, ” credits and they have taken “,  creditsTaken, ” so far.”

This program requires 63 credits and
they have taken 40 so far.

Step 6:  Complete the following pseudocode to solve
the programming problem.

1.  //This
program takes in student information and calculates

2.  //how
many credits the student has left before graduation.

3.  //Information
is then printed to the screen.

4.  //Declare variables

5.  Declare Real
creditsTaken

6.  Declare Real credits Degree

7.  Declare Real credits Left

8.  Declare String student Name

9.  DeclareStringdegreeName

11. Display “Enter
student name.”

12. Input studentName

13.  Display “Enter degree program.”

14. Input degree Name

15. Display “Enter credits needed for name.”

16. Input credits Degree

17. Display “Enter the number of credits taken so far.”

18. Input creditsTaken

19.

20.

21.

22.

23.

24.

25. //Calculate remaining
credits

26. Set credits Left = credits Degree – credits Taken

27. //Display student name,
degree program, and credits left.

28. Display “The
student’s name is “, studentName

29.  Display “You taking
classes for “, degree Name

30. Display “You need “, credits Left, ” more credits to earn this degree.”

Lab 1.3 – Flowcharts

This lab requires you to think about the steps that take
place in a program by designing a flowchart.
While designing flowcharts can be done with paper and pencil, one
mistake often requires a lot of erasing.
Therefore, a flowcharting application such as Raptor or Visio should be
used.  This lab
will give you a brief overview of Raptor.
Read the following program prior to completing the lab.

Write a
program that will take in basic information from a student, including student
name, degree name, number of credits taken so far, and the total number of
credits required in the degree program.
The program will then calculate how many credits are needed to
student name, the degree name, and credits left to graduate.

Step 1:  Start Raptor; notice the Raptor
screen.  This window is your primary tool
for creating a flowchart.  Prior to
adding symbols, save your document by clicking on File and then Save.  Select your location and save the file as Lab 1-3.
The .rap file extension will

Step 2:  Notice the MasterConsole screen.  This window is used to show your program
output once your flowchart is completed.
The Clear button will clear the console to view a fresh run of your
program.

flowchart should follow the pseudocode in Lab 1-2, Step 6.  While a rectangle is normally used for
declaring variables, there is no easy way to do this in Raptor.  Since this is an important part of
flowcharting, we will do this using a comment box.  To do this, Right-Click on the Start symbol
and select Comment.  In the Enter Comment box, type the variables
your program will need.  Below is a start
to how it should look.

Step 4:  The next step in your flowchart should be
to ask for user input.  Click the Input
Symbol on the Left and Drag and Drop to the flow line between Start and
Stop.  Double Click on the Input Symbol
to begin entering information.  Enter Enter
student name in the top box.
Enter studentName in the variable
box.  Below is how it should look.

Step 5:  Continue the Step 4 directions for all
your input statements, changing each Input symbol to reflect the appropriate
user interaction.

Step 6:  The next step in your flowchart is to
process any calculations that exist.
Click on the Assignment symbol and drag it to the flow line between the
last input statement and the end symbol.
Double click on the Assignment symbol to enter your code.  In the Set box, put the name of your storage
variable.  In the To box, put the
expression part of your formula.  Below
is how it should look.

Step 7:  The next step in your flowchart is to
display the requested output to the screen.
Click the Output symbol and drag it to the flow line between the
assignment statement and the end symbol.
Double click on the Output symbol to enter your code.  Under Output Type, select Output Expression
since we want to display both a sentence and the contents of a variable.  In the box, type “Student
name is ” + studentName.
Below is how it should look once you click Done.

Step 8:  Continue the Step 7 directions for all
your output statements, changing each Output symbol to reflect the appropriate
requested output information.

Step 9:  Once your flowchart is complete, click on
Run and then Execute to Completion on the Raptor menu.  Follow the flow of your program to see if it
window should show output similar to

Student name
is Bill Jones

The degree
program is Computer Programming

Credits left

—-Run
finished—-

Step 10:  The final step is to insert your finished
flowchart in the space below.  Inside
Raptor, select File and the Print to Clipboard from the menu.  Inside Word in the space below, select Edit
and Paste.

PASTE FLOWCHART HERE

Lab 1.4 –
Python Code

This lab requires you to translate your work
in the pseudocode and flowchart to actual code using Python.  Read the following program prior to
completing the lab.

Write a
program that will take in basic information from a student, including student
name, degree name, number of credits taken so far, and the total number of
credits required in the degree program.
The program will then calculate how many credits are needed to
student name, the degree name, and credits left to graduate.

Step 1:  Examine the following line of code.  What do you expect as output to the screen?

studentName =
input(‘Enter student name. ‘)

Enter Student Name

Step 2:  Examine the following line of code.  What type of value do you expect the user of
the program to enter?

creditsDegree
= input(‘Enter credits required for degree.’

A numerical value for their
required credits for their degree

Step 3:  If the user of the program types Bill
Jones to the question in Step 1, what do you expect the output to the
screen to be when the following line of code processes?

print
(“The student’s name is”, studentName)

Jones

Step 4:  Examine the following line of code.  If the program requires 63 credits, and the
student has 20 left, what do you expect the output to the screen to be?

print (‘The
program requires’, creditsDegree, ‘credits and they have taken’, creditsTaken,
‘credits so far.’)

The student has already taken 40
credits so far

Step 5:  Start the IDLE Environment for Python.  If the Edit window for entering code does not
come up, go to Options, Configure IDLE, click on the General tab, and under Startup Preferences select Open Edit
Window.  Close and reopen the
Environment.   Prior to entering
code, save your file by clicking on File and then Save.  Select your location and save this file as Lab1-4.py.  Be sure to include the .py extension.

documentation.  Document the first few
lines of your program to include your name, the date, and a brief description
of what the program does.  Each line that
you want to comment out must begin with a # sign.  For example:

#Sally Smith

#January 15

#This program

Step7:  After documentation, enter the following
line of code into your program.

studentName =
raw_input(‘Enter student name. ‘)

Step 8:  On the menu, select Run and then Run
action.  If you get a syntax error, you
must fix it before you are able to run your program.  Click OK and review the highlighted syntax
error to fix it.

Step 9:  Repeat Step 8, but change the statement
so that it asks the user to enter their degree name.  It is up to you whether you want to repeat
Step 9 each time you code a line.  It is
recommended for beginning programmers so they can immediately identify syntax
errors.  Also, one syntax error at a time
seems better than many all at once.

Step 10:  Next, you should write the code that will ask
the user how many credits are required in the degree.  This can be done using the input function since it is a numeric
value.  Enter the following line of code

creditsDegree
= input(‘Enter the number of credits required for the degree. ‘)

Step 11:  Repeat Step 11 but change the statement
so that it asks the user to enter the number of credits they have taken so far.

Step 12:  Next, add your calculation.  This is done very simply with the following
code.

creditsLeft =
creditsDegree – creditsTaken

Step 13:  Add the following line of code to your
program.

print (‘The
student’s name is’, studentName)

Step 14:  If you have not tested your program in a
while, now is a good time to try it out.
Go to Run and Run Module and observe what happens.  SYNTAX ERROR!

Step 15:  While nothing stands out as being wrong
in Step 15, notice that the word student’s is
actually causing the problem.  To the
language, the apostrophe looks as if it is the end of the statement.  Since it is not, it must be quoted out by
putting a in front of it.  Change the
line to the following.

print (“The
student’s name is”, studentName)

Step 16:  Finish your code by printing the
remaining of the requested statements.
Your final output might look like the following.

Enter student
name. Bill Jones

Enter degree
name. Computer Programming

Enter the
number of credits required for the degree. 63

Enter the
number of credits taken so far. 24

The student’s
name is Bill Jones

The degree
name is Computer Programming

There are

Step 17:  When your code is complete and runs
properly, on the Menu, go to Edit and then Select All, then Edit and Copy.  Paste the code below.

PASTE CODE HERE

Student Name = raw_ input (“Enter
student name: ”

Degree Name = raw_ input (“Enter degree
name: ”

Credits Degree = input (“Enter credits
needed for degree: ”

Credits Taken = input (“Enter credits
taken: ”

Credits Left = credits Degree  – credits Taken

print “The student name is “,
student Name, “.

print “You are taken classes for “,
degree Name, “.

print “You need “, credits Left,
” more credits to earn this degree”

Lab 1.5 – Programming Challenge 1 – Team Average

Write the Algorithm, Pseudocode, Flowchart, and Python code
for the following programming problem.

Team Average

A college wants you to write a
program for them that will calculate the average number of wins for their football team over the past five
years.  The user of the program should be
able to enter the number of wins each year.
The program will calculate the average number of wins during that five
year period and display that information to the screen.

The Algorithm

TYPE ALGORITHM HERE

Number of wins each of five years
Calculate the average number of
wins
Display the information to the
Screen

The Pseudocode

TYPE PSEUDOCODE HERE

//Declare
variables

Declare Int
year1
Declare Int year2
Declare Int year3

Declare Int
year4

Declare Int
year5

Declare Real
averageWin

//inputs

Display “Enter wins for year 1: ”

Input year1

Display “Enter wins for year 2: ”

Input year2

Display “Enter wins for year 3: ”

Input year3

Display “Enter wins for year 4: ”

Input year4

Display “Enter wins for year 5: ”

Input year5

//calculations

Set average Wins = (year1+year2+year3+year4+year
5)/5

//output

Display “Your average for the past
five years is “,
average Wins, “.”

The Flowchart

PASTE FLOWCHART HERE

The Python Code

PASTE CODE HERE

year1=input (“Enter wins for year 1:
“)

year2=input (“Enter wins for year 2:
“)

year3=input (“Enter wins for year 3:
“)

year4= year2 + year3 + year4 + year5)/5

print “Your average for the past five
years is “, average Wins, “.”

input (“Enter wins for year 4: “)

year5=input (“Enter wins for year 5:
“)

average Wins = (year1 +

Lab 1.6 – Programming Challenge 2 – Pedometer
Calculator

Write the Algorithm, Pseudocode, Flowchart, and Python code
for the following programming problem.

Help Video:  Double click the file to view video

Pedometer Calculator

A
dietician wants you to write a program that will calculate the number of
calories a person can lose by walking at a slow pace for a mile; however, the
user will have only the distance given by a pedometer, which is measured in
steps and not miles.  Assume each mile a
person walks is equivalent to 2000 steps, and that for every mile walked, a
person loses 65 calories.  Allow the user
of the program to enter the number of steps taken throughout the day.  The program will calculate the distance in
miles and the number of calories lost.
The user of the program should also be able to enter the day of the week
the data is being calculated for.  The
day of the week, the distance in miles, and the calories lost should then be
displayed to the screen.

The Algorithm

1 .Take in steps and days of the week

2. Calculate the lose of calories

3. Display the calories lost of the day entered

The Pseudocode

//declare

Declare String day Walked

Declare Int walked Steps

Declare Real calories       Lost

//input

Display “What day are you calculating for?: ”

Input day Walked

Display “How many steps did you take?: ”

Input walked Steps

//calculate

Set Real calories Lost = (walked Steps/2000)*65

//output
Display “You lost “, calories Lost, ” on “, day Walked, “.”

The Flowchart

The Python Code

Day Walked = raw _input (“What day are you calculating
for?: “)

Steps Walked = input (“How many steps did you take on
this day?: “)

Calories ost = (steps Walked/2000)*65

print “You lost “,calories Lost, “calories
on” day Walked,”.”