Practical 1: Introduction of C++ Programming: Firstly, We Know About WHAT IS C++ PROGRAMMING LANGUAGE ?
Practical 1: Introduction of C++ Programming: Firstly, We Know About WHAT IS C++ PROGRAMMING LANGUAGE ?
Cout: In C++, cout is an object used for standard output, which is typically the
console or terminal.
Cin: In c++ , cin is an object used for standard input, which is typically the keyboard.
HEADER FILES ARE USED :
IOSTREAM: 1. Iostream header is used to read input from the user.
2. Iostream header is also in used to display the data.
PRACTICAL 2: ALGORITHM AND FLOWCHART
ALGORITHM: Algorithm is a set of well-defined instructions to solve a particular problem. It
takes a set of input(s) and produces the desired output.
IMPORTANT POINTS:
1. Each step in the algorithm should be clear.
2. Input and output is precise.
3. Normal English is used in it.
4. It is effective code to solve the problems.
EXAMPLE ARE :
Ques To solve the problem of addition of two numbers:
STEP1: START
STEP2: Input a,b
STEP3: SUM= a+b
STEP4: Output SUM
STEP5: End
Qualities of flowchart
Effective way to represent the code.
Diagrams make easier the beginneers to understand
the codes.
Diagrams are best way to make a simple program.
Normal English is apply inside the diagrams.
Here, the following table are given:
EXAMPLE:
START
Input a,b
SUM= a+b
SUM
END
PRACTICAL 3: BASIC PROGRAM
Write a program to get text message.
Source of code :
#include<iostream.h>
#include<conio.h>
void main()
{
char name;
cout<<"javastpoint";
cin>>name;
getch();
}
OUTPUT:
PRACTICAL 4: WRITE A PROGRAM OF SUM OF NUMBERS.
SOURCE OF CODE:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,e,f,sum;
}
OUTPUT:
PRACTICAL 5:
CONDITIONAL CONTROL STATEMENTS:
The conditional statements (also known as decision control structures) such as if, if
else, switch, etc. are used for decision-making purposes in C++ programs.
They are also known as Decision-Making Statements and are used to evaluate one or
more conditions and make the decision whether to execute a set of statements or
not.
There are 4 types of conditional statements or decision-making statements in C
language:
if Statement
if-else Statement
if-else-if Ladder
switch Statement
1. IF STATEMENT :
The if statement is a program control statement that is used to execute a part of code
based on some condition.
Advantages of if Statement :
Following are the main advantages of the if statement in C:
SOURCE OF CODE:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,e,f,sum;
cout<<"enter any 6 number";
cin>>a>>b>>c>>d>>e>>f;
sum=a+b+c+d+e+f;
cout<<"sum is"<<sum;
getch();
}
OUT PUT:
2. IF ELSE STATEMENT:
if statement alone tells us that if a condition is true it will execute a block of
statements and if the condition is false it won’t.
We can use the else statement with the if statement to execute a block of code
when the condition is false.
The if-else statement consists of two blocks, one for false expression and one for
true.
Write a program of if else statement ?
Source of code:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
{
cout<<"a is greatest";
}
else
{
cout<<"b is greatest";
}
getch();
}
OUTPUT:
Source of code :
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"enter value of a";
cin>>a;
cout<<"enter value of b";
cin>>b;
cout<<"enter the value of c";
cin>>c;
if(a>b>c)
{
cout<<"a is largest";
}
else if(b>a && b>c)
{
cout<<"b is largest";
}
else
{
cout<<"c is largest";
}
getch();
}
OUTPUT:
4. SWITCH STATEMENT:
The switch statement in C++ is a flow control statement that is used to execute the
different blocks of statements based on the value of the given expression. We can create
different cases for different values of the switch expression. We can specify any number
of cases in the switch statement but the case value can only be of type int or char.
SOURCE OF CODE :
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int day;
cout<<"enter number between 1-7=";
cin>>day;
switch(day)
{case1:
cout<<"today is monday";
break;
case2:
cout<<"today is tuesday";
break;
case3:
cout<<"today is wednesday";
break;
case4:
cout<<"today is thursday";
break;
case5:
cout<<"today is friday";
break;
case6:
cout<<"today is saturday";
break;
case7:
cout<<"today is sunday";
break;
default:
cout<<"invalid input";
getch();
}
OUTPUT:
PRACTICAL 6: LOOPS
LOOPS : Loops in programming are used to repeat a block of code until the specified
condition is met. A loop statement allows programmers to execute a statement or group of
statements multiple times without repetition of code.
TYPES OF LOOPS:
FOR LOOP
WHILE LOOP
DO WHILE LOOP
1. FOR LOOP: is a repetition control structure that allows programmers to write a loop
that will be executed a specific number of times. for loop enables programmers to
perform n number of steps together in a single line.
SOURCE OF CODE :
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i;
for(i=1;i<=15;i++)
{
cout<<i;
}
getch();
}
OUTPUT:
2. WHILE LOOP: In Entry controlled loops the test condition is checked before entering
the main body of the loop. While Loop is Entry-controlled loops.
SOURCE OF CODE :
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i;
while(i<=15)
{
cout<<i;
i=i++;
}
getch();
}
OUTPUT:
DO WHILE: In Exit controlled loops the test condition is evaluated at the end of the loop
body. The loop body will execute at least once, irrespective of whether the condition is true
or false. do-while Loop is Exit Controlled loop.
SOURCE OF CODE:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i=1;
do
{
cout<<i;
i=i++;
}
while(i<=5
);
getch();
}
OUTPUT:
PRACTICAL 7: ARRAY
ARRAY : An array is a collection of items of same data type stored at contiguous memory
locations.
TYPES OF ARRAY:
1. 1D( ONE DIMENSIONAL) – when the single subscript is used in the program. This is
called one dimensional.
2. Multi dimensional ( 2D,3D etc….) – when the two or more subscript are used in the
program. This is called are two dimensional.
SOURCE OF CODE:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int row_size,col_size;
cout<<"Enter the row size of the matrix";
cin>>row_size;
cout<<"Enter the col size of the matrix";
cin>>col_size;
int[10][10];
int i,j;
cout<<"Enter the elements of matrix";
for(i=0;i<row_size;i++)
{
for(j=0;j<col_size;i++)
{
cin>>matrix[i][j];
}
}
getch();
}
OUTPUT:
PRACTICAL 8: POINTER
DEFINATIONS: A pointer can be used to store the memory address of other
variables, functions, or even other pointers.
SYNTAX:
The syntax of pointers is similar to the variable declaration in C, but we use the ( * )
dereferencing operator in the pointer declaration.
DATATYPE *ptr
Where,
ptr is the name of the pointer.
datatype is the type of data it is pointing to.
SOURCE OF CODE :
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num=30;
int *p;
p=#
cout<<"address of num"<<&num<<endl;
cout<<"address of p"<<&p<<endl;
cout<<"value of p"<<*p<<endl;
getch();
}
OUTPUT:
PRACTICAL 9: STRUCTURE
STRUCTURE:
STRUCTURE are user defined data types which are used to store
group of items of non-similar data types.
A structure creates a data type that can be used to group items of
possibly different types into a single type.
The ‘struct’ keyword is used to create a structure.
SYNTAX:
struct structureName
{
member1;
member2;
member3;
.
.
.
memberN;
};
SOURCE OF CODE :
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i;
struct student
{
int roll;
char name[30];
float marks;
};
struct student s[5];
for(i=0;i<=5;i++)
{
cout<<"enter roll";
cin>>s[i].roll;
cout<<"enter name";
cin>>s[i].name;
cout<<"enter marks";
cin>>s[i].marks;
}
for(i=0;i<5;i++)
{
cout<<"roll"<<s[i].roll;
cout<<"name"<<s[i].name;
cout<<"marks"<<s[i].marks;
}getch
OUTPUT:
PRACTICAL 10: CLASSES
CLASSES: is the building block that leads to Object-Oriented programming.(OOP)
A C++ class is like a blueprint for an object.
An Object is an instance of a Class. When a class is defined, no memory is
allocated but when it is instantiated (i.e. an object is created) memory is
allocated.
SOURCE OF CODE:
#include<iostream.h>
#include<conio.h>
class student
{
public:
int rollno;
char name[20];
float marks;
};
void main()
{
student s1;
cout<<"Enter your rollno";
cin>>s1.rollno;
cout<<"Enter your name";
cin>>s1.name;
cout<<"Enter your marks";
cin>>s1.marks;
cout<<s1.rollno<<endl;
cout<<s1.name<<endl;
cout<<s1.marks;
getch();
}
OUTPUT: