Presentation is loading. Please wait.

Presentation is loading. Please wait.

Midterm Review.

Similar presentations


Presentation on theme: "Midterm Review."— Presentation transcript:

1 Midterm Review

2 First Midterm Exam Friday, Oct 6th Closed book
But.. you may bring a cheat sheet! One side of an A4-sized paper Partial access to computers

3 Part II (paper or computer based)
Part I (paper based) Multiple choices Write the output of a program Part II (paper or computer based) Programming Visual Studio only You shouldn’t use the network

4 Variables a place to hold a number or data of other types
Variable names Start with a letter or the underscore Remaining can be letters, numbers or underscore x x1 3X _abc %change data-1 PROG.CPP Big_Bonus C++ is case-sensitive rate RATE Rate

5 The output function cout
c(C++ language)out(output) c(C++ language)in(input) cout<<whatever data you want to output; cout<<“Welcome to CMPT102!”; << represents the flow of the data.

6 Input Function cin cout: output to screen cin: input from keyboard
cout<<whatever you want to output; cin>>variable_name; cin>>variable1>>variable2; Or cin>>variable1; cin>>variable2;

7 http://software. intel

8 The char Type Short for character
Any single character from the keyboard a letter, a digit, or punctuation mark int number; char letter; int number = 5; char letter = ‘a’; char letter = ‘A’;

9 The Class string #include <string> Concatenation
char letter; string message; char letter = ‘a’; string message = “hello”; Concatenation string firstName = “Chuck”; string lastName = “Norris”; string name = firstName + lastName; //string name = firstName + “ “ + lastName;

10 getline() To read the whole line of input into a string string name;
getline(cin, name);

11 The bool Type Boolean Two values bool flag; bool isPrime = false; True

12 Arithmetic Operators +, -, *, / int / int -> int
double / int -> double 10/3, 5/2, 11/3

13 Modulus % 17 % 5 = 2 23 % 2 = ? 20 % 3 = ? How to determine if a number is even/odd?

14 Syntax for if-else if (condition) Yes_Statement else No_Statement
Chooses between two alternative actions

15 The And Operator If score is greater than 0 and less than 100...
(score > 0) && (score < 100) is true only if both are true

16 The Or Operator (score1 >= 60) || (score2 >= 60)
is true if one or both are true

17 The Not Operator !(score > 60) is equivalent to score <= 60

18 Nested Statements

19 Multiway if-else syntax
if (condition_1) Action_1; else if (condition_2) Action_2; ... else if (condition_N) Action_N; else Action_For_All_Other_Cases;

20 The Conditional Operator
Can use to create short if/else statements Format: expr ? expr : expr; x<0 ? y=10 : z=20; First Expression: Expression to be tested 2nd Expression: Executes if first expression is true 3rd Expression: Executes if the first expression is false

21 Type Casting static_cast<Type>(Value) double -> int
static_cast<int>(9.2) static_cast<int>(number)

22 switch Statement Syntax
switch (Controlling_Expression) { case result_1: Statement_Sequence_1; break; case result_2: ... case result_n: Statement_Sequence_n; default: Default_Statement_Sequence; }

23 Syntax of the while Statement
while (Boolean_Expression) { Statement_1; // body Statement_2; // iteration ... } Statement;

24 The do-while Statement
{ Statement_1; Statement_2; ... } while (Boolean_Expression); Statement; while (Boolean_Expression);

25 Announcements Homework 3 is out No class on Tuesday, Oct 10
Due on Friday, Oct 13 No class on Tuesday, Oct 10 Follows a Monday schedule


Download ppt "Midterm Review."

Similar presentations


Ads by Google