BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO :17 BATCH: A
BCA 2ND YR
SCOPE RESOLUTION OPERATOR Program :
#include<iostream>
using namespace std;
int x; //Global x
int main()
{
int x=10; //Local x
cout<<"Value of global x is "<< ::x;
cout<<"\n Value of local x is "<<x;
return 0;
Output:
BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO 17 BATCH A
BCA 2ND YR
If else statement Program :
#include <iostream>
using namespace std;
int main () {
int num1,num2;
cout << "enter any two numbers";
cin>>num1>>num2;
if (num1>num2)
{
cout <<num1<<" is the greater number";
}
else
{
cout <<num2<< " is the greater number";
}
return 0;
}
Output :
BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO 17 BATCH A
BCA 2ND YR
Call by value Program :
#include<iostream>
#include<conio.h>
using namespace std;
void change (int data){
data=5;
}
int main(){
int data =3;
change(data);
cout<<"Value of the data is: "<<data<<endl;
return 0;
}
Output :
BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO 17 BATCH A
BCA 2ND YR
Array Program :
#include<iostream>
using namespace std;
int main(){
int numbers[5],i;
cout<<"Enter 5 numbers:"<<endl; //store input
from user to array
for(int i=0;i<5;i++){
cin>>numbers[i];
}
cout<<"The numbers are:"; //print array elements
for(int n=0;n<5;n++){
cout<<numbers[n]<<" ";
}
return 0;
}
Output :
BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO 17 BATCH A
BCA 2ND YR
do –while loop Program :
#include<iostream>
using namespace std;
int main(){
int i=1; //Local variable declaration
cout<<"Even numbers b/w 1 to 2o are\n";
do{
if(i%2==0)
cout<<i<<endl;
i++;
}while(i<=20);
return 0;
}
Output :
BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO 17 BATCH A
BCA 2ND YR
Call by reference Program :
#include<iostream>
void swap(int &a, int &b)
{
int num;
num = a;
a = b;
b = num;
std::cout<<"Value of a after swap="<<a;
std::cout<<"\nValue of b after swap="<<b;
}
int main()
{
int a = 50, b = 100;
swap(a, b); // passing value to function
std::cout<<"\nValue of a before swap="<<a;
std::cout<<"\nValue of b before swap="<<b;
return 0;
}
Output :
BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO 17 BATCH A
BCA 2ND YR
For-loop Program :
#include<iostream>
#include<conio.h>
using namespace std;
int a,i=1;
int main(){
cout <<"Table of 7 \n";
for( int a=7; a<=70 ; a=a+7){
for(i=1 ; i<=10 ; i++ ){
}
cout <<"7*"<<i<<" = "<<a<<endl;
}
return 0;
}
Output :
BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO 17 BATCH A
BCA 2ND YR
Function Overloading Program :
#include<iostream>
#include<conio.h>
using namespace std;
class A{
public:
void show(int n){
cout<<" Square of "<<n<<"= "<<n*n<<endl;
}
void show(int n,int m){
cout<<" Addition of "<<n<<"+"<<m<<"= "<<n+m<<endl;
}
};
int main(){
A ob;
ob.show(5);
ob.show(5,3);
getch();
return 0;
}
Output :
BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO 17 BATCH A
BCA 2ND YR
Binary Operator overloading Program :
using namespace std;
class Height{
public:
int feet, inch;
Height(){
feet = 0;
inch = 0;
}
Height(int f, int i){
feet = f;
inch = i;
}
// Overloading (+) operator to perform addition of
// two distance object using binary operator
Height operator+(Height h2){
Height h3; // Create an object to return
// Perform addition of feet and inches
h3.feet = feet + h2.feet;
h3.inch = inch + h2.inch;
return h3; // Return the resulting object
}
};
int main() {
Height h1(3, 7);
Height h2(6, 1);
Height h3;
//Use overloaded operator
h3 = h1 + h2;
cout << "Sum of Feet & Inches: " << h3.feet << "'" << h3.inch << endl;
return 0;
}
Output :
BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO 17 BATCH A
BCA 2ND YR
Unary Operator overloading Program :
#include <iostream>
using namespace std;
class Count {
private:
int value;
public:
// Constructor to initialize count to 5
Count() : value(5) {};
// Overload ++ when used as prefix
void operator ++ () {
++value;
}
void display() {
cout << "Count: " << value << endl;
}
};
int main() {
Count count1;
// Call the "void operator ++ ()" function
++count1;
count1.display();
return 0;
}
Output :
BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO 17 BATCH A
BCA 2ND YR
Virtual class Program :
#include<iostream>
using namespace std;
class A {
public:
int a;
A() { // constructor
a = 10;
}
};
class B : public virtual A {
};
class C : public virtual A {
};
class D : public B, public C {
};
int main(){
D object; // object creation of class d
cout << "a = " << object.a << endl;
return 0;
}
Output :
BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO 17 BATCH A
BCA 2ND YR
Inheritance Program :
#include<iostream>
using namespace std;
class Parent{ //Base class
public:
int id_p;
};
class Child : public Parent{ //sub class inheriting from parent class
public:
int id_c;
};
int main(){
Child obj1;
obj1.id_c = 7;
obj1.id_p = 90;
cout << "Child id is: " << obj1.id_c << endl;
cout << "Parent id is: " << obj1.id_p << endl;
}
Output :
BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO 17 BATCH A
BCA 2ND YR
If else loop flowchart:
BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO 17 BATCH A
BCA 2ND YR
Loop flowcharts:
BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO 17 BATCH A
BCA 2ND YR
Data Types in c++:
#include<iostream>
#include<conio.h>
using namespace std;
int main(){
int id = 22; //integer datatype
float balance = 323.14; //float datatype
double volume = 134.12345; //double datatype
char ch='h'; //character datatype
bool b = false; //boolean datatype
cout<<id<<endl;
cout<<balance<<endl;
cout<<volume<<endl;
cout<<ch<<endl;
cout<<b<<endl;
getch();
return 0;
}
Output :
BODDAWAR GANGAPRASAD PRABHAKAR
ROLL NO 17 BATCH A
BCA 2ND YR
Friend function program:
#include <iostream>
using namespace std;
// forward declaration
class ClassB;
class ClassA {
public:
// constructor to initialize numA to 12
ClassA() : numA(12) {}
private:
int numA;
// friend function declaration
friend int add(ClassA, ClassB);
};
class ClassB {
public:
// constructor to initialize numB to 14
ClassB() : numB(12) {}
private:
int numB;
// friend function declaration
friend int add(ClassA, ClassB);
};
// access members of both classes
int add(ClassA objectA, ClassB objectB) {
return (objectA.numA + objectB.numB);
}
int main() {
ClassA objectA;
ClassB objectB;
cout << "Sum: " << add(objectA, objectB);
return 0;
}
Output :