Professional Documents
Culture Documents
Computer Programming
• Computer
– Programmable machine which working under a given set of
instruction
– Program
– Set of instructions that is used to control the computer in processin
data
• Programming Language
– Artificial language that can be used to define a sequence
instructions that can ultimately be processed and executed by t
computer
Generations
First generation (1GL)
• Machine language/ Machine code/ Native code
• Microprocessor can process directly without a previous
transformation
C++ Comments
Variables
Memory location in the computer memory which can store
data and is given a symbolic name for easy reference
Syntax
2)int myNum;
myNum = 15;
cout << myNum;
C++ Identifiers
NSJ ONLINE ACADEMY 9
STRUCTURE PROGRAMMING SHORT NOTE
C++ Constants
Escape Sequency
Algorithms
• iostream.h
Header Files
– Stands for input output stream
– Invoke the commonly used functions like cout,cin
• stdio.h
– Defines three variable types, several macros, and various functions for performing
input and output.
• conio.h
– Invoke the commonly used functions like clrscr ()
NSJ ONLINE ACADEMY 12
STRUCTURE PROGRAMMING SHORT NOTE
Type Conversion
double a;
int b = 5;
float c = 8.5;
a = b * c;
double x = 10.3;
int y;
y = int (x); // functional notation
y = (int) x;
Operators
Arithmatic Operators
Assignment Operators
Relational /Comparison
Operators
Logical Operators
Conditions
If Condition
If Condition Syntax
if(condition)
{
statement(s);
}
else
}
statement(s); NSJ ONLINE ACADEMY 17
✦ int time = 20;
STRUCTURE PROGRAMMING SHORT NOTE
if (time < 18) {
cout << "Good day.";
} else {
cout << "Good evening.";
}
// Outputs "Good evening."
Switch Syntax
switch (int or char variable)
case value:
statements;
break;
case value :
statements;
break;
case value :
statements;
break;
default;
statements;
char Grade='A';
switch (Grade)
{
case 'A':
cout<<"Excellent";
break;
case 'S' :
cout<<"Simple pass";
break;
case 'F' :
cout<<"fail";
break;
default:
cout<<"invalid input";
}
While
Syntax :
while(condition)
{
statement(s);
}
int i=0;
while(i<10)
{
i++;
cout<<i<<endl;
}
Do While
do
{
statements;
} while (condition);
int i=0;
do
{ i++;
cout<<i<<endl;
}while(i<10);
For Loop
Break
int i=0;
while (i<10)
{
if (i==5)
{
break;
}
cout <<i<<endl;
i++;
}
Continue
int i=0;
while (i<10)
{
if (i==5)
{
continue;
}
cout <<i<<endl;
i++;
NSJ ONLINE ACADEMY 25
STRUCTURE PROGRAMMING SHORT NOTE
C++ Arrays
int i=0;
int num[5];
num[0]=11;
int A[5] = {11,2,23,4,15};
num[1]=12;
int B[] = {6,7,8,9,15,12};
num[2]=13;
int c[5]={};
num[3]=14;
num[4]=15;
while(i<5)
{
cout<<num[i]<<endl;
i++; NSJ ONLINE ACADEMY 26
}
STRUCTURE PROGRAMMING SHORT NOTE
char names[]={'N','i','m','a','l'};
Two-Dimensional Array
int i=0;
int sales[3][5];
sales[0][0]=11;
sales[0][1]=12;
sales[0][2]=13;
sales[0][3]=14;
sales[0][4]=15;
sales[1][0]=21;
sales[1][1]=22;
sales[1][2]=23;
sales[1][3]=24;
sales[1][4]=25;
sales[2][0]=31;
sales[2][1]=32;
sales[2][2]=33;
sales[2][3]=34;
sales[2][4]=35;
NSJ ONLINE ACADEMY 27
STRUCTURE PROGRAMMING SHORT NOTE
int i=0,j=0;
int A[4][3] = {{22, 23, 10},{15, 25, 13},{20, 74, 67},{11, 18, 14}};
while(j<3)
{
cout<<A[0][j]<<" ";
j++;
}
Advantages
Same name for similar set of objects
Useful with working in sequence of the same kind of data.
Data accessing is faster
2D arrays are used to represent matrices.
Used to implement other data structures like linked lists, stacks,
queues, trees, graphs
Disadvantages
Sometimes it's not easy to operate with indexes
C environment doesn't have checking mechanism for array
sizes/fixed size
Pointers
Functions
01st System
// Create a function
void myFunction() {
cout << "I just got executed!";
}
int main() {
myFunction(); // call the function
return 0;
}
02nd System
int main() {
myFunction("Liam");
myFunction("Jenny");
myFunction("Anja");
return 0;
}
// Liam Refsnes
// Jenny Refsnes
// Anja Refsnes
03rd System
int myFunction() {
return 5 ;
}
int main() {
cout << myFunction();
return 0;
}
// Outputs 5
04th System
int main() {
cout << myFunction(5, 3);
return 0;
}
// Outputs 8 (5 + 3)
Structures
✦ struct structureName
✦ {
✦ //member
definitions
✦ }; NSJ ONLINE ACADEMY 34
STRUCTURE PROGRAMMING SHORT NOTE
struct Subjects
{
char S_code[20];
char S_name[50];
int Hours;
};
Flow Charts
Pseudo Code