CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)

Slides:



Advertisements
Similar presentations
Computer Programming w/ Eng. Applications
Advertisements

Introduction to C Programming
CS 1400 Chapter 2 sections 1, 2, 4 – 6, 8,
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Chapter 10.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 CIS 205 Practice Test George Lamperti A word that has a predefined meaning in a C++ program and cannot be used as a variable name is known as.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 Introduction.
1 9/20/06CS150 Introduction to Computer Science 1 Review: Exam 1.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
Introduction to C Programming
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
CS161 Topic #15 1 Today in CS161 Lecture #15 Practicing! Writing Programs to Practice Write a game program (1 player) of Mad Math Reuse the functions to.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
First tutorial.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Today in CS161 Lecture #9**go to Blackboard ** Practicing… Review from Shackelford Reading If statements Loops Begin writing Programs Using if statements.
1 CS 1430: Programming in C++. 2 Literal Values Literal values of int Literal values of float
CS102 Introduction to Computer Programming Chapter 4 Making Decisions.
Week 1 Algorithmization and Programming Languages.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Logic Our programs will have to make decisions on what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if and if-else.
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
Fundamental Programming: Fundamental Programming Introduction to C++
Control Structures (A) Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing.
 Wednesday, 9/18/02, Slide #1 CS106 Introduction to CS1 Wednesday, 9/18/02  QUESTIONS?? HW #1 due today at 5!!  Today: Loops, and two new data types.
# ACS 168 Structured Programming Using the Computer Chapter 2 Spring 2002 Prepared by Shirley White.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
6/3/2016 CSI Chapter 02 1 Introduction of Flow of Control There are times when you need to vary the way your program executes based on given input.
Writing JavaScript Functions. Goals By the end of this unit, you should understand … How to breakdown applications into individual, re-usable modules.
Logic Our programs will have to make decisions in terms of what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if.
Logic Our programs will have to make decisions on what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if and if-else.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Sixth.
1 CS161 Introduction to Computer Science Topic #17.
CHAPTER 10 ARRAYS AND FUNCTIONS Prepared by: Lec. Ghader Kurdi.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
1 CS161 Introduction to Computer Science Topic #8.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
Copyright © 2002 W. A. Tucker1 Chapter 9 Lecture Notes Bill Tucker Austin Community College COSC 1315.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Functions Structured Programming. Topics to be covered Introduction to Functions Defining a function Calling a function Arguments, local variables and.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Data Structures & Algorithms CHAPTER 2 Arrays Ms. Manal Al-Asmari.
CIS 115 All Exercises Devry University (Devry) FOR MORE CLASSES VISIT CIS 115 All Exercises Devry University.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter 2: Introduction to C++
Introduction to C++ October 2, 2017.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Programming Funamental slides
Programming Funamental slides
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Presentation transcript:

CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for) Functions (pass by value, pass by reference) Arrays (specifically arrays of characters)

CS161 Topic #16 2 How to prepare for the Final Exam Best place to start preparing for the final exam is... Homework #6 which has you practice each of the constructs Practice with the demo programs Take them, modify them, replace one loop for one of the other loops Final exam is 2 hours long Closed book, Closed notes It will cover: Algorithms, Ethics, Style, and Programming You will NOT be asked to write a complete program (whew!)

CS161 Topic #16 3 Sample Programming Questions Write a C++ statement to answer each of the following: 1. Display your name to the screen 2. Let’s say you have a variable that contains your age. Show how you would display it on the screen 3. Show how to add 1 to your age

CS161 Topic #16 4 The Basics Write a C++ statement to answer each of the following:  Show an example of an assignment statement. What goes on the left hand side?  What is the difference between integer division and floating point division – can you give an example? portion = 10/3;  what is the answer? portion = 10.0/3.0;  how is this different?

CS161 Topic #16 5 The Basics Write a C++ statement to answer each of the following: 1. Show two example of comments… 2. Where should comments be placed? 3. Assume you have an integer variable “count”. Show how to define (create) the variable. 4. Now, show how to add 2 to the variable “count” and store it in the variable “total”

CS161 Topic #16 6 Sample Programming Questions: Math! Some math…given: int count; and, int total; 1. Multiply count by 4 and store it into total 2. Find the remainder of dividing count by 3, output the result 3. How can you find out if count is an even number? 4. What is the difference between the += and the + operations?

CS161 Topic #16 7 Sample Programming Questions: Trivia Trivia… 1. What does each C++ statement end with? 2. Does cin do input or output? 3. Variables must start with what …. Show an example 4. The << is for input or output? 5. A group of statements, such as the contents of a function are enclosed by what symbols?

