Professional Documents
Culture Documents
The Basic Structure of The C/C++ Language: I. Objectives
The Basic Structure of The C/C++ Language: I. Objectives
II. Theory
a. Types of Data
Signed Unsigned
Type
Short Long Short Long
Size in bit 32
Range +/- 3.4e +/-
Float
38 (~7
digits)
Size in bit 64
Range +/- 1.7e +/-
Double
308 (~15
digits)
Size in bit 16 32 16 32
Range -32,768 s/d -2,147,483,648 0 s/d 65,535 0 s/d
Int
32,767 s/d 4,294,967,295
2,147,483,647
Size in bit 8 8
Char Range -128 s/d 0 s/d 255
127
b. Constant
1. Consists of a combination of letters and numbers with the first character must be a
letter. C language is case-sensitive language, that is mean uppercase or capital
letter, and lowercase is something different. So, nim, NIM, and Nim are different.
2. Must not contain space
3. Must not contain special symbols except an underline (underscore). The special
symbols that not allowed are: $, ?, %, #, !, &, *, (, ), -, +, =, etc 4. Free of length,
but only 32 first character that will be used
5. The example for the correct variable naming :
: NIM,a, x, Student_name, f3089, f4, Value, Ronaldo, etc.
6. The example for the incorrect variable naming :
: %Student_point, 80student, student name, urgent!, etc.
Scope of Variable
All the variables that we intend to use in a program must have been declared with its
type specified in an earlier point in the code. A variable can be either of global or
local scope.
#include <iostream>
using namespace std;
Global
Int reg_id; variable
char Name[20];
int main()
{
Local
sHort reg_id;
variable
float Something;
cout<<”Enter your registration id:”;
Instruction
cin>>reg_id;
return 0;
}
d. Declaration
f. Standar Output
By default, output of C++ program is the screen, show in console window.
To access standard output, we can use cout and follow by operator “<<” (Stream
insertion).
E.g. : std::cout<<”this is display on the screen” <<std::endl;
std::cout<<”and this is on the second line”;
or
cout<<”this is display on the screen”<<endl; cout<<”and this
is on the second line”; if already use the “using namespace
std;” after header.
g. Standar Input
Standard input device is usually the keyboard. We can use cin stream and follow by
operator “>>”(Stream extraction). First, we must declare the variable before use
command input. So when the value is inserted, it can stored in variable. e.g. : int
age;
std::cin>>age; or
int age;
cin>>age;
if already use the “using namespace std;” after header.
III. Procedure of Experiment
1. Explain about the types of data that you know and the difference of each of them!
2. Explain and show the difference of constant and variable in C++ program!
3. Explain about the meaning of modulus in C++ program!
4. “a=++b” and“a=b++”, what is the difference between both of the declaration!
5. Explain the difference of char and string in a program!
6. Explain the library and header of the C++ program that you know! (min 3)
7. Explain how to use logical expression of AND, OR, NOT, make each syntax and table out
of it in the C++ Program!
8. Explain what “bool” is in the procedure 3? Why don’t just use another data type?
9. Explain what are Alogrithm and flowchart? What the difference? And explain the use of
every flowchart’s symbol that you know.
10. Make a simple program that can declare types of data (min. 3 types of data) ! (don’t take
from modul!)