Day 1

Improv exercise:  The class tells a story.  Each member of the class add a sentence of the story using the last word from the previous member.

Example:

Professor: I’m here to sell you a xylophone.

Student1: I don’t want a xylophone, do you have bongos.

Student2: Bongos make me sick.
Student3: I was sick after ate at McDonalds.

Student4: Hey! I work at McDonalds.

Student5: You work at McDonalds? No wonder you are broke.

Day 2

 

 

1)       What is a computer program? 

a)      Instructions for the computer written in a vocabulary the computer understands

b)      Unambiguous (CLEAR, no ambiguity)

c)      Followed exactly as written – order matters

2)      What is computer programming?

a)      Writing instructions

b)      Testing program

c)      Debugging program

 

Definitions of computer programming:

From wikipedia: the process of writing, testing, debugging/troubleshooting, and maintaining the source code of computer programs.

 

Algorithm – a set of instructions for solving a problem that can used repeatedly.

3)      A computer program has 3 fundamental pieces – sequence, selection and iteration – today we are going to focus on sequence or the order in which instructions are executed – briefly explain what selection and iteration are

a)      Sequence: the order in which instructions are executed

b)      Selection: instructions are executed only if a specific condition is met

c)      Iteration: instructions are executed repeatedly.

 

4)      A computer program must be translated into machine language for the computer to execute it.  Discuss the difference between compiler (converts all of the code to machine language before executing) and interpreter (converts one line of code at a time and immediately executes each line before moving to the next line).  Talk about the difference between syntax errors and logic errors.

a)      Syntax error: - incorrect word used, incorrect punctuation

b)      Logic error: - syntax is correct but when it executes you don’t get the result you want because of an error in the logic of your program.

5)      Write directions to the Math Lab (B130) / Computer Lab (B 225) using a limited set of words.
Vocabulary: Walk, turn (assume 90 degree turn), step(s), down (or up), right, left, open, door

Day 3

Bill, Ken, and Mark are, not necessarily in this order, a kicker, a receiver, and a quarterback. The kicker, who is the shortest of the three, has never been married. Bill, who is Ken's father-in-law, is taller than the receiver. Who plays in which position?

Matrix logic (or 2D chart) can be used as a way to organize information and help you eliminate possibilities in a systematic way.  A logic matrix sets up a one-to-one correspondence between the elements in a problem.  When doing matrix logic it is VERY IMPORTANT to read the instructions, pay attention to detail, organize your thoughts, make notes, etc. 

Ted, Ken, Allyson and Janie (two married couples) each have a favorite sport: running, swimming, biking and golf.  Given the following clues, determine who likes which sport.

 

1.      Ted hates golf.

2.      Ken wouldn’t run around the block if he didn’t have to, and neither would his wife.

3.      Each woman’s favorite sport is featured in a triathlon.

4.      Allyson bought her husband a new bike for his birthday to use in his favorite sport.

 

 

 

SPORTS

NAMES

 

Running

Swimming

Biking

Golf

Ted

 

 

 

 

Ken

 

 

 

 

Allyson

 

 

 

 

Janie

 

 

 

 

 

 

 

 

 

 

 

Use “X” for “No” and “O” for “Yes”

 

1)      Sometimes there are more variables in the problem – if this is the case we need a larger matrix

 

Tom, John, Fred and Bill are friends whose occupations are (in no particular order) nurse, secretary, teacher and pilot.  They attended a picnic recently, and each one brought his favorite meat (hamburger, chicken, steak and hot dogs) to barbecue.  From the clues below, determine each man’s occupation and favorite meat.

1.      Tom is neither the nurse nor the teacher. (Tom/Teacher, Tom/Nurse)

2.      Fred and the pilot play in a jazz band together. (Fred/Pilot)

3.      The burger lover and the teacher are not musically inclined. (Burger/Teacher)

Also: Fred/Burger, Fred/Teacher, Pilot/Burger

4.      Tom brought the hot dogs. (X in rows, columns for Tom/Hot Dog)

