Information Technology for Engineers FE11A/ENGR1001 Recap
FE11A/ENGR1001 Mid Term When: Thursday 3rd November, 2005. When: 1:30pm – 4:00pm. Where: MD2 & MD3 – Civil Building. Group 1: MD2. Group2: MD3. Group 1 –Mechanical, Chemical. Group 2 – Civil, Surveying, Geosciences.
Proper IDE Usage
Break
Control Structures Sequence; Selection; Repetition; Invocation.
Sequence
Comments // Single line Comments Block Comments /* Program Name Description Assumptions */
Preprocessor Commands Header Files #include <iostream.h> Types of Header Files <iostream.h> <stdlib.h> <math.h> <iomanip.h> <string.h>
Main Functions int main() void main()
int main int main() { Statements; return 0; }
void main void main() { Statements; return; // not always necessary }
Pseudocode BEGIN / START statements END / STOP
Data Types Unsigned / Signed Interger types short int int long int char Real / Floating Point types float double long double
Variable Naming Scheme See Page138 in Manual. (Very, very, very important)
Variable Declaration Data-type variable-name //comment int score;//holds student score double rate;//holds interest rate char opselect;//holds control character
Pseudocode DECLARE AS INTEGER score DECLARE AS DOUBLE rate DECLARE AS CHAR opselect
Variable Initilization Data-type variable-name = value//comment int score = 0;//holds student score double rate = 3.5;//holds interest rate char opselect = ‘x’;//holds control character Const int votingAge = 18;//legal voting age
Pseudocode DECLARE AS INTEGER score, SET AS 0 DECLARE AS DOUBLE rate, SET AS 0.0 DECLARE AS CHAR opselect, SET AS ‘x’
Output PRINT “Hello World!!” Display “Hello World!!” cout<<“Hello World!!”; cout<<“Hello World!!”<<endl; Hello World!!
PRINT “I am ” age “ years old.” cout<<“I am ”<<age<<“ years old.”<<endl; I am 5 years old.
Input READ num1 READ num1, num2 cin>>num1; cin>>num1>>num2;
Escape Characters See page 129.
Arithmetic Addition(+); Subtraction(-); Multiplication(*); Division(/); Modulus(%).
receiving-variable = variable operator variable CALCULATE x = y + z x = y + z;
Incrementing INCREMENT count count++; count=count+1; count+=1;
Decrementing DECREMENT count count = count -1; count--; count -= 1;
Break
Selection
Structures If-else switch One way selection Liner nested Non linear nested switch
If-else if (condition) { statements; } else
Pseudocode IF condition THEN statements ELSE ENDIF
One Way Selection if (condition) { statements; }
Pseudocode IF condition THEN statements ENDIF
Linear Nested if (condition) { statements; } else if else
Pseudocode IF condition THEN statements ELSE IF condition THEN ELSE ENDIF
None Linear Nested if (condition) { statements; }
Pseudocode IF condition THEN statements ENDIF
Switch switch (condition) { case val1: statements; case val2: default: }
Pseudocode SWITCH expression ENDSWITCH condition 1 : sequence 1 default: sequence ENDSWITCH
Break
Repetition
Structures while do…while for
While while (condition) { statements; }
Psudeocode WHILE condition statements ENDWHILE