UTPA STEM/CBI Courses/Computer Science/Selection

Course Title: Computer Science I

Lecture Topic: Selection

Instructor: Laura Grabowski

Institution: UTPA

Backwards Design

edit

Course Objectives

  • Primary Objectives- By the next class period students will be able to:
    • Understand concepts of how selection structures work: Test current condition (while program executes), outcome of test, decision based on outcome
    • Understand how different selection structures work (if, if/else, nested if/else, switch)
    • Write C++ code for different selection structures
  • Sub Objectives- The objectives will require that students be able to:
    • Write logical and relational expressions
    • Identify syntax errors in selection statements
  • Difficulties- Students may have difficulty:
    • Understanding the underlying concepts involved
    • Remembering the correct syntax for the conditional expressions
  • Real-World Contexts- The concepts of decision-making are grounded in the real world -- we do it all the time. The details of this lesson, however, relate specifically to the context of learning how to design and write computer programs. In that context, some interesting applications include:
    • Designing video games
    • Comparison-based searching and sorting algorithms

Model of Knowledge

  • Concept Map
    • Analysis of problem, requires
      • Critical thinking skills
      • Summarizing skills
    • Design of solution (algorithm design), requires
      • Problem decomposition skills
      • Understanding of underlying programming concepts
        • Data types
        • Sequence
        • Control structures
          • Selection -- this lesson
          • Repetition
        • Modular programming (functions)
        • Arrays
        • Abstract data types
          • Structures
          • Classes
        • Pointers
        • Data structures and algorithms
          • Trees
          • Searching
          • Sorting
      • Use of design tools -- pseudo-code writing skills
    • Implementation of solution
      • Tools of the trade
        • Learned in Lectures through
          • Slides
          • Analogies
          • Sample programs
          • Group exercises
        • Using C++ to implement underlying concepts (listed above)
        • Applying underlying concepts, covered in lectures using
          • In-class exercises
          • Lab assignments
          • Homework assignments


  • Content Priorities
    • Enduring Understanding
      • Understand fundamental programming concepts
      • Understand basics of algorithm design
      • Be able to design, write, debug, and test simple programs in C++
    • Important to Know and Do
      • Familiarity with programming environments such as Microsoft Visual C++
      • Document algorithm design with tools such as pseudo-code and flow diagrams
    • Worth Being Familiar with
      • Time management


Assessment of Learning

  • Formative Assessment
    • In Class (groups)
      • Pre-lesson quiz after student has read chapter.
      • Team coding exercises: Work with the group to write code for selection statements.
      • Code traces. Walk though code fragments provided and determine how statements will execute based on differing conditions at run-time.
    • Homework (individual)
      • Lab assignments using selection
      • Worksheet: writing selection code fragments, executing code traces
  • Summative Assessment
    • Unit quiz
    • Exam

Legacy Cycle

edit

OBJECTIVE

By the next class period students will be able to:

  • Understand concepts of selection structures: Test current condition (while program executes), outcome of test, decision based on outcome
  • Understand how different selection structures work (if, if/else, nested if/else, switch)
  • Write C++ code for different selection structures

The objectives will require that students be able to:

  • Write logical and relational expressions
  • Identify syntax errors in selection statements


THE CHALLENGE

You want to enter a game programming contest. You need to write a program to play the game “Rock-Paper-Scissors”. To win the contest, your game must be able to beat a human player in at least five out of ten consecutive games. How can you make your program win the contest?

GENERATE IDEAS

  • Play several rounds of two-player “Rock-Paper-Scissors” with your group.
    • Make sure everyone understands how the game works.
    • Observe, record your ideas about, and then discuss:
      • What strategies did you try?
      • What strategies seem to win?
  • Think about and write down your ideas about how you might write an algorithm to implement the game (individually).
  • Discuss your algorithm ideas with your group.
  • Brainstorm on what you need to implement your algorithms in C++
    • What do you know that you can use?
    • What do you sort of remember but need to review or have more details on?
    • What don’t you know that you need to know in order to solve the problem?

MULTIPLE PERSPECTIVES

  • From the group discussions, groups share with class
    • What sorts of strategies do you need to implement to program the game?
    • What do you know? What do you need to know to solve the problem?
  • Lecture on selection (if, if/else, nested if/else) to help students gain understanding of selection structures. Organizing question for the lecture is “What do we need to know in order to write our “Rock-Paper-Scissors” program?
    • The rules of the game
    • How to compare the players’ actions (relational and logical tests) and make decisions based on what is happening at program run-time (selection).

RESEARCH & REVISE

  • Students will work in groups to complete an exercise on writing code for simple selection statements.
  • Students will outline their ideas for the “Rock-Paper-Scissors” program.

TEST YOUR METTLE

Students will receive feedback on their exercise solutions and on their game program ideas. Students will be given a quiz at the beginning of the next class.


GO PUBLIC

Students will be able to answer the questions about how to make run-time decisions in a program. Students will also complete lab assignments and homework assignments that focus on using selection structures.

Pre-Lesson Quiz

edit

For Questions 1-4, use the following declarations to evaluate the given expressions as TRUE or FALSE.

int x = 8;
int y = 15;
double myVal1 = 2.5;
double myVal2 = 5.8;

1 x < y

TRUE
FALSE

2 x != x

TRUE
FALSE

3 myVal1 > myVal2

TRUE
FALSE

4 myVal2 < 5.9

TRUE
FALSE

5

Given the declarations

bool legalAge;
int age = 23;

is legalAge true or false after the following statement is executed?

legalAge = (age >= 21);

TRUE
FALSE


Test Your Mettle Quiz

edit

1 Which of the following C++ statements is an example of one-way selection?

if (score < 60) grade = ‘F’ else grade = ‘P’;
if (score < 60) grade = ‘F’;
if (score < 60) grade = 'F' else if (score > 89) grade = 'A';

2

The expression

if hours < 40

contains a syntax error. Which of the following corrects that error?

if hours < 40;
if int hours < 40
if (hours < 40)

3

The expression

if (balance = 0)

contains a logical error. Which of the following corrects that error?

if (balance == 0)
if (balance = 0);
if (balance != 0)

4 What will be the output of the following code if the input is 5?

int value;
bool correct = false;
cin >> value;
if (value == 8)
   correct = true;
if (correct)
   cout << "Great job!"
else
   cout << "Nope, fooled you!"

Great job!
Nope, fooled you!
Nothing is output