Sei sulla pagina 1di 63

Object Oriented Programming with C++ LAB

PRACTICAL FILE

SUBMITTED IN THE PARTIAL FULFILLMENT OF THE


DEGREE OF

BACHELOR OF BUSINESS ADMINISTRATION(CAM)

(2022-2025)

SUBMITTED BY:
UJJVALADITYA PANDEY
ENROLLMENT NO.:
00821001922
UNDER THE GUIDANCE OF

Dr. Mahesh Sharma

(Vice Principal, BBA 1st Shift)

IDEAL INSTITUTE OF MANAGEMENT & TECHNOLOGY

(AFFILIATED TO GURU GOBIND SINGH INDRAPRASTHA UNIVERSITY,


DELHI
ACKNOWLEDGEMENT

I am preparing this practical file of Object Oriented Programming


with C++ Lab for the program of Bachelor of Business Administration
(CAM) for Ideal Institute of Management & Technology, Affiliated to
Guru Gobind Singh Indraprastha University.

It has been a great challenge but a plenty of learning and opportunities


to gain a huge amount of knowledge on the way of preparing this file.
I could not have completed my work without the constant guidance of
Dr. Mahesh Sharma, my faculty, who helped me along the way and
was always prepared to give me feedback and guidelines whenever I
needed it.

UJJVALADITYA PANDEY

Enroll. no.: 00821001922


TABLE OF CONTENT

S.NO. TITLE PG.


NO.
1 Introduction to C++
2 About Borland C++
3 Basic Program Using C++
4 Basic Addition Program Using C++
5 Basic Multiplication Program
6 Decimal Division Using C++
7 Multiplication Table Using C++
8 Increment Operator Program
9 Decrement Operator Program
10 Factorial Program Using C++
11 Positive Number Checker Program
12 Grade Checker Program
13 Array Program Using C++
14 Odd & Even Using C++
15 Switch Arithmetic Program
16 Constructor
17 Destructor
18 Inheritance

19 FOR Operator

20 Call by Reference

21 Employee ID program Using C++

22 Vowels Using IF ELSE IF

23 Vowels Using IF

24 Nested While Program Using C++

25 Star Pattern Nested

26 Thank You
Introduction To C++

C++ is a powerful and widely-used programming


language created by Bjarne Stroustrup, a Danish
computer scientist, in the late 1970s and early
1980s. Stroustrup wanted to enhance the C
language to support the principles of OOP, such as
encapsulation, inheritance, and polymorphism. He
aimed to design a language that would enable
efficient and flexible programming while
leveraging the existing C ecosystem.
C++ has found extensive use in various domains
due to its flexibility and efficiency. It is widely
used for system software development, game
development, embedded systems, scientific and
numerical computing, graphics programming,
finance, and high-performance applications.
Popular software like operating systems, browsers,
game engines, database systems, and resource-
intensive applications are often developed using
C++.
About Borland C++

The text editor that we are using in our C++ Lab is


Borland C++ it is a text editor and integrated
development environment (IDE) that was popular
during the late 1980s and 1990s. It was developed
by Borland International and provided a powerful
and user-friendly environment for writing,
compiling, and debugging C and C++ programs.

Borland C++ played a significant role in


popularizing C++ as a programming language and
encouraging the adoption of object-oriented
programming practices. It provided developers
with an accessible and productive environment for
harnessing the capabilities of C++.
Basic Program In C++

#include<iostream.h>

#include<conio.h>

void main()
{

cout<<"\n Hi, Ujjval this side ! ";

getch();

Output:
Basic Addition Program in C++

#include<iostream.h>
#include<conio.h>

void main()
{

int a,b,c;

cout<<"\n Enter a Value for A: ";


cin>>a;

cout<<"\n Enter a Value for B : ";


cin>>b;

c = a+b;

cout<<"\n Value of A: "<<a;


cout<<"\n Value for B: "<<b;

cout<<"\n Addition of A & B is : "<<c;

getch();

Output:
Incrementation Operator in C++

#include<iostream.h>
#include<conio.h>

void main()
{

for(int i = 0; i<=9; i++)

cout<<"\n TOKYO REVENGERSSS"<<i;

getch();

}
Output:
Decrementation Operator in C++

#include<iostream.h>
#include<conio.h>

void main()
{
int i = 10;

for (; i >= 0; i--)


{
cout << "Countdown: " << i << endl;
}

getch();
}
Output:
Basic Multiplication Program in C++

#include<iostream.h>
#include<conio.h>

void main()
{
int num1,num2,result;
cout<<" Enter a Number : ";
cin>>num1;
cout<<" Enter another Number : ";
cin>>num2;

result = num1 * num2;

cout << "Multiplication Result: " << result<<endl;

getch();
}
Output:
Decimal Division in C++

#include<iostream.h>
#include<conio.h>

void main()
{
float dividend,divisor,quotient;
cout<<"Enter the Divident: ";
cin>>dividend;
cout<<"Enter the Divisor: ";
cin>>divisor;

quotient = dividend / divisor;

cout << "Division Quotient: " << quotient <<


endl;

getch();
}
Output
Multiplication Table in C++

#include<iostream.h>
#include<conio.h>

void main()
{
int n,i;

cout<<"\n Enter a variable/value : ";


cin>>n;
cout<<"The Multiplication Table for "<<n<<" is as
follows: "<<endl;

for(i=1;i<=10;i++)
{
cout<<n<<"*"<<i<<"="<<n*i<<endl;
}
getch();
}
Output:
Factorial Program in C++

#include <iostream.h>
#include<conio.h>

void main()
{
int x, num, factorial = 1;

cout <<"\n Type a positive number: ";


cin >> num;

for (x = 1; x <= num; x++)


{
factorial *= x; // factorial = factorial * x;
}
cout << "Factorial of " << num << " = " <<
factorial;
getch();}
Output:
Positive Integer Checker In C++

#include<iostream.h>
#include<conio.h>

void main()
{

int number;

cout << "Enter an Integer: ";


cin >> number;

if (number > 0)
{
cout << "The number is a positive integer." <<
endl;
}
else
{
cout << "The number is not a positive integer." <<
endl;
}
getch();
}

Output Positive :

Output Negative :
Grade Checker Using IF and Else Operator
in C++

#include<iostream.h>
#include<conio.h>

void main()
{
int num;

cout<<"Enter a number to check grade:";


cin>>num;

if (num <0 || num >100)


{
cout<<"wrong number";
}
else if(num >= 0 && num < 50)
{
cout<<"Fail !!!";
}
else if (num >= 50 && num < 60)
{
cout<<"D Grade !";
}
else if (num >= 60 && num < 70)
{
cout<<"C Grade !";
}
else if (num >= 70 && num < 80)
{
cout<<"B Grade !";
}
else if (num >= 80 && num < 90)
{
cout<<"A Grade !";
}
else if (num >= 90 && num <= 100)
{
cout<<"A+ Grade !!! \n EXCELLENT";
}
getch();
}

Output :
Array Program in C++

#include<iostream.h>
#include<conio.h>

void main()
{
int x[5];

cout<<"\n Enter a Value for X[0] : ";


cin>>x[0];

cout<<"\n Enter a Value for X[1] : ";


cin>>x[1];

cout<<"\n Enter a Value for X[2] : ";


cin>>x[2];

cout<<"\n Enter a Value for X[3] : ";


cin>>x[3];

cout<<"\n Enter a Value for X[4] : ";


cin>>x[4];

cout<<endl;
cout<<x[0]<<" "<<x[1]<<" "<<x[2]<<"
"<<x[3]<<" "<<x[4]<<endl;

getch();

Output :
C++ program to find if an integer is even or
odd or neither (0) using nested if statement

#include<iostream.h>
#include<conio.h>

void main()
{
int num;

cout << "Enter an integer: ";


cin >> num;

// outer if condition
if (num != 0)
{

// inner if condition
if ((num % 2) == 0)
{
cout << "The number is even." << endl;
}

// inner else condition

else
{
cout << "The number is odd." << endl;
}
}

// outer else condition


else
{
cout << "The number is 0 and it is neither
even nor odd." << endl;
}
getch();
}
Output 1:

Output 2:

Output 3:
Nested While Program in C++

#include<iostream.h>
#include<conio.h>
void main()
{
int i=1;
while(i<=3)
{
int j = 1;
while (j <= 3)
{
cout<<i<<" "<<j<<"\n";
j++;
}
i++;
}
getch();
}
Output :
Switch Arithmetic Program in C++

#include<iostream.h>
#include<conio.h>

void main()
{

char oper;
float num1, num2;

cout <<"\n Enter an operator (+, -, *, /): ";


cin >> oper;

cout <<"\n Enter a value for num1: ";


cin>>num1;

cout <<"\n Enter a value for num2: ";


cin>>num2;
switch (oper)
{
case '+':
cout<<endl<<num1<< " + " <<num2<< " =
"<<num1 + num2<<endl;
break;
case '-':
cout<<endl<<num1<< " - "<<num2<< " =
"<<num1 - num2<<endl;
break;
case '*':
cout<<endl<<num1<< " * "<< num2 << "
= "<< num1 * num2<<endl;
break;
case '/':
cout <<num1 << " / "<< num2 << " = "<<
num1 / num2<<endl;
break;
default:
cout<< "Error! The operator is not correct";
break;
}

getch();
}

Outputs :
Destructor Program in C++

#include<iostream.h>
#include<conio.h>

class Student
{

private:

int rno;
char name[8];

public:

Student() //Default Constructor


{
}
Student(int r) //Parameterized Constructor
{
rno = r;
}

void get()
{
cout<<"\n Enter a value for Roll No. : ";
cin>>rno;

cout<<"\n Enter a value for Name : ";


cin>>name;
}
void show()
{
cout<<"\n Roll No. : "<<rno;
cout<<"\n Name : "<<name;
}
~Student() //Destructor...
{
cout<<"\n Destructor called successfully...";
}
};

void main()
{
clrscr();

Student s1;
s1.show();

Student s2(1001);
s2.show();

Student s3;
s3.get();
s3.show();

getch();
}
Output :
Constructor Program in C++

#include<iostream.h>
#include<conio.h>
#include<string.h>

class CAM2
{
private:
int id;
char name[20];

public:
CAM2()
{
id = 0;
strcpy(name, "");
}
CAM2(int i, char n[20])
{
id = i;
strcpy(name, n);
}

void Kartik()
{
cout << "\n Enter ID: ";
cin >> id;
cout << "\n Enter Name: ";
cin >> name;
}

void Ujjval()
{
cout << "\n Enter ID: ";
cin >> id;
cout << "\n Enter Name: ";
cin >> name;
}
~CAM2()
{
cout << "\n Destructor";
}
};

void main()
{
CAM2 h;
h.Ujjval();

CAM2 hh(1001,"Vidit");
hh.Ujjval();

h.Kartik();
h.Ujjval();

getch();
}
Output :
Inheritance Program in C++

#include<iostream.h>
#include<conio.h>

class Animal
{
public:
void eat()
{
cout<<"Eating..."<<endl;
}
};
class dog:public Animal
{
public:
void bark()
{
cout<<"barking...";
}
};
void main()
{
dog d1;
d1.eat();
d1.bark();

getch();
}

Output :
Call By Reference in C++

#include<iostream.h>
#include<conio.h>

//Call by Reference

void swap(int &x, int &y)


{
int temp;

temp = x; /* save the value of x */


x = y; /* put y into x */
y = temp; /* put x into y */

void main ()
{
clrscr();

// local variable declaration:


int a = 100;
int b = 200;

cout << "Before swap, value of a :" << a <<


endl;
cout << "Before swap, value of b :" << b <<
endl;

// calling a function to swap the values.


swap(a, b);

cout << "After swap, value of a :" << a << endl;


cout << "After swap, value of b :" << b << endl;

getch();
}
Output:
Employee Id Program in C++

#include<iostream.h>
#include<conio.h>

class Emp
{

private: //Access Specifier

int empid;
char name[10];
char org[15];
double sal;

public: //Access Specifier

void get()
{
cout<<"\n Enter Emp ID: ";
cin>>empid;

cout<<"\n Enter Name: ";


cin>>name;

cout<<"\n Enter Organization: ";


cin>>org;

cout<<"\n Enter Salary: ";


cin>>sal;
}

void show()
{
cout<<"\n Employee ID: "<<empid;
cout<<"\n Name of the Employee: "<<name;
cout<<"\n Organization, working with: "<<org;
cout<<"\n Salary of the Employee: "<<sal;
}

};

void main()
{
clrscr();

Emp e;

e.get();

e.show();

getch();

}
Output:
FOR Operator in C++

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

for(int i = 0; i<=9; i++)

cout<<"\n Hi, it's Number : "<<i;

}
getch();
}
Output:
Vowels using IF ELSE IF in C++

#include<iostream.h>
#include<conio.h>
void main()
{
char alpha;
cout<<"Enter an alphabet:=";
cin>>alpha;
if(alpha=='a')
cout<<"It is vowel";
else if(alpha=='e')
cout<<"It is vowel";
else if(alpha=='i')
cout<<"It is vowel";
else if(alpha=='o')
cout<<"It is vowel";
else if(alpha=='u')
cout<<"It is vowel";
else
cout<<"It is consonant";
getch();
}
OUTPUT:
Vowels using IF in C++

#include<iostream.h>
#include<conio.h>
void main()
{
char alpha;
cout<<"Enter an alphabet:=";
cin>>alpha;
if(alpha=='a'||alpha=='e'||alpha=='i'||alpha=='o'|
|alpha=='u')
cout<<"It is vowel";
else
cout<<"It is consonant";
getch();
}
Output:
Star Pattern Using Nested in C++

#include<iostream.h>
#include<conio.h>

void main()
{

clrscr();

int n;

cout<<"\n Enter a value: ";


cin>>n;
for (int i = 0; i < n; i++)
{

// Inner loop to handle number of


columns
// values changing acc. to outer loop

for (int j = 0; j <= i; j++)


{

// Printing stars
cout << "* ";

// Ending line after each row


cout << endl;
}

getch();
}
Output:

Potrebbero piacerti anche