Topic Reviews For Unit 5 - 6. ET156 – Introduction to C Programming Topic Reviews For Unit 5 - 6.

Slides:



Advertisements
Similar presentations
Chapter 4 Loops Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
Advertisements

4 Control Statements: Part 1.
Chapter 5: Control Structures II (Repetition)
Numeric Types & Ranges. ASCII Integral Type Numerical Inaccuracies Representational error – Round-off error – Caused by coding a real number as a finite.
Introduction to C Programming
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Lecture 10 Flow of Control: Loops (Part 2) COMP1681 / SE15 Introduction to Programming.
1.
Chapter 7: Arrays In this chapter, you will learn about
Data Structures ADT List
LIST PROCESSING.
Module 10: Virtual Memory
Review Pseudo Code Basic elements of Pseudo code
Chapter 8: Arrays.
Chapter 7 - Iteration. Chapter Goals Program repitiation statements – or loops – with the for, while, and do-while statements Program repitiation statements.
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
Programming In C++ Spring Semester 2013 Lecture 3 Programming In C++, Lecture 3 By Umer Rana.
1 Chapter 4 The while loop and boolean operators Samuel Marateck ©2010.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
While loops.
Project 6: Working with If Statements Essentials for Design JavaScript Level One Michael Brooks.
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
Addition 1’s to 20.
Week 1.
Types of selection structures
Pointers and Arrays Chapter 12
Chapter 8 Improving the User Interface
Standard Algorithms Find the highest number. ! Your name and today’s date ! Find the maximum Dim numbers(20) As Integer.
L6:CSC © Dr. Basheer M. Nasef Lecture #6 By Dr. Basheer M. Nasef.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 3 Loops.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
CHAPTER 5: LOOP STRUCTURES Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 5 Looping.
Introduction to Computers and Programming Lecture 8: More Loops New York University.
Introduction to Computers and Programming More Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
Understanding Arrays and Pointers Object-Oriented Programming Using C++ Second Edition 3.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
- SEARCHING - SORTING.  Given:  The array  The search target: the array element value we are looking for  Algorithm:  Start with the initial array.
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops.
Chapter 5: Control Structures II (Repetition)
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
Java Programming: From the Ground Up
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman CP 202 Chapter
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
+ Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 5: Looping.
CSCI 171 Presentation 5. The while loop Executes a block as long as the condition is true general form: while (condition) { statement 1; statement 2;
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Controlling Program Flow with Looping Structures
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 5 Looping.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Unit 6 Data Types and Arrays. Key Concepts Explicit and automatic conversion ASCII Enumerated types Function parameters Arrays Loops and arrays Passing.
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
Arrays. Example Write a program to keep track of all students’ scores on quiz 1. Need a list of everyone’s score Declare 14 double variables? What about.
CC213 Programming Applications Week #2 2 Control Structures Control structures –control the flow of execution in a program or function. Three basic control.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 6.
REPETITION CONTROL STRUCTURE
while Repetition Structure
EKT120 COMPUTER PROGRAMMING
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
Lecture 7: Repeating a Known Number of Times
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Alternate Version of STARTING OUT WITH C++ 4th Edition
EPSII 59:006 Spring 2004.
Presentation transcript:

Topic Reviews For Unit 5 - 6. ET156 – Introduction to C Programming Topic Reviews For Unit 5 - 6.

Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might never execute.

Loop Review

Loop Review A variable used to store a value being computed in increments during a loop’s execution is called an accumulator.

Loop Review A for loop can either increment or decrement the loop control variable’s value by any value.

Loop Review

This is an example of a sentinel-controlled loop. Loop Review You want to write a program that prompts the user for a value until the user enters -1. This is an example of a sentinel-controlled loop.

Loop Review

What type of loop always executes at least once? Loop Review What type of loop always executes at least once? a. Sentinel-controlled loop b. For loop c. Do-while loop d. Counter-controlled loop

Loop Review

A variable that has a memory address as its value is called a pointer. Pointers A variable that has a memory address as its value is called a pointer.

Process Flow The process of testing flow of control between a main function and its subordinate functions is called top-down testing.

Integers Loss of accuracy due to round- off errors may occur when performing mathematical operators with integer values. a. True b. False

ASCII codes Which of the following characters has the lowest valued ASCII character code? a. X b. a c. A d. 6

Arrays The subscript of the first element in an array is 0. The Eight Elements of Array x

Figure 8.2 Arrays answer and score

Figure 8.3 Program to Print a Table of Differences

Figure 8.3 Program to Print a Table of Differences (cont’d)

A function’s return type cannot be an array. Functions and arrays A function’s return type cannot be an array.

Function fill_array

Parallel Arrays b. Multidimensional array c. Parallel arrays d. Stack You need to store the average rainfall, high temperature, and low temperature for each day in the year. Average rainfall must be stored as a double. Temperatures must be stored as integers. What type of data structure could you use? a. Enumeration b. Multidimensional array c. Parallel arrays d. Stack

Function to Add Two Arrays

Function Data Areas for add_arrays(x, y, x_plus_y, 5);

Stacks When using a stack, all new elements are added to the top of the stack. Only the top element can be removed from the stack.

Arrays and Flags A program sets a flag within a loop to indicate when an element has been found in an array. This program is performing a linear search.

All elements in a multidimensional array have the same data type.

Copy this code. What changes are needed to make it work. int i = 0; myArray[]= {2, 4, 6, 8, 10, 12, 14, 16, 18, 20} while (i < 10) { printf("%d, " myArray[i]); } The way that it is written, the value 2 will be output infinitely.

What will be the value of y after the following code executes? int x = 0, n = 2; do { x *= n + 1; n++; }while (n < 10); a. 0 b. 1 c. 10 d. 11

You want to write a program that will loop until an event occurs You want to write a program that will loop until an event occurs. This is an example of ________________. a. an accumulator-controlled loop b. a conditional loop c. a counter-controlled loop d. a sentinel-controlled loop

What type of loop always executes at least once. a What type of loop always executes at least once? a. Sentinel-controlled loop b. For loop c. Do-while loop d. Counter-controlled loop A variable that stores a 1 or 0 that is used to indicate whether an event has occurred or not is called? a. an accumulator b. a flag c. an increment operator d. a sentinel value

What will be the value of y after the following code executes What will be the value of y after the following code executes? int x = 0, n = 2; do { x *= n + 1; n++; }while (n < 10); a. 0 b. 1 c. 10 d. 11

What will be the value of x after executing the following code What will be the value of x after executing the following code? int i, j, x=0; for (i=0; i< 3; ++i) { for(j=1; j< 2; ++j) x += i * j; } a. 0 b. 3 c. 6 d. 9

Assume that age = 18. What will be the output of the following code Assume that age = 18. What will be the output of the following code? switch (age) { case 16: case 17: printf("Old enough to drive/n"); case 18: case 19: case 20: printf("Old enough to vote/n"); case 21: printf("Old enough to drink/n"); } a. Nothing b. Old enough to vote c. Old enough to vote Old enough to drink d. Old enough to drive Old enough to vote

Assume that price = $4.00. What would be the value of total after executing the following code? if (price > 100) shipping = 20; else if (price < 50) shipping = 10; else if (price < 5) shipping = 0;  if (price > 10) tax = price * 0.5; else tax = price * 0.1; total = price + tax + shipping; a. 14.20 b. 14.04 c. 4.20 d. 4.04

What will the output be when the following code executes What will the output be when the following code executes? #define SIZE 5 int main(void) { int cubes, i; for (i=0; i<SIZE; ++i) { cubes = i * i * i; printf(“%f “, cubes); } a. 0 1 8 27 64 b. 0 1 8 27 64 125 c. 0.0 0.0 0.0 0.0 0.0 d. No output

What will be the output when the code below executes What will be the output when the code below executes? int i = 0; while (i < 10) { printf(" The value of i is: %d”, i); } a. 1, 2, 3, 4, 5, 6, 7, 8, 9 b. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 c. No values will be output. d. The value 0 will be output infinitely.

You want to write a program that prompts the user for a value until the user enters -1. This is an example of ________________. a. an accumulator-controlled loop b. a conditional loop c. a counter-controlled loop d. a sentinel-controlled loop

A for loop _________________________________. a A for loop _________________________________. a. will never result in an infinite loop b. increases the loop control variable’s value by 1 with every execution c. can increment the loop control variable’s value by any positive increment d. can either increment or decrement the loop control variable’s value by any value

A variable used to store a value being computed in increments during a loop’s execution is called _____________________. a. an accumulator b. a flag c. an increment operator d. a sentinel value

The statements within a while loop execute _________________________. a. at least once and continue executing until the loop repetition condition becomes true b. at least once and continue executing until the loop repetition condition becomes false c. until the loop repetition condition becomes false and might never execute d. until the loop repetition condition becomes true and might never

The controlling expression for a switch statement can be of type ___________. a. int, char, or double b. int or double c. int or char d. char or double

Using nested if statements is more efficient than using a sequence of if statements. a. True b. False