1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

User-Defined Functions Like short programs Can operate on their own data Can receive data from callers and return data to callers.
1 Lecture 16:User-Definded function I Introduction to Computer Science Spring 2006.
Chapter 7: User-Defined Functions II
Functions Most useful programs are much larger than the programs that we have considered so far. To make large programs manageable, programmers modularize.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
CS150 Introduction to Computer Science 1
Overview creating your own functions calling your own functions.
1 6/20/2015CS150 Introduction to Computer Science 1 Functions Chapter 6, 8.
Chapter 5: Control Structures II (Repetition)
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
CPSC230 Computers & Programming I Lecture Notes 20 Function 5 Dr. Ming Zhang.
1 CS 105 Lecture 10 Functions Version of Mon, Mar 28, 2011, 3:13 pm.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
File Review Declare the File Stream Object Name –ofstream for output to file –ifstream for input from file Associate a File Name with the File Stream Object.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
1 Lecture 3 Part 1 Functions with math and randomness.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 9 Clicker Questions September 29, 2009.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Functions in C Programming Dr. Ahmed Telba. If else // if #include using namespace std; int main() { unsigned short dnum ; cout
CPS120: Introduction to Computer Science Decision Making in Programs.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 6 September 17, 2009.
Chapter 5 Control Structure (Repetition). Objectives In this chapter, you will: Learn about repetition (looping) control structures Explore how to construct.
Computer Science Department LOOPS. Computer Science Department Loops Loops Cause a section of your program to be repeated a certain number of times. The.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Functions Outline 5.1Introduction 5.2Program Modules.
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
KIC/Computer Programming & Problem Solving 1.  Introduction  Program Modules in C  Math Library Functions  Functions  Function Definitions  Function.
Chapter 3 Part I. 3.1 Introduction Programs written in C ◦ All statements were located in function main Programs written in C++ ◦ Programs will consist.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter Functions 6. Modular Programming 6.1 Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules.
Function prototype A function must be declared before it can be referenced. One way to declare a function is to insert a function prototype before the.
C++ Programming Lecture 13 Functions – Part V The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Chapter 3: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Lecture 2 Functions. Functions in C++ long factorial(int n) The return type is long. That means the function will return a long integer to the calling.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
 2000 Prentice Hall, Inc. All rights reserved Introduction Divide and conquer –Construct a program from smaller pieces or components –Each piece.
Introduction to Programming Lecture 6. Functions – Call by value – Call by reference Today's Lecture Includes.
Lecture 17: 4/4/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
FUNCTIONS (C) KHAERONI, M.SI. OBJECTIVE After this topic, students will be able to understand basic concept of user defined function in C++ to declare.
1 This week Basics of functions Stack frames Stack vs. Heap (brief intro) Calling conventions Storage classes vs. scope Library functions Overloading.
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Lecture 12: Dividing Up Work. Why Using Functions Divide-and-conquer making large program development more manageable. Software reusability Use existing.
Introduction to Programming
Suppose we want to print out the word MISSISSIPPI in big letters.
CSC113: Computer Programming (Theory = 03, Lab = 01)
This technique is Called “Divide and Conquer”.
Programming Fundamentals
User-Defined Functions
Lecture 4B More Repetition Richard Gesick
Introduction to Functions
CISC181 Introduction to Computer Science Dr
CS150 Introduction to Computer Science 1
Chapter 6: User-Defined Functions I
Chapter 9: Value-Returning Functions
CISC181 Introduction to Computer Science Dr
Fundamental Programming
CS150 Introduction to Computer Science 1
Introduction to Programming
Functions Imran Rashid CTO at ManiWeber Technologies.
Introduction to Programming
Lecture 3 More on Flow Control, More on Functions,
Presentation transcript:

1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009

Consider the loop: for ( int x = 1; x < 5; increment ) cout << x + 1 << endl; If the last value printed is 5, which of the following might have been used for increment? (a) x++ (b) x += 1 (c) ++x (d) Any of the above 2

Which of the following for headers is not valid? (a) for( int i = 0; i < 10; i++) (b) int i = 1; for( ; i < 10; i++ ) (c) for( int i = 0, int j = 5; ; i++) (d) for( int i = 0; i < 10; ) 3

In a switch structure (a) a break is required after each case (b) multiple actions do not need to be enclosed in braces (c) a default case is required (d) a break is required after the default case 4

The following program segment will int counter = 1; do { cout << counter << “ “; } while ( ++counter <= 10 ); (a) print the numbers 1 through 11 (b) print the numbers 1 through 10 (c) print the numbers 1 through 9 (d) cause a syntax error 5

In C++, the condition 4 > y > 1 (a) evaluates correctly and could be replaced by ( 4 > y && y > 1 ) (b) does not evaluate correctly and should be replaced by ( 4 > y && y > 1 ) (c) evaluates correctly and could not be replaced by ( 4 > y && y > 1 ) (d) does not evaluate correctly and should not be replaced by ( 4 > y && y > 1 ) 6

Consider the following code, assuming that x is an integer variable with an initial value of 12: if( x = 6 ) cout << x; What is the output? (a) 6 (b) 12 (c) nothing (d) a syntax error is produced 7

All of the following are true of functions except: (a) they define specific tasks that can be used at many points in a program (b) a function call must specify the name and arguments of the function (c) the definition of a function usually is visible to other functions (d) the implementation of a function is hidden from the caller 8

A valid reason for building programs out of functions is (a) that the divide-and-conquer approach facilitates program construction (b) that pre-existing functions can be used to create new programs (c) the avoidance of code repetition within a program (d) all of the above 9

The function prototype double mySqrt( int x ); (a) declares a function called mySqrt which takes an integer as an argument and returns a double (b) defines a function called mySqrt which takes an argument of type x and returns a double (c) declares a function called mySqrt which takes a double as an argument and returns an integer 10

Which of the following will not produce a syntax error? (a) omitting a return type from a function definition (b) returning a value from a function declared as void (c) declaring a function parameter again inside a function (d) using the same names for arguments passed to a function and the corresponding parameters in the function definition 11