5.      Bill sat next to the burger fan and across from the steak lover. (Bill/Burger, Bill/Steak

KNOW ALL MEATS

Also: Burger lover is not teacher or pilot -> john bought burgers -> john not teacher or pilot

KNOW BILL IS TEACHER, TOM IS PILOT

6.      The secretary does not play an instrument or sing. (Fred/Secretary)

KNOW FRED IS NURSE, JOHN IS SECRETARY

 

Use the matrix below to work this problem.  Use “X” to represent a “No” and “O” to represent a “Yes”.

 

 

OCCUPATIONS

MEAT

 

 

Nurse

Scty

Tchr

Pilot

Burg

Chkn

Steak

HDog

NAMES

Tom

 

 

 

 

 

 

 

 

John

 

 

 

 

 

 

 

 

Fred

 

 

 

 

 

 

 

 

Bill

 

 

 

 

 

 

 

 

MEAT

Burg

 

 

 

 

 

 

 

 

Chkn

 

 

 

 

 

 

 

 

Steak

 

 

 

 

 

 

 

 

HDog

 

 

 

 

 

 

 

 

Day 4

The way a computer stores numbers is using combinations of 0 & 1’s. How does the computer store these one’s and zeros?   At the most basic level computers look for the presence or absence of an electrical charge. The computer's physical memory consists of millions of transistors, each of which can be in an "off" or "on" state, and these two states can be used to represent the digits 0 and 1 in the binary numbering system. (When data is transferred to a magnetic or optical disk, the "ons" and "offs" of the transistors are converted to patches of up-or-down magnetization on the magnetic medium or light-or-dark spots on the optical medium.)

 

Binary allows the computer to perform calculations on numbers.

 

Our numerical world: 0,1,2,3,4,5,6,7,8,9 – 10 digits, BASE 10, decimal system

A number like 2654:

_          2          6          5          4          2000+600+50+4 = 2654

104       103       102       101       100

10000  1000    100      10        1

 

A computers numerical world: 0,1 – 2 digits, BASE 2, called the binary number system. 

0          0          0          0          1          0          1          1          8+2+1 = 11

27            26         25         24         23         22         21         20

128      64        32        16        8          4          2          1

 

Each 1/0 is called a bit, 8 bits are in 1 byte.  So in 1 byte the computer can store any number 0-255

– assume a full byte is used to store all numbers:

1        How would I write the number 5 in binary?

2        How would I write the number 150 in binary?

3        What is 00101011 in decimal?

4        What is 10001101 in decimal?

Proceedure (Algorithm) for translating decimal to binary:

1.       set position to 7

2.       set placeholder to 128

3.       if decimal number < placeholder

·         print 0

else

·         print 1

·         set decimal number to decimal number - placeholder

4.       set position to position - 1

5.       set placeholder to placeholder / 2

6.       repeat steps 3 through 5 until position equals -1

Review:

  • Computers use a combination of 1’s and 0’s (called bits or binary digits) to store numerical values. 
  • There are 8 bits in 1 byte.  One byte can store any number between 0-255 as a binary number.
  • Each bit in the byte has a corresponding decimal value (placeholder) based on the position of the bit. The placeholder is determined by 2position.

 

__        __        __        __        __        __        __        __       

 7         6         5         4         3         2          1         0     --  Position

27            26         25         24         23         22         21         20    

128      64        32        16        8          4          2          1      --  Placeholder

 

Exercise: Read through the instructions for converting any decimal number in the range 0 to 255 to a binary number. Keep track of what is stored in each location.

 

Terminology:

  • Position: The rightmost bit is position 0.  Positions increase by 1 as you move to the left until you get to position 7 which is the leftmost bit.
  • Placeholder: The corresponding decimal value for each position.
  • Decimal Number: The number being converted to binary.  Keep in mind that the instructions may update the decimal number to a different value as needed.

 

Day 5

Make a systematic list of all the ways you can order the bits 0 and 1 into a 3 digit sequence, for example, 010.

 

Bit 1

Bit 2

Bit 3

0

0

0

0

0

1

0

1

0

0

1

1

1

0

0

1

0

1

1

1

0

1

1

1

8 different ways

 

Ask for answers and then go over it using systematic lists.

 

Systematic Lists

Another way of solving a problem is to make a systematic list.  A systematic list is generated to organize information in a methodical way. 

A table is an easy way to organize a list – the columns are labeled with the information of the problem and the rows are the different possibilities

 

2)      Leslie has 25 cents in her pocket but does not have a quarter.  If you can tell her all possible combinations of coins she could have that add up to 25 cents, she will give you the 25 cents.

 

What would you put as the column headings?  How could you systematically determine all the possibilities?

Dimes

Nickels

Pennies

2

1

0

2

0

5

1

3

0

1

2

5

1

1

10

1

0

15

0

5

0

0

4

5

0

3

10

0

2

15

0

1

20

0

0

25

 

12 possibilities

Andrew and his friends have formed a fantasy football league in which each team will play one game against each of the other teams.  There are 7 teams: Texas A&M (Aggies), Purdue (Boilermakers), Alabama (Crimson Tide), Oregon (Ducks), Boston College (Eagles), Air Force (Falcons) and Florida (Gators).  How many games will be played in all?

 

Team1

Team2

Texas

Purdue

Texas

Alabama

Texas

Oregon

Texas

BC

Texas

AF

Texas

