C++ PROGRAMMING MODEL
Gerald L. Almodiel
CS331: Computer Organization, Architecture and
Assembly Language Programming
College of Computer Studies
AMA Computer University
Topics Outline
2
Names & Variables
Data Types
Types of Characters
Types of Integers
Floating-point Numbers
Sample Programs
CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/11/2014
Names & Variables
3
Variables
Location in the memory where value or
data can be stored
Must compose of letters, digits and
underscore
Must begin with either letter or
underscore
Case-sensitive
CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/11/2014
Names & Variables
4
Variable Declaration
We declare variables with its name
and data types before use
e.g.
int num1;
We can declare variables of same
type in one declaration
e.g.
int num1, num2, num3;
CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/11/2014
Names & Variables
5
Identifiers
Is a sequence of one or more letters,
digits and underscore characters
Spaces, punctuation marks and
symbols cannot be part of identifiers
Specific compilers may also have
additional specific reserved keywords
e.g.
true, switch, try ….etc.
CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/11/2014
Data Types
6
Data Types
It is the name of the type of the value that we
stored in variables
3 Common Data Types
int – integer numbers
int num = 5;
char – characters
char x = ‘x’;
double – floating-point numbers
double num1 = 20.221;
CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/11/2014
Data Types
7
4 Fundamental Data Types
Character Types
- They can represent a single character, such as 'A' or '$'.
- The most basic type is char, which is a one-byte character
Integer Types
- They can store a whole number value, such as 7 or 1024.
Floating-point Types
- They can represent real values, such as 3.14 or 0.01, with
different levels of precision
Boolean Types
- The Boolean type, known in C++ as bool, can only represent one
of two states, true or false.
CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/11/2014
Types of Characters
8
Character Types
Types Names || Typical Range
_______________|________________________
char || -127 to 127 or 0 to 255
char16_t || At least 16 bits
char32_t || At least 32 bits
wchar_t || wide character range
CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/11/2014
Types of Integers
9
Integer Types
Types Names || Typical Range
______________|____________________________
short int || -32768 to 32767 or 0 to 65,535
int || 0 to 4 ,294 ,967 ,295
long int || -2,147,483,647 to 2,147,483,647
long long int || At least 64 bits
CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/11/2014
Floating-point numbers
10
Floating-point Types
Types Names || Typical Range
______________|_________________________
float || +/- 3.4e +/- 38 (~7 digits)
double || +/- 1.7e +/- 308 (~15 digits)
long double || Precision not less than double
CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/11/2014
Data Types
11
Boolean Types
Types Names || Returns
_______________|______________________________
bool || 1 (True) or 0 (False)
CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/11/2014
Sample Program
12
#include <iostream>
using namespace std;
int main()
{
// variable declaration
int num1 = 1; // variable num1 with data type integer and value 1
char x = ‘x’; // variable x with data type char and value character x
double num2 = 25.5; // variable num2 with double data type and value 25.5
bool guess1 = true;
bool guess2 = false;
cout << “Num1 = ” << num1 << endl;
cout << “Character x = ” << x << endl;
cout << “num2 = ” << num2 << endl;
return 0;
}
CSCI6B : Computer Organization, Architecture and Assembly Language
1/11/2014
Programming
Computer Organization, Architecture and Assembly
Language programming
13
ANY QUESTIONS ?
CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/11/2014
14
~ FIN
CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/11/2014