Oops1 4
Oops1 4
Oops1 4
//FUNCTION OVERLOADING
#include<iostream>
using namespace std;
void number(int a){
cout<<a<<endl;
}
number(b);
return 0;
}
Output : -
//Inline function and Default Argument
cout<<"*"<<" ";
}
for(int i=0;i<b;i++){
cout<<"&"<<" ";
}
for(int i =0 ;i<c;i++){
cout<<"#"<<" ";
}
}
int main(){
bool ans = cmp(5,4);
cout<<ans<<endl;
print(4);
cout<<endl;
print(4,5);
cout<<endl;
print(4,5,6);
return 0;
}
Output :
//CALL BY REFERENCE AND RETURN BY REFERENCE
#include<iostream>
using namespace std;
void inc(int &a){
a ++;
cout<<"The increased value of a "<<a<<endl;
int main(){
int x =9;
inc(x);
cout<<endl;
Output :
Experiment No. 2
//Encapsulation
//Structure limitation and how class overcome it
#include<iostream>
using namespace std ;
class Rectangle{
public:
int length;
int breadth;
int main(){
Rectangle rec(5,4);
cout<<"Area of rectangle "<<rec.getArea();
return 0;
}
Output: -
//Data hiding
#include<iostream>
using namespace std;
class Rectangle{
private:
int lenght;
int breadth;
public:
void setLen(int len){
lenght = len;
}
int getLen(){
return lenght;
}
int getbre(){
return breadth;
}
int getArea(){
return lenght * breadth;
}
};
int main(){
Rectangle rect;
rect.setLen(8);
rect.setBre(6);
cout<<"Area of rectangle
"<<rect.getArea()<<endl; return 0;
}
OUTPUT:
/ Array of object
#include <iostream>
using namespace std;
class Employee
{
int id;
int salary;
public:
void setid()
{
salary = 876;
cout << "Enter the id " <<
endl; cin >> id;
}
void getid()
{
cout << "Employee id is " << id << endl;
}
};
int main()
{
Employee fb[4];
Output:
Experiment no.3
#include <iostream>
using namespace std;
class ComplexNo
{
int real;
int imag;
public:
void getdata();
void setdata();
void add(ComplexNo c1, ComplexNo c2)
{
real = c1.real + c2.real;
imag = c1.imag + c2.imag;
}
};
Output:
//Friend function
#include<iostream>
using namespace std;
class Equitri{
float a;
float perimeter;
public:
void setA(float len){
a =len;
perimeter = a*3;
}
friend void
printPerimeter(Equitri); };
int main(){
Equitri et;
et.setA(3);
printPerimeter(et);
return 0;
}
Output:
Experiment No.4
class Student
{
private:
string name;
int rollno;
public:
static int objectCount;
void setter()
{
cout << "Enter the name of student " << endl;
cin >> name;
cout << "Enter the rollno of student " << endl;
cin >> rollno;
objectCount++;
}
void getter()
{
cout << "Name " << name <<
endl; cout << "Rollno " << rollno
<< endl;
}
};
int Student::objectCount;
int main()
{
Student s1;
s1.setter();
s1.getter();
Student s2;
s2.setter();
s2.getter();
cout << "Objects " << Student::objectCount << endl;
return 0;
}
Output:
// Static data functions
#include <iostream>
using namespace std;
class Note
{
static int num;
public:
static void func()
{
cout << "The value of num is " << num << endl;
}
};
int Note::num = 90;
int main()
{
Note n;
n.func();
return 0;
}
Output :