C++ and Programming Fundamentals
C++ and Programming Fundamentals
C++ and Programming Fundamentals
Fundamentals
Input CU Output
PM
SM
Combination of 8 bits is – 1
1024 byte - 1 KB
1024 KB - 1MB
1024 MB - 1GB
1024 GB - 1TB
Dr. garima Sinha 7
Operating System
• Computer System is quite sophisticated and very often a
user may unaware of its complete potential so an interface
is needed between computer hardware and user and this
interface is known as “Operating System”
• Functions of Operating System
Process Management
User Management
Time Management
Memory Management
I/O Management
Types of Operating System
Single User OS
Multi User OS
CUI
GUI
Desktop
Distributed
Dr. garima Sinha 8
Types of software
• System Software
• OS, Compilers, Interpreters, Firmware's etc.
• Application Software
– Packaged Software
• DBMS Oracle, FoxPro, MS-Access, SQL
• Office Automation MS-Office
• Financial Accounting Tally
• Web Browser Internet Explorer, Fireball, Mozilla
• Web Servers PWS, JWS, Apache, IIS
• Multimedia based software's
– Custom software
Symbols Meaning
Data Input/Output
Start/End
Decision
Connector
Directional Arrows
Representation of Fractions:
Decimal fractions are interpreted as follows:
0.235 = 2*10-1 + 3*10-2 + 5*10-3
@ $ \b \n \t
Examples:
x y12 sum_1 _temerature
names area tax_rate TABLE
Invalid Examples:
4th “x” order-no error flag
*An identifier can be up to 31 character long.
Data Types
Character Constants
‘A’ ‘x’ ‘3’ ‘$’ ‘‘
String Constants:
“Amit” “2225378”
Declaration of variable:
A declaration associates a group of variable with a
specific data type.
All variable must be declared before they can appear in
executable statements.
Syntax;
Data type <variables names separated by comma>;
int a,b,c;
float d,e,f;
char star = ‘*’;
Mathematical +-*/%
Relational > < >= <= !=
Assignment =
Equality ==
Logical &&(AND) ||(OR) !(NOT)
Text +
Expressions:
It is combination of operator and operand, it may be of
following types:
1. Mathematical
2. Relational
3. Logical
4. Bit wise operator. Etc.
(cin cout)
char line[80];
gets(line)
puts(line)
Third /, *, %
Fourth -, +
1. if()
syntax
if (condition/conditions with the help of logical
operators)
{
Statement/Statements;
}
Syntax
if (condition/conditions)
{
statement/statements;
}
else{
if (condition/conditions)
{
statement/statements;
}
else
{
statement/statements;
}
}
Dr. garima Sinha 45
WAP in C++ to compute greatest among three numbers.
#include<iostream.h>
#include<conio.h>
void main()
{
Clrscr();
int a,b,c;
Cout<<“Enter three numbers”;
Cin>>a>>b>>c;
if(a>b)
{
if(a>c)
cout<<a;
else
cout<<c;
}
else
{
if(b>c)
Ternary operator(?:)
Max=(a>b && a>c ? a :((b>a && b>c) ? b : c)));
swith..case:
The swith..case is variation in the idea of nested if…else
against a single variable.
A switch statement is used when there is a choice as to
which code to execute, depending on the value of a
constant expression.
Different cases are presented, and are checked one by
one to see if one case matches the value of the constant
Expression. If case matches, its block of code is
executed .
Input n
Case 1 default
Case 2Case n
Stmnt n default
Stmnt 1 Stmnt 2
stop
False
Condition Exit
TRUE
Body of loop
Increment/decrement
initialization;
while (condition)
{
body of loop;
increment/decrement;
}
Wap in c++ to print 1 to 10 nos.
#include<iostream.h>
void main()
{
int i=1;
Wap to print 10 to 1.
Wap to print 1 to n
Wap to print n to 1
Syntax:
for (initialization; condition; Increment/Decrement)
{
Body of loop;
}
Initialization; initialization;
while (condition) for (;condition;)
{ {
Body of loop; Body of loop;
Increment/Decrement; Increment/Decrement;
} }
Dr. garima Sinha 66
(3) do while loop
The do while loop is similar, but the test occurs after the
loop body is executed. This ensures that the loop body
will execute at once.
Syntax :
Initialization;
do
{
Body of loop;
}while (condition);
Condn 1
Initialization2
Condn 2
for (initialization1;condn1;increment/decrement1)
{
for (initialization2;condn 2;increment/decrement2)
{
Body of inner loop (loop 2);
}
Body of outer loop (loop 1);
}
Initialization 1;
while(condition1)
{
initialization 2
while (condition 2)
{
body of loop 2;
increment/decrement 2;
}
Body of loop 1;
Increment/decrement 2;
}
A
AB
ABC
ABCD
ABCDE
54321
4321
321
21
1
*
**
***
****
*****
1
121
12321
1234321
*****
****
***
**
*
for example:
for (int i=0;i<=10;++i)
{
if (i==5)
break;
else
Takes control here
cout<<i;
}
cout<<“Hello”
}
Dr. garima Sinha 79
Continue Statement:
The continue statement is used to repeat the same
operations again even if it checks the error. The general
syntax of the continue statement is:
continue;
for example:
for (int i=0;i<=10;++i)
{ Takes Control here
if (i==5)
continue;
else
cout<<i;
}
cout<<“Hello”;
}
Arrays Declaration:
Data type arrays_name[index];
For example:
int a[5];
Memory representation:
a[0] a[1] a[2] a[3] a[4]