T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout << x + y / z – k << endl << ;

Slides:



Advertisements
Similar presentations
Recursion.
Advertisements

Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
Engineering Problem Solving With C++ An Object Based Approach Chapter 9 Pointers and Creating Data Structures.
CMPUT 101 Lab # 5 October 22, :00 – 17:00.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 5. Functions.
Functions CS 308 – Data Structures. Function Definition Define function header and function body Value-returning functions return-data-type function-name(parameter.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
1 6/20/2015CS150 Introduction to Computer Science 1 Functions Chapter 6, 8.
True/False. False True Subject May Go Here True / False ? Type correct answer here. Type incorrect answer here.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
What is the out put #include using namespace std; void main() { int i; for(i=1;i
Basic Elements of C++ Chapter 2.
Scope Accessibility of Names. Review We’ve seen that C++ permits a programmer to declare names and then use those names in a manner consistent with their.
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
USER-DEFINED FUNCTIONS. STANDARD (PREDEFINED) FUNCTIONS  In college algebra a function is defined as a rule or correspondence between values called the.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
Introduction to C++ Basic Elements of C++. C++ Programming: From Problem Analysis to Program Design, Fourth Edition2 The Basics of a C++ Program Function:
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 2.
Review Binary Numbers Bit : 0 or 1 Byte: 8 bites 256 different values 2 8 KB : 1024 bytes 2 10 bytes MB : 1024 * 1024 bytes 2 10 * 2 10 (2 20 ) bytes GB.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
CSC 107 – Programming For Science. Today’s Goal  Discuss writing functions that return values  return statement’s meaning and how it works  When and.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Selection Control Structures (L08) * Selection Criteria * if Statements * The if-else Statement Selection Control Structure Dr. Ming Zhang.
CHAPTER 10 ARRAYS AND FUNCTIONS Prepared by: Lec. Ghader Kurdi.
Instructor - C. BoyleFall Semester
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 2: Basic Elements of C++
Function User defined function is a code segment (block) that perform an specific action. Function Definition: Function Definition: Return_DT F_name (
L what are executable/non-executable statements l out of the ones below which constructs are executable #include p=3.14; const double PI=3.14; int myfunc(int);
LINKED LISTS Midwestern State University CMPS 1053 Dr. Ranette Halverson 1.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
Fundamental Programming Fundamental Programming More Expressions and Data Types.
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.
Variables  A piece of memory set aside to store data  When declared, the memory is given a name  by using the name, we can access the data that sits.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
MR. CRONE Generating Random Numbers. Random Numbers Many programs require the computer to generate random numbers Random numbers are used in many applications.
CSII Final Review. How many bits are in a byte? 8.
 By the end of this section you should be able to: ◦ Differentiate between sequence, selection, and repetition structure. ◦ Differentiae between single,
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
for( 起始條件 ; 判斷式 ; 條件運算 ){ // 迴圈內容 } while( 判斷式 ){ // 迴圈內容 } do{ // 迴圈內容 } while( 判斷式 ) ;
Branching statements.
Chapter 3 Selection Statements
Chapter 2: Basic Elements of C++
Chapter Topics The Basics of a C++ Program Data Types
Variables Mr. Crone.
LESSON 2 Basic of C++.
Section 3 Review Mr. Crone.
Basic Elements of C++.
Variables A piece of memory set aside to store data
Bools & Ifs.
Chapter 2: Basic Elements of C++
Programming fundamentals 2 Chapter 2:Function
Basic Elements of C++ Chapter 2.
Chapter 2 – Getting Started
Multiple Files Revisited
Value returning Functions
Bools & Ifs.
CS150 Introduction to Computer Science 1
If Statements.
Fundamental Programming
CS 101 First Exam Review.
HNDIT11034 More Operators.
ASEE / GradSWE C++ Workshop
Presentation transcript:

T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout << x + y / z – k << endl << ;

T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout << x + y / z – k << endl << ; // insertion symbol causes error

What does the following code print? cout << double(4 / 3) – 2 << endl;

What does the following code print? cout << double(4 / 3) – 2 << endl; // // -1

What does the following code print int x = 5; x +=20; x = sqrt(x); x--; cout << x << endl;

What does the following code print int x = 5; x +=20; // 25 x = sqrt(x); // 5 x--; // 4 cout << x << endl; // 4

What does the following code print? int x = 5, y = 13; x *= 5; x ++; x /= 4; y = 100; cout << y << endl;

What does the following code print? int x = 5, y = 13; x *= 5; x ++; x /= 4; y = 100; cout << y << endl; // Prints 100

What does the following code print? int x = 4, y = 5, z = 6; x = (x + y) % z; x++; y++; x += y; cout << x << endl;

What does the following code print? int x = 4, y = 5, z = 6; x = (x + y) % z; //9 mod 6 = 3 x++; // x = 4 y++; // y = 6 x += y; // x = 10 cout << x << endl; // Prints 10

What does the following code print? double x = 1.5, y = 2.5, z = 3; cout << int (z)/int(y) + x << endl;

What does the following code print? double x = 1.5, y = 2.5, z = 3; cout << int (z)/int(y) + x << endl; // // 2.5

What does the following code print? const double MYSTERY = 4.5; int x = 3, y = 4; cout << MYSTERY + 4; const MYSTERY2 = 3; cout << MYSTERY2 + 4;

What does the following code print? const double MYSTERY = 4.5; int x = 3, y = 4; cout << MYSTERY + 4; const MYSTERY2 = 3; // ERROR! cout << MYSTERY2 + 4;

What does the following code print? const int MYSTERY = 4; int y = 1, z = 2; cout << sqrt(MYSTERY) + pow(MYSTERY, z) * 1 << endl;

What does the following code print? const int MYSTERY = 4; int y = 1, z = 2; cout << sqrt(MYSTERY) + pow(MYSTERY, z) * 1 << endl; // * 1 // 18

What does the following code print? double x = 0.5; int y = 20; cout << (y%5) * x << endl;

What does the following code print? double x = 0.5; int y = 20; cout << (y%5) * x << endl; // 0 * 0.5 // 0

int x =1, y = 2, z = 3, p = 4, q = 5; x ++; x+=y; x++; x+=z; x++; x+=p; cout << x << endl;

int x =1, y = 2, z = 3, p = 4, q = 5; x ++; // x = 2 x+=y; // x = 4 x++; // x = 5 x+=z; // x = 8 x++; // x = 9 x+=p; // x = 13 cout << x << endl;

double x = 0.5, y = 1.5; cout << int(x + x + x + x + y) << endl;

double x = 0.5, y = 1.5; cout << int(x + x + x + x + y) << endl; // // 3

int x = 15, y = 2, z = 3; x = x + sqrt(pow(z, y) + 16); cout << x << endl;

int x = 15, y = 2, z = 3; x = x + sqrt(pow(z, y) + 16); // 15 + sqrt(9 + 16) // // 20

int x, y, z; x = 15; z = y = x; cout << “ z = “ << z << endl; cout << “y = “ << y << endl; cout << “x = “ << x << endl;

int x, y = 5, z = 4; x = 15; z = y = x; cout << “ z = “ << z << endl; // z = 15 cout << “y = “ << y << endl; // y = 15 cout << “x = “ << x << endl; // x = 15

const double y = 55.5; y++; cout << y << endl;

const double y = 55.5; y++; // ERROR cout << y << endl;

double y = 5.5; cout << int(y) << endl; cout << y << endl;

double y = 5.5; cout << int(y) << endl; // 5 cout << y << endl; // 5.5

int y = 4, x = 5, z = 7; x = z; cout << “z = “ << z << endl; cout << “x = “ << x << endl;

int y = 4, x = 5, z = 7; x = z; cout << “z = “ << z << endl; // z= 7 cout << “x = “ << x << endl; // x = 7

cout << abs(int(5.9) * -1) << endl;

// abs( 5 * -1) // abs(-5) // 5

cout<< int(5) / double(2) << endl;

// 5 / 2.0 // 2.5

Type the symbol for the assignment operator.

// =

What is the difference between syntax and semantics?

// Syntax – Rules for creating statements // Semantics – How we interpret statements

True or false? bool x = true; int y = 5, z = 6; (y > z && x )

True or false? bool x = true; int y = 5, z = 6; (y > z && x ) // F

True or false? bool x = true, y = false, z = false (x && !y && !z)

True or false? bool x = true, y = false, z = false (x && !y && !z) True!

What does the code print? int x = 4, y = 2, z = 1; if(y ==2) if( z ==1) x += 6; else x =4; else x += 8; cout << x << endl;

What does the code print? int x = 4, y = 2, z = 1; if(y ==2) // True if( z ==1) // True x += 6; // x = 10 else x =4; else x += 8; cout << x << endl;

What does the code print? int x = 54; if(x>= 5 && x <= 100) x = 4; else x = 5; cout << x << endl;

What does the code print? int x = 54; if(x>= 5 && x <= 100) // True x = 4; // x = 4 else x = 5; cout << x << endl; // 4

What does the code print? int x = 14; if(x < 10) cout << “1”; if (x > 10) cout << “2”; if ( x >10 && x < 20) cout << “3”; if(x ==10 || x ==14) cout << “4”;

What does the code print? int x = 14; if(x < 10) // false cout << “1”; if (x > 10) // true cout << “2”; if ( x >10 && x < 20) // true cout << “3”; if(x ==10 || x ==14) // true cout << “4”; Prints: 234

const int RADIUS = 3.14; double num = 5.5; bool x = false; if(!x) RADIUS += 4; else num= 17; cout << num << endl;

const int RADIUS = 3.14; double num = 5.5; bool x = false; if(!x) RADIUS += 4; // ERROR! else num= 17; cout << num << endl;

int x = 4, y = 5; bool isWorking = false; if(x<y) if(isWorking) isWorking = false; else isWorking = true; else y = 20; cout << isWorking << endl;

int x = 4, y = 5; bool isWorking = false; if(x<y) if(isWorking) isWorking = false; else isWorking = true; else y = 20; cout << isWorking << endl; // Prints 1

What is the decimal equivalent of the following binary number?

What is the decimal equivalent of the following binary number?

Write 56 as a binary number.

** One more question

Write 56 as a hexadecimal number.

38

What does the code below print? for(int i = 0; i <= 3; i ++) cout << i;

What does the code below print? for(int i = 0; i <= 3; i ++) cout << i; //Prints:

What does the code below print? int x = 4; while(x < 10){ cout << x; x += 2; }

What does the code below print? int x = 4; while(x < 10){ cout << x; x += 2; } // Prints: 4 6 8

What does the code below print? for(int i = 0; i < 10; i *=2) cout << i;

What does the code below print? for(int i = 0; i < 10; i *=2) cout << i; // INFINITE LOOP

What does the code below print? int x = 5; while(x !=-1){ cout << x; x -= 2; }

What does the code below print? int x = 5; while(x !=-1){ cout << x; x -= 2; } // Prints: 5 3 1

Using interval notation, what range does the code below specify? rand() %

Using interval notation, what range does the code below specify? rand() % [10,20)

Using interval notation, what range does the code below specify? rand() % 5+15

Using interval notation, what range does the code below specify? rand() % 5+15 [15,20)

Using interval notation, what range does the code below specify? rand() % 7+50

Using interval notation, what range does the code below specify? rand() % 7+50 [50,57)

Using rand(), write a statement that creates a random number from [15, 20]

rand() %

Using rand(), write a statement that creates a random number in the interval: [50, 100)

rand() %

What does the code below print? int x = 0; while(x <5){ if(x % 2 == 0) cout << “$”; else cout << “#”; x ++; }

What does the code below print? int x = 0; while(x <5){ if(x % 2 == 0) cout << “$”; else cout << “#”; x ++; } // $#$#

What does the code below print? int x = 5; while(x < 10){ if(x % 3 == 0) cout << “$”; else cout << “#”; x ++; }

What does the code below print? int x = 5; while(x < 10){ if(x % 3 == 0) cout << “$”; else cout << “#”; x ++; } //Prints: #$##$

What does the code below print? int x = 0; while (x <= 4){ x++; cout<< x; }

What does the code below print? int x = 0; while (x <= 4){ x++; cout<< x; }// Prints: 12345

True/False  A parameter of a function is a value that is passed into a function when the function is called.

Insert the correct line of code where indicated. void change (double); int main () { double amount; cout >amount; // Insert Code Here // return 0; }

Give me on possible answer!  The purpose of a function header is to....

True/False  The function that is called into use is called the called function.