Florida

Purdue

Alabama

Purdue

Oregon

Purdue

BC

Purdue

AF

Purdue

Florida

Alabama

Oregon

Alabama

BC

Alabama

AF

Alabama

Florida

Oregon

BC

Oregon

AF

Oregon

Florida

BC

AF

BC

Florida

AF

Florida

 

The object of Frisbin is to throw three Frisbees at three different-sized bins that are set up on the ground about 20 feet away from the player.  If a Frisbee lands in the largest bin, the player scores 1 point.  If a Frisbee lands in the medium-sized bin, the player scores 5 points.  If a Frisbee lands in the smallest bin, the player scores 10 points.  Kirk McCoy is playing the game.  If all three of his Frisbees land in bins, how many different total scores can he make?

 

For her Shakespeare course, Kristen is to read all five of the following plays and choose three of them to write papers about: Richard III, The Tempest, Macbeth, A Midsummer Night’s Dream and Othello.  How many different sets of books can Kristen write papers about?

 

Day 6

So far we’ve talked about the following topics with regard to computer programs: sequence of instructions, limited vocabulary, types of errors (syntax vs. logic), how the computer stores information – today we are going to talk about how a computer can make decisions based upon certain circumstances or conditions.  Before we get into the specifics of how the computer does this, let’s talk about decisions in every day life:

  • How do you determine if you need an umbrella? (if it is raining, then use an umbrella)
  • How do you determine if you need a jacket?  (if the temperature is below 70 degrees, then I need a jacket)
  • How do you determine if you have to come to CSC 104 class?  (if it is Tuesday or Wednesday, then I have CSC 104)
  • How does the clerk at a store determine if you can purchase beer or they should send you home?  (if the person is 21 or older, then sell beer, else send home)

 

Life is full of decisions!

 

The computer makes decisions as well.  These decisions are called selection statements or conditional statements and are typically referred to as “if statements” or “if then statements” because they follow the syntax (if x, then y, end if).  The computer can handle simple if statements, simple if/else statements, complex if and if/else statements as well as nested if and if/else statements.  Today we are going to focus on simple if, simple if/else statements and if time permits, nested if/else statements.

 

An ‘if statement’ allows the computer to check a condition and decide which statement(s) to execute based upon the evaluation of that condition. A condition evaluates to true or false.  If the condition is true, the “then” statement(s) are executed, if the condition is false, the “else” statement(s) are executed.

 

Simple if statements

 

Structure:

if (value1 relationalOperator value2) then

statement(s) to be executed if the condition evaluates to TRUE

end if

 

·         The “value1 relationalOperator value2” is called a condition and will be placed in parenthesis.  You can compare numbers, characters, text, colors, etc.

·         There are 6 relational operators:

 <               less than

 >               greater than

<=              less than or equal to

>=              greater than or equal to

 =               equal to

< >             not equal to

 

If statement examples

Results for each of the different values

if (weather = “raining”) then

            bring umbrella

end if

 

values for weather:

raining: bring umbrella

sunny:

drizzling:

 

if (temp < 70) then

            bring jacket

end if

 

values for temp:

65:  jacket

70:

80:

 

if (sales > 5000) then

            bonus is 500

end if

 

values for sales:

1000:

5000:

5050: bonus is 500

 

if (feeling = “hungry”) then

            eat

end if

 

values for feeling:

full:

hungry: eat

starving:

 

 

Day 7

Introduction to logical operators.  Sometimes you want to evaluate 2 or more conditions in order to make a decision.  Conditions are combined using logical operators. Logical operators (OR, AND, NOT) –

 

Truth Tables:

X

NOT X

True

False

False

True

 

X

Y

X OR Y

True

True

True

True

False

True

False

True

True

False

False

False

 

X

Y

X AND Y

True

True

True

True

False

False

False

True

False

False

False

False

 

Let’s say you want to determine whether or not it is the proper day/time for CSC104.  How would you write that as a complex condition?

            if (day = “Tuesday”) AND (time = 1pm) then

                        CSC 104

            end if

You can use more than 1 logical operator in a complex condition – for example

if ((day = “Tuesday”) AND (time = 10am)) OR ((day = “Wednesday”) AND (time = 9:30am))

 

Order of precedence: use parenthesis, if no parenthesis ANDs are executed first then ORs.

 

What if we have more than 2 possible actions or multiple values to be checked?  We can use additional conditions by placing one if statement within another if statement – this is called nesting if statements.  For example,

Let’s say a sporting event charges different prices based upon where a seat is located – seats in the lower balcony cost $100, seats in the middle section cost $60 and seats in the upper deck cost $25.  How would you determine the seat price?

 

if (seatLocation = “lower balcony”) then

            price is $100

