COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.

Slides:



Advertisements
Similar presentations
Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
Advertisements

COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
If Statements & Relational Operators Programming.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
Programming Switch command. COMP102 Prog. Fundamentals: Switch command / Slide 2 Multiple Selection: The switch Statement value1 action 1 value2 action.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
1 9/20/06CS150 Introduction to Computer Science 1 Review: Exam 1.
If Statements. COMP104 If / Slide 2 Three Program Structures * Sequence - executable statements which the computer processes in the given order * Choice.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Computer Science 1620 Function Scope & Global Variables.
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
1 9/25/06CS150 Introduction to Computer Science 1 Nested Ifs, Logical Operators, exit() Page 194.
How Create a C++ Program. #include using namespace std; void main() { cout
1 Midterm Review COMP 102. Tips l Eat a light meal before the exam l NO electronic devices (including calculators, dictionaries, phones, pagers, etc.)
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
What is the out put #include using namespace std; void main() { int i; for(i=1;i
Loops Programming. COMP104 Lecture 9 / Slide 2 Shortcut Assignment l C++ has a set of operators for applying an operation to a variable and then storing.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Basic Elements of C++ Chapter 2.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
CS31: Introduction to Computer Science I Discussion 1A 4/9/2010 Sungwon Yang
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
C++ Programming: Basic Elements of C++.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 3 Selections.
Additional Control Structures. Chapter 9 Topics Switch Statement for Multi-way Branching Do-While Statement for Looping For Statement for Looping Using.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 6 September 17, 2009.
Chapter 7 Additional Control Structures. Chapter 7 Topics l Switch Statement for Multi-Way Branching l Do-While Statement for Looping l For Statement.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 3 Selections.
1 ELEC 206 Chapter 3 Control Structures 5-Step Problem Solving Methodology 1. State the problem clearly. 2. Describe the input and output. 3. Work a.
1 Compound Assignment C++ has a large set of operators for applying an operation to an object and then storing the result back into the object Examples.
 2003 Prentice Hall, Inc. All rights reserved. Outline 1 fig02_07.cpp (1 of 2) 1 // Fig. 2.7: fig02_07.cpp 2 // Class average program with counter-controlled.
1 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long.
VARIABLES AND DATA TYPES Chapter2:part1 1. Objectives: By the end of this section you should: Understand what the variables are and why they are used.
C++ / G4MICE Course Session 2 Basic C++ types. Control and Looping Functions in C Function/method signatures and scope.
If Statements Programming. COMP104 Lecture 7 / Slide 2 Review: Rules for Division l C++ treats integers different than doubles. 100 is an int. l 100.0,
Lecture 5: Expressions and Interactivity Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
April 11, 2005 More about Functions. 1.Is the following a function call or a function header? calcTotal(); 2.Is the following a function call or a function.
1 Programming in C++ Dale/Weems/Headington Chapter 9 Additional Control Structures (Switch, Do..While, For statements)
Fundamental Programming Fundamental Programming More Expressions and Data Types.
Chapter 3 – Variables and Arithmetic Operations. First Program – volume of a box /************************************************************/ /* Program.
Chapter 7 Conditional Statements. 7.1 Conditional Expressions Conditions - compare the values of variables, constants and literals using one or more relational.
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.
Chapter 2 Creating a C++ Program. Elements of a C++ Program Four basic ways of structuring a program Four basic ways of structuring a program 1.Sequencing.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 15, 2004 Lecture Number: 11.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout
Chapter 3 Selection Statements
Chapter Topics The Basics of a C++ Program Data Types
Chapter 3 Control Statements
-Neelima Singh PGT(CS) KV Sec-3 Rohini
Basic Elements of C++.
Data Types, Identifiers, and Expressions
Variables A piece of memory set aside to store data
Introduction to C++ October 2, 2017.
CS 1430: Programming in C++.
Basic Elements of C++ Chapter 2.
Introduction to C++ Programming
Summary Two basic concepts: variables and assignments Basic types:
CS150 Introduction to Computer Science 1
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
CS150 Introduction to Computer Science 1
Fundamental Programming
Fundamental Programming
Life is Full of Alternatives
Life is Full of Alternatives
Presentation transcript:

COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo

1. Introduction to Computer Systems Hardware  Input  Process  Memory  Output Software  System Operating system Translation System  Application

2. Data Types, Variables and Constants Data Types  void, int, char, float, double, bool Variables Name / Identifiers Name  Start with a-z/A-Z  Contain only a-z/A-Z/0-9/$/_  Case sensitive Variables Declaration  ;  = ;

2. Data Types, Variables and Constants Constants  Never changed in the program  const = ; Type casting  int( )  double( )  bool( ) Common Mistakes  char a = A; Should be char a = ‘A’;false for 0, true for others1 for true, 0 for falseascii value of characterstruncate the decimal place

3. Structure of C++ Programs #include  using namespace std;  Match with, for time()for srand()/rand()for cin/coutfor setw()/setprecision()

3. Structure of C++ Programs cin >>  User input cout <<  Screen output Common mistakes  cin >>a<<endl; Should be cin>>a; cout<<endl;

3. Structure of C++ Programs Rules for division  double / double = double  double / int = double  int / double = double  int / int = int Random number  srand(time(0));  int ran = rand() % x; truncate the decimal placeRandom no: 0 to x-1

3. Structure of C++ Programs Order of Precedence  Parentheses ( … )  Post-increment/decrement i++ i--  Unary operators !  Pre-increment/decrement ++i --i  Multiplicative operators * / %  Additive operators + -  Relational ordering = >  Relational equality == !=  Logical and &&  Logical or ||  Assignment = += -= *= /= %=

4. Selections condition action true false if statement condition action true false action if-else statement

4. Selections condition action true false action if-else if statement condition action false true selector action Value1 action switch statement action Value2 Value3

4. Selections Truth Table E1E2E1 && E2 true false truefalse E1E2E1 || E2 true falsetrue falsetrue false E!E truefalse true

5. Loops for loop  for(i= ; i ; i ) {…} while loop  while ( ) {…} do-while loop  do {…}  while ( )

6. Functions Return statement  void = no return statement or return nothing  other = return value to the caller through the function name Pass by value  parameters inside and outside functions is not related Pass by reference  parameters inside and outside functions is related  Value changed inside functions will affect outside  Value changed outside functions will affect inside

6. Functions (03 past paper Q6) #include <iostream.h> int Test(int&, int, int&); int a = 2; int b = 3; int main() { int b = 4; int c = 5; int d ; d = Test(a, b, c); b = b + 3; cout << a << ' ' << b << ' ' << c << ' ' << d << endl; return 0; } int Test(int& z, int x, int& y) { z = 3; x = b; a = y + a; cout << z << ' '<< --x << ' ' << y++ <<' ' << a << endl; return (y - x); }