![Page 1: COMP 102 Programming Fundamentals I Presented by : Timture Choi COMP102 Lab 011](https://reader036.vdocument.in/reader036/viewer/2022062523/5a4d1af27f8b9ab05997eff6/html5/thumbnails/1.jpg)
COMP 102
Programming Fundamentals I
Presented by : Timture Choi
COMP102 Lab 01 1
![Page 2: COMP 102 Programming Fundamentals I Presented by : Timture Choi COMP102 Lab 011](https://reader036.vdocument.in/reader036/viewer/2022062523/5a4d1af27f8b9ab05997eff6/html5/thumbnails/2.jpg)
Introduction to C++ C++ Extension of C Supports OO programming Free-format languageGeneral form Comment Include necessary header files “main()” function
COMP102 Lab 01 2
![Page 3: COMP 102 Programming Fundamentals I Presented by : Timture Choi COMP102 Lab 011](https://reader036.vdocument.in/reader036/viewer/2022062523/5a4d1af27f8b9ab05997eff6/html5/thumbnails/3.jpg)
CommentsProvides explanatory notes
Purpose of the program/each function Usage of each variableAppear in green in VC++
1. Single line comments //
2. Multiple line comments /* … */
COMP102 Lab 01 3
![Page 4: COMP 102 Programming Fundamentals I Presented by : Timture Choi COMP102 Lab 011](https://reader036.vdocument.in/reader036/viewer/2022062523/5a4d1af27f8b9ab05997eff6/html5/thumbnails/4.jpg)
Compiler DirectivesAppear in blue in VC++Import the required library in programPre-defined #include <xxx> E.g. <iostream>, <math>User-defined #include “xxx.h”
COMP102 Lab 01 4
![Page 5: COMP 102 Programming Fundamentals I Presented by : Timture Choi COMP102 Lab 011](https://reader036.vdocument.in/reader036/viewer/2022062523/5a4d1af27f8b9ab05997eff6/html5/thumbnails/5.jpg)
“main()” FunctionStart of the programVariables/constant declaration Must be declared before used Identifier
Name for variables/constant/function Should not be a keyword Case sensitive Start with letter
Statements Deal with user input/output Specific calculation
COMP102 Lab 01 5
![Page 6: COMP 102 Programming Fundamentals I Presented by : Timture Choi COMP102 Lab 011](https://reader036.vdocument.in/reader036/viewer/2022062523/5a4d1af27f8b9ab05997eff6/html5/thumbnails/6.jpg)
Programming StyleFree-format language Increase writability
How easily a language can be used to write programs Decrease readability
Measures how easy it can be understoodNote: Write comments for both variables and
functions Use meaningful variable names Only one statement for each line
COMP102 Lab 01 6
![Page 7: COMP 102 Programming Fundamentals I Presented by : Timture Choi COMP102 Lab 011](https://reader036.vdocument.in/reader036/viewer/2022062523/5a4d1af27f8b9ab05997eff6/html5/thumbnails/7.jpg)
DeclarationsAllocation Reserves memory to store constants and
variablesDeallocation Releases storage of constants and variables
from memoryBinding Associates the constants/variables with
memory location
COMP102 Lab 01 7
![Page 8: COMP 102 Programming Fundamentals I Presented by : Timture Choi COMP102 Lab 011](https://reader036.vdocument.in/reader036/viewer/2022062523/5a4d1af27f8b9ab05997eff6/html5/thumbnails/8.jpg)
DeclarationsConstant Cannot be changed throughout the
program Syntax:
const <type> <identifier> = <expression>;
const: keyword E.g.
const double pi=3.14, gravity=9.8;
COMP102 Lab 01 8
![Page 9: COMP 102 Programming Fundamentals I Presented by : Timture Choi COMP102 Lab 011](https://reader036.vdocument.in/reader036/viewer/2022062523/5a4d1af27f8b9ab05997eff6/html5/thumbnails/9.jpg)
DeclarationsVariable Can be changed during program
execution Note: will not be initialized automatically
Better to initialize when declared Syntax:
<type> <identifier>; <type> <identifier>, <identifier>; <type> <identifier> = <expression>;
COMP102 Lab 01 9
![Page 10: COMP 102 Programming Fundamentals I Presented by : Timture Choi COMP102 Lab 011](https://reader036.vdocument.in/reader036/viewer/2022062523/5a4d1af27f8b9ab05997eff6/html5/thumbnails/10.jpg)
Data Typevoid
no value and operationint
Integer 32 bits (4 bytes)
Float Floating point 32 bits (4 bytes)
Double 64 bits (8 bytes)
char Character
bool Either true/false
COMP102 Lab 01 10
![Page 11: COMP 102 Programming Fundamentals I Presented by : Timture Choi COMP102 Lab 011](https://reader036.vdocument.in/reader036/viewer/2022062523/5a4d1af27f8b9ab05997eff6/html5/thumbnails/11.jpg)
Data TypeNote: Precision Data size
Depend on design/compiler of the languageBytes/BitsOverflow/UnderflowAffect program size
Data range Signed/Unsigned
Signed bit
COMP102 Lab 01 11
![Page 12: COMP 102 Programming Fundamentals I Presented by : Timture Choi COMP102 Lab 011](https://reader036.vdocument.in/reader036/viewer/2022062523/5a4d1af27f8b9ab05997eff6/html5/thumbnails/12.jpg)
SUMMARYBy the end of this lab, you should be able to: Understand the general form of a program
Comments Compiler directives “main()” function Keyword and identifier
Defined and Initialized Constants Variables
With appropriate data types
COMP102 Lab 01 12