else

            if (seatLocation = “middle section”) then

                        price is $60

            else

                        price is $25

            end if

end if

 

Notice we don’t need to check if the seat is located in the upper deck because that is the only other option, known as the default.

 

Complex conditions

Structure:

if (condition1) logicOperator (condition2) then

statement(s) to be executed if the complex condition evaluates to TRUE

else

statement(s) to be executed if the complex condition evaluates to FALSE

end if

 

Logic Operators: AND, OR

 

Complex if and if/else statement examples

Results for each of the different values

if (average >= 70) AND (average < 80) then

            grade is C

end if

 

 

values for average:

60:

70:  grade is C

75:  grade is C

80:

if (average >= 70) OR (average < 80) then

            grade is C

end if

 

 

values for average:

60:  grade is C

70:  grade is C

75:  grade is C

80:  grade is C

if (age < 12) OR (age >=65) then

            discounted ticket

else     

            regular ticket

end if

values for age:

10:  discounted ticket

12:  regular ticket

25:  regular ticket

65:  discounted ticket

if (age < 12) AND (age >=65) then

            discounted ticket

else     

            regular ticket

end if

values for age:

10:  regular ticket

12:  regular ticket

25:  regular ticket

65:  regular ticket

Day 8

What if we have more than 2 possible actions or multiple values to be checked?  We can use additional conditions by placing one if statement within another if statement – this is called nesting if statements.  For example,

Let’s say a sporting event charges different prices based upon where a seat is located – seats in the field level cost $100, seats in the middle section cost $60 and seats in the upper deck cost $25.  How would you determine the seat price?

 

if (seatLocation = “lower balcony”) then

            price is $100

else

            if (seatLocation = “middle section”) then

                        price is $60

            else

                        price is $25

            end if

end if

 

Notice we don’t need to check if the seat is located in the upper deck because that is the only other option, known as the default.

 

Nested if/else

a.       Give the nested if/else handout. Be sure to draw flow charts to trace through 2 of the examples.

b.      Go over each example and the test values and results. 

c.       Draw flow charts to trace through the logic of an example.

d.      After going over all examples, have students write their own nested if/else statements for all the scenarios on back of handout. 

e.       Go over as a class once they are finished.

 

 

 


 

CSC104 – Tracing If Statements

 

Complete the results column for each example

 

 

Examples

Results for each of the different values

if (num1 = 2) AND (num2 > 5) then

            correct

else

            not correct

end if

values for num1 & num2:

 

num1                  num2                  result

2

2

3

5

6

6

 

if (num1 < > 5) OR (num2 <= 7)

            correct

else

            not correct

end if

values for num1 & num2:

 

num1                  num2                   result

2

5

3

5

2

9

 

if (age >= 55) then

            $10

else

            if (age >= 21) then

                        $15

            else

                        if (age >= 5) then

                                    $7

                        else

                                    free

                        end if

            end if

end if

values for age:

56 ->

20 ->

2 ->

5 ->

 

 

 

CSC104 – If Statement Worksheet - Write if statements for the following scenarios.  You will need to determine what type of if statement is appropriate (simple if, simple if/else, nested if/else, complex condition).

 

1)      “check for school closure” if weather is any one of the following: snowing, icy, snow predicted, “go to school” otherwise

 

 

 

 

 

2)      “grade is A+” if the average is 95 or higher

 

 

 

 

3)      Determine if a student is “part time”, “full time”, or “full time overloaded” based on the following credit structure:

  • 11 or fewer credits: “part time”
  • 12 – 17 credits: “full time”
  • 18 or more credits: “full time overloaded”

 

 

 

 

 

 

 

 

 

4)      “grade is B” if the average is in the 80’s

 

 

 

 

5)      Determine the ticket price based upon the following pricing structure:

a.       $5 if 65 or older

b.      $10 for anyone under 65

 

 

 

 

6)      When playing war “player 1 wins” if his/her card is higher than player 2, “player 2 wins” if his/her card is higher than player 1, and the players declare “WAR” if their cards have the same value.

 

CSC104 Exercises: Simple if statements

 

Write the following if statements:

1)      get more paper” if the paper count is less than 10.

 

If statement

Results for 3 different test values

 

 

 

 

 

 

 

 

 

 

2)       buy new computer” if the computer’s age is 3 or older. 

 

If statement

Results for 3 different test values

 

 

 

 

 

 

 

 

 

 

3)      “Grade of A” if a student has an average of 90 or higher. 

 

If statement

Results for 3 different test values

 

 

 

 

 

 

 

 

 

 

4)      “Return allowed” if a customer is attempting to return an item within 90 days of purchase. 

 

If statement

Results for 3 different test values