CS161 Topic #16 8 Sample Programming Questions Short coding questions 1. Store the integers 62 and 99 in two variables; store the sum of these two in variable total 2. Compute the sales tax on a $52 purchase assuming that sales tax is 4% 3. You have four values (in four different variables). Show how you could calculate the average of all four.

CS161 Topic #16 9 Sample Programming Questions Change the previous questions 1. Read in two integer values and store the sum of these two in variable total 2. Read in the amount of purchase and sales tax and compute the amount of tax. 3. You have four values that you read in from the user (in four different variables). Show how you could calculate the average of all four.

CS161 Topic #16 10 If Statements 1. Write an if statement that checks to see if x is 100 or if y is zero 2. Write an if/else statement that displays a message indicating whether chr (a character variable) is one of the following symbols:. ;, or ! 3. Write an if statement that displays an error message if the variable “grade” is not 0 through 100 (valid values are 0-100).

CS161 Topic #16 11 If Statements 1. Explain what the || does. Give an example of when it could be used 2. Explain what the && does. Give an example of when it could be used 3. True or False: = and == are the same 4. True or False: all lines in a block {} should be indented after the if 5. True or False: x != y is the same as x > y || x < y 6. True or Fasle: y = y

CS161 Topic #16 12 If Statements  The following statement should determine if x is not greater than 20. What is wrong with it: if (!x > 20) 2. The following statement should determine if count is within the range of 0 through 100. What is wrong with it: if (count >= 0 || count <= 100) 3. The following statement should determine if count is within the range of 0 through 100. What is wrong with it: if (count 100)

CS161 Topic #16 13 Loops! 1. Write a while loop that lets the user enters a number. The number should be multiplied by 10 and the result stored in variable product. The loop should continue as long as product contains a value less than Write a for loop that displays 0, 10, 20, 30, 40, 50,…1000

CS161 Topic #16 14 Loops! 1. Write a do while loop that asks the user to enter a number and echoes the number to the screen. It continues to do this as long as a negative value has been entered. 2. Write a loop that displays 10 rows of 15 # signs

CS161 Topic #16 15 Loops! 1. Why should you indent statements in the body of a loop? 2. Which loop would you use if you knew the number of times it was going to iterate (or loop)? 3. Which loop would you use to confirm the user’s input?

CS161 Topic #16 16 Loops! Ask the user to enter in a positive number. Read it in. 1. Then, loop for that many times. Each time through the loop read in a number entered by the user and sum it together with the others. 2. Or, loop for that many times – summing up all of the values from1 until that number. So, if 10 was entered, then it will sum together Write a loop to display a-z characters…be creative!

CS161 Topic #16 17 Functions! 1. Explain pass by value 2. Explain pass by reference 3. What data type can be the returned type of a function 4. What does it mean if a function has a void return type 5. The toupper function is a pass by value function. What does that mean since we are trying to upper case a character? How do we call the function to get an upper case character back?

CS161 Topic #16 18 Functions! 1. How many returned values can a function have? 2. Write a prototype for a function named “calculate” that returns a float and has two integer arguments (age and num) passed by value. 3. Write a prototype for a function named “days”. It should return an integer and have three integer arguments: years, months, and weeks passed by value.

CS161 Topic #16 19 Functions! 1. What is a local variable? 2. If two functions have the same local variable – does it share the same memory or do they use different memory locations? 3. Why do local variables lose their values between calls to the function in which they are defined? 4. Show how you return a value from a function…

CS161 Topic #16 20 Functions! 1. Given this function prototype – show an example of how to call it… void showValue (int quantity); 2. The following statement calls a function named “half”. This function returns a value that is half that of the argument (a floating point value). Write the prototype: 3. True or False: Function prototypes are terminated with a semicolon 4. True or False: The header of a function (where you write the function) is ended witih a semicolon

CS161 Topic #16 21 Arrays 1. Show how to create an array of 100 characters 2. Create an array big enough to hold the word “hello” 3. What is the index of the first element in an array 4. Show how to read in a sentence and store it in one array. Assume the sentence is no longer than 131 characters and it ends with a period

CS161 Topic #16 22 Arrays 1. Display a message if the first character of the sentence is capitalized 2. Write a loop to find out how many lower case letters are in the array 3. If an array contains the word “fun”, what number will strlen return? 4. What is the difference between cin >> array and cin.get(); versus cin.get(array, size);