BCA-II Sem-IV CPP Journal 2024-25
BCA-II Sem-IV CPP Journal 2024-25
in
Object Oriented Programming Using C++
Course Code: CCL 406
Lab Course-VII Based on CC401
BCA Part – II, Sem– IV
2024-25
1
1) Write a simple program (without Class) to use of operators in C++
#include <iostream>
#include<conio.h>
int main()
{
int a = 8, b = 3;
cout << "a + b = " << (a + b) << endl;
cout << "a - b = " << (a - b) << endl;
cout << "a * b = " << (a * b) << endl;
cout << "a / b = " << (a / b) << endl;
cout << "a % b = " << (a % b) << endl;
return 0;
}
/*Output
Output:- a + b = 11
a - b = 5
a * b = 24
a / b = 2
a % b = 2
*/
2
2) Write a if statement program :-
#include<iostream.h>
#include<conio.h>
Void main()
{
Clrscr();
int age=20;
if(age>=18)
{
Cout<<”are you eligible for voting ”<<endl;
}
getch();
}
/*output
are you eligible for voting
*/
3
3) Write a program to create a class and creating an object.
#include <iostream.h>
#include <string.h>
class MyClass
{
public:
int myNum;
string myString;
};
int main()
{
MyClass myObj;
myObj.myNum = 15;
myObj.myString = "Some text";
cout << myObj.myNum << "\n";
cout << myObj.myString;
return 0;
}
/*output
50
Some text*/
4
4) Illustrating different Access Specifies.
#include<iostream.h>
#include<conio.h>
class Circle
{
public:
double radius;
double compute_area()
{
return 3.14*radius*radius;
}
};
int main()
{
Circle obj;
obj.radius = 5.5;
cout << "Radius is: " << obj.radius << "\n";
cout << "Area is: " << obj.compute_area();
return 0;
}
/*output
Radius is: 5.5
Area is: 94.985
*/
5
5 )Write a Loop program to demonstrate static data member
#include <iostream.h>
#include <conio.h>
class A
{
public:
A()
{
cout << "A's Constructor Called " << endl;
}
};
class B
{
static A a;
public:
B()
{
cout << "B's Constructor Called " << endl;
}
};
int main()
{
B b;
return 0;
}
/*output
B's Constructor Called
*/
6
6 )Demonstrate arguments to the function.
#include <iostream.h>
#include <conio.h>
int main()
{
myFunction("Liam");
myFunction("Jenny");
myFunction("Anja");
return 0;
}
/*output
Liam Refsnes
Jenny Refsnes
Anja Refsnes*/
7
7 )Illustrating inline function.
#include <iostream.h>
#include <conio.h>
/*output
The cube of 3 is: 27
*/
8
8) Define Member function-outside the class using Scope Resolution
Operator
#include <iostream.h>
#include <conio.h>
class Operate
{
public:
void fun();
};
void Operate::fun()
{
cout << " It is the member function of the class. ";
}
int main ()
{
Operate op;
op.fun();
return 0;
}
/*output
It is the member function of the class.
*/
9
9) Illustrating friend class and friend function.
#include <iostream.h>
#include<conio.h>
class GFG
{
private:
int private_variable;
protected:
int protected_variable;
public:
GFG()
{
private_variable = 10;
protected_variable = 99;
}
class F
{
public:
void display(GFG& t)
{
cout << "The value of Private Variable = "
<< t.private_variable << endl;
cout << "The value of Protected Variable = "
<< t.protected_variable;
}
};
int main()
{
GFG g;
10
F fri;
fri.display(g);
return 0;
}
/*output
*/
11
10 )Create constructors – default, parameterized, copy.
#include <iostream.h>
#include<conio.h>
class student
{
int rno;
char name[50];
double fee;
public:
student()
{
cout << "Enter the RollNo:";
cin >> rno;
cout << "Enter the Name:";
cin >> name;
cout << "Enter the Fee:";
cin >> fee;
}
void display()
{
cout << endl << rno << "\t" << name << "\t" << fee;
}
};
int main()
{
student s;
s.display();
return 0;
}
/*output
12
.
11) Illustrating Inheritance – single
#include <iostream.h>
#include <conio.h>
class Account
{
public:
float salary = 60000;
};
class Programmer: public Account
{
public:
float bonus = 5000;
};
int main(void)
{
Programmer p1;
cout<<"Salary: "<<p1.salary<<endl;
cout<<"Bonus: "<<p1.bonus<<endl;
return 0;
}
/*Output
Salary: 60000
Bonus: 5000
*/
13
12) Write a program static polymorphism
#include <iostream.h >
#include <conio.h >
class Geeks
{
public:
void func(int x)
{
cout << "value of x is " << x << endl;
}
void func(double x)
{
cout << "value of x is " << x << endl;
}
void func(int x, int y)
{
cout << "value of x and y is " << x << ", " << y
<< endl;
}
};
int main()
{
Geeks obj1;
obj1.func(7);
obj1.func(9.132);
obj1.func(85, 64);
return 0;
}
/*Output
value of x is 7
value of x is 9.132
14
13) Demonstrate on virtual program.
#include <iostream.h>
#include <conio.h>
class base
{
public:
virtual void print() { cout << "print base class\n";
}
void show()
{
cout << "show derived class\n";
}
};
int main()
{ base* bptr;
derived d;
bptr = &d;
bptr->print();
bptr->show();
return 0;
}
/*Output
print derived class
show base class
15
14) Demonstrate on pure virtual function
#include <iostream.h>
#include <conio.h>
class Base
{
int x;
public:
virtual void fun() = 0;
int getX()
{
return x;
}
};
public:
void fun()
{
cout << "fun() called";
}
};
int main(void)
{
Derived d;
d.fun();
return 0;
}
/*Output
fun() called
*/
16