Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMPUT 101 Lab # 5 October 22, 2007 14:00 – 17:00.

Similar presentations


Presentation on theme: "CMPUT 101 Lab # 5 October 22, 2007 14:00 – 17:00."— Presentation transcript:

1 CMPUT 101 Lab # 5 October 22, 2007 14:00 – 17:00

2 Data types in C/C++ int -- numbers without decimals between +32767 and -32768. 0, -3, 5, 190, -202, etc. double – decimal numbers 0.5, 0.003, 3.37, 1032.0 char – any single symbol ‘c’, ‘g’, ‘5’, ‘(‘, etc.

3 First example int num; cout > num; cout << "The number entered is : " << num; cout – standard output device (monitor) cin – standard input device (keyboard)

4 Comparison Vs. assignment Use ‘=‘ to assign a value to a variable. int number; number = 4; But, use “==“ to compare values resulting in true/false. if (number == 4) { cout << "That number is 4." << endl; } cout << “The number is “ << number << endl;

5 Curly brackets { } Use curly brackets { } when you have more than one statement belonging to an if, else, or while statement. if (num > 0) { num = num + 1; cout << "positive"; } ------- 1 else if (num < 0) { num = num - 1; cout << "negative"; } ------- 2 else cout << "zero";

6 While loop in C++ int num = 0; while (num < 5) { cout << "Num is " << num << endl; num = num + 1; }

7 If – else statement in C++ if (relation) { block-statement; } else{ block-statement; }

8 Relations in C++ Please refer to A brief list of C++ commands

9 Notes Identifier names should be descriptive. e.g. int celcius; is descriptive, int t; is not descriptive. If not saved on H:drive may not be able to execute Do not use capital letters in a file name or folder, this causes problems. Close all executions (runs) before compile codes, otherwise you won’t see the effect of the new codes.

10 Lab exercises Ex 1 and 2 - output must be in format shown. See example runs


Download ppt "CMPUT 101 Lab # 5 October 22, 2007 14:00 – 17:00."

Similar presentations


Ads by Google