[ Home Page ] [ Back ] [ Content of Contributions ] [ Movement: Green Leaf World ]
Program Reference: Cpp_Programs/ Day_03/ Prog_01.cpp
#include<stdlib.h>
#include <iostream>
class A
{
private:
int a, b, c;
public:
A(void){std::cout<<"\nThis is Default(!) Constructor of class A Running....";}
A(int x){ std::cout<<"\nThis is Constructor1 of class A Running....\n"; a=x;}
A(int x, int y){std::cout<<"\nThis is Constructor2 of class A Running....\n"; a=x; b=y;}
A(int x, int y, int z){
std::cout<<"\nThis is Constructor3 of class A Running....\n"; a=x; b=y; c=z;}
A( A &ob){std::cout<<"\nCopy Constructor Running....\n"; a=ob.a; b=ob.b; c=ob.c;}
~A(void){std::cout<<"\nThis is Default Destructor of class A Running....\n";}
void Display(void) {std::cout<<"\nA = "<<a<<"\tB = "<<b<<"\tC = "<<c<<"\n\n";}
};
int main(void)
{
system("clear"); //TO CLEAR THE SCREEN [use clrscr(); in windows]
std::cout<<"\n\t\t\tDemonstration of Constructor-Destructor: Implicit Call\n";
A ob1;
std:: cout<<"\nEnd of the Program....\n\n\n";
}
#include <iostream>
class A
{
private:
int a, b, c;
public:
A(void){std::cout<<"\nThis is Default(!) Constructor of class A Running....";}
A(int x){ std::cout<<"\nThis is Constructor1 of class A Running....\n"; a=x;}
A(int x, int y){std::cout<<"\nThis is Constructor2 of class A Running....\n"; a=x; b=y;}
A(int x, int y, int z){
std::cout<<"\nThis is Constructor3 of class A Running....\n"; a=x; b=y; c=z;}
A( A &ob){std::cout<<"\nCopy Constructor Running....\n"; a=ob.a; b=ob.b; c=ob.c;}
~A(void){std::cout<<"\nThis is Default Destructor of class A Running....\n";}
void Display(void) {std::cout<<"\nA = "<<a<<"\tB = "<<b<<"\tC = "<<c<<"\n\n";}
};
int main(void)
{
system("clear"); //TO CLEAR THE SCREEN [use clrscr(); in windows]
std::cout<<"\n\t\t\tDemonstration of Constructor-Destructor: Implicit Call\n";
A ob1;
std:: cout<<"\nEnd of the Program....\n\n\n";
}
Output
$ g++ Prog_01.cpp
$ ./a.out
Demonstration of Constructor-Destructor: Implicit Call
This is Default(!) Constructor of class A Running....
End of the Program....
This is Default Destructor of class A Running....
$
$ ./a.out
Demonstration of Constructor-Destructor: Implicit Call
This is Default(!) Constructor of class A Running....
End of the Program....
This is Default Destructor of class A Running....
$
Program Reference: Cpp_Programs/ Day_03/ Prog_02.cpp
#include "A.class"
#include<stdlib.h>
#include <iostream>
int main(void)
{
system("clear"); //TO CLEAR THE SCREEN [use clrscr(); in windows]
std::cout<<"\n\t\t\tDemonstration of Constructor-Destructor: Implicit Call\n";
A ob1;
ob1.Display();
std:: cout<<"\n\nEnd of the Program....\n\n\n";
}
#include<stdlib.h>
#include <iostream>
int main(void)
{
system("clear"); //TO CLEAR THE SCREEN [use clrscr(); in windows]
std::cout<<"\n\t\t\tDemonstration of Constructor-Destructor: Implicit Call\n";
A ob1;
ob1.Display();
std:: cout<<"\n\nEnd of the Program....\n\n\n";
}
Output
$ g++ Prog_02.cpp
$ ./a.out
Demonstration of Constructor-Destructor: Implicit Call
This is Default(!) Constructor of class A Running....
A = -1217167360 B = 134514923 C = -1218494464
End of the Program....
This is Default Destructor of class A Running....
$
$ ./a.out
Demonstration of Constructor-Destructor: Implicit Call
This is Default(!) Constructor of class A Running....
A = -1217167360 B = 134514923 C = -1218494464
End of the Program....
This is Default Destructor of class A Running....
$
Program Reference: Cpp_Programs/ Day_03/ Prog_03.cpp
#include "A.class"
#include<stdlib.h>
#include <iostream>
int main(void)
{
system("clear"); //TO CLEAR THE SCREEN [use clrscr(); in windows]
std::cout<<"\n\t\t\tDemonstration of Constructor-Destructor: Explicit Call\n";
A ob1;
ob1.Display();
A ob2(10);
ob1.Display();
ob2.Display();
}
#include<stdlib.h>
#include <iostream>
int main(void)
{
system("clear"); //TO CLEAR THE SCREEN [use clrscr(); in windows]
std::cout<<"\n\t\t\tDemonstration of Constructor-Destructor: Explicit Call\n";
A ob1;
ob1.Display();
A ob2(10);
ob1.Display();
ob2.Display();
}
Output
$ g++ Prog_03.cpp
$ ./a.out
Demonstration of Constructor-Destructor: Explicit Call
This is Default(!) Constructor of class A Running....
A = -1076302324 B = -1219926867 C = -1218378812
This is Constructor1 of class A Running....
A = -1076302324 B = -1219926867 C = -1218378812
A = 10 B = 134515019 C = -1218379776
This is Default Destructor of class A Running....
This is Default Destructor of class A Running....
$
$ ./a.out
Demonstration of Constructor-Destructor: Explicit Call
This is Default(!) Constructor of class A Running....
A = -1076302324 B = -1219926867 C = -1218378812
This is Constructor1 of class A Running....
A = -1076302324 B = -1219926867 C = -1218378812
A = 10 B = 134515019 C = -1218379776
This is Default Destructor of class A Running....
This is Default Destructor of class A Running....
$
Program Reference: Cpp_Programs/ Day_03/ Prog_04.cpp
#include "A.class"
#include<stdlib.h>
#include <iostream>
int main(void)
{
system("clear"); //TO CLEAR THE SCREEN [use clrscr(); in windows]
std::cout<<"\n\t\t\tDemonstration of Constructor-Destructor: Implicit Call\n";
A ob1(10);
ob1.Display();
ob1 = A(123);
ob1.Display();
ob1 = A(11, 22);
ob1.Display();
ob1 = A(1, 2, 3);
ob1.Display();
}
#include<stdlib.h>
#include <iostream>
int main(void)
{
system("clear"); //TO CLEAR THE SCREEN [use clrscr(); in windows]
std::cout<<"\n\t\t\tDemonstration of Constructor-Destructor: Implicit Call\n";
A ob1(10);
ob1.Display();
ob1 = A(123);
ob1.Display();
ob1 = A(11, 22);
ob1.Display();
ob1 = A(1, 2, 3);
ob1.Display();
}
Output
$ g++ Prog_04.cpp
$ ./a.out
Demonstration of Constructor-Destructor: Implicit Call
This is Constructor1 of class A Running....
A = 10 B = -1217444392 C = 1
This is Constructor1 of class A Running....
This is Default Destructor of class A Running....
A = 123 B = 1 C = -1080157100
This is Constructor2 of class A Running....
This is Default Destructor of class A Running....
A = 11 B = 22 C = -1218526268
This is Constructor3 of class A Running....
This is Default Destructor of class A Running....
A = 1 B = 2 C = 3
This is Default Destructor of class A Running....
$
$ ./a.out
Demonstration of Constructor-Destructor: Implicit Call
This is Constructor1 of class A Running....
A = 10 B = -1217444392 C = 1
This is Constructor1 of class A Running....
This is Default Destructor of class A Running....
A = 123 B = 1 C = -1080157100
This is Constructor2 of class A Running....
This is Default Destructor of class A Running....
A = 11 B = 22 C = -1218526268
This is Constructor3 of class A Running....
This is Default Destructor of class A Running....
A = 1 B = 2 C = 3
This is Default Destructor of class A Running....
$
Program Reference: Cpp_Programs/ Day_03/ Prog_05.cpp
#include "A.class"
#include<stdlib.h>
#include <iostream>
int main(void)
{
system("clear"); //TO CLEAR THE SCREEN [use clrscr(); in windows]
std::cout<<"\n\t\t\tDemonstration of Copy Constructor\n";
A ob1(10, 2, 3);
ob1.Display();
A ob2(ob1);
ob1.Display();
ob2.Display();
}
#include<stdlib.h>
#include <iostream>
int main(void)
{
system("clear"); //TO CLEAR THE SCREEN [use clrscr(); in windows]
std::cout<<"\n\t\t\tDemonstration of Copy Constructor\n";
A ob1(10, 2, 3);
ob1.Display();
A ob2(ob1);
ob1.Display();
ob2.Display();
}
Output
$ g++ Prog_05.cpp
$ ./a.out
Demonstration of Copy Constructor
This is Constructor3 of class A Running....
A = 10 B = 2 C = 3
Copy Constructor Running....
A = 10 B = 2 C = 3
A = 10 B = 2 C = 3
This is Default Destructor of class A Running....
This is Default Destructor of class A Running....
$
$ ./a.out
Demonstration of Copy Constructor
This is Constructor3 of class A Running....
A = 10 B = 2 C = 3
Copy Constructor Running....
A = 10 B = 2 C = 3
A = 10 B = 2 C = 3
This is Default Destructor of class A Running....
This is Default Destructor of class A Running....
$
Program Reference: Cpp_Programs/ Day_03/ Prog_06.cpp
#include "A.class"
#include<stdlib.h>
#include <iostream>
int main(void)
{
int a,b,c;
system("clear"); //TO CLEAR THE SCREEN [use clrscr(); in windows]
std::cout<<"\n\t\t\tDemonstration of Copy Constructor\n";
std::cout<<"Please Enter Three Values";
std::cin>>a>>b>>c;
A ob1(a,b,c);
ob1.Display();
A ob2(ob1);
ob1.Display();
ob2.Display();
}
#include<stdlib.h>
#include <iostream>
int main(void)
{
int a,b,c;
system("clear"); //TO CLEAR THE SCREEN [use clrscr(); in windows]
std::cout<<"\n\t\t\tDemonstration of Copy Constructor\n";
std::cout<<"Please Enter Three Values";
std::cin>>a>>b>>c;
A ob1(a,b,c);
ob1.Display();
A ob2(ob1);
ob1.Display();
ob2.Display();
}
Output
$ g++ Prog_06.cpp
$ ./a.out
Demonstration of Copy Constructor
Please Enter Three Values1
2
3
This is Constructor3 of class A Running....
A = 1 B = 2 C = 3
Copy Constructor Running....
A = 1 B = 2 C = 3
A = 1 B = 2 C = 3
This is Default Destructor of class A Running....
This is Default Destructor of class A Running....
$
class A
{
private:
int a, b, c;
public:
A(void){std::cout<<"\nThis is Default(!) Constructor of class A Running....";}
A(int x){ std::cout<<"\nThis is Constructor1 of class A Running....\n"; a=x;}
A(int x, int y){std::cout<<"\nThis is Constructor2 of class A Running....\n"; a=x; b=y;}
A(int x, int y, int z){
std::cout<<"\nThis is Constructor3 of class A Running....\n"; a=x; b=y; c=z;}
A( A &ob){std::cout<<"\nCopy Constructor Running....\n"; a=ob.a; b=ob.b; c=ob.c;}
~A(void){std::cout<<"\nThis is Default Destructor of class A Running....\n";}
void Display(void) {std::cout<<"\nA = "<<a<<"\tB = "<<b<<"\tC = "<<c<<"\n\n";}
};
$ ./a.out
Demonstration of Copy Constructor
Please Enter Three Values1
2
3
This is Constructor3 of class A Running....
A = 1 B = 2 C = 3
Copy Constructor Running....
A = 1 B = 2 C = 3
A = 1 B = 2 C = 3
This is Default Destructor of class A Running....
This is Default Destructor of class A Running....
$
Content of A.Class
#include <iostream>
class A
{
private:
int a, b, c;
public:
A(void){std::cout<<"\nThis is Default(!) Constructor of class A Running....";}
A(int x){ std::cout<<"\nThis is Constructor1 of class A Running....\n"; a=x;}
A(int x, int y){std::cout<<"\nThis is Constructor2 of class A Running....\n"; a=x; b=y;}
A(int x, int y, int z){
std::cout<<"\nThis is Constructor3 of class A Running....\n"; a=x; b=y; c=z;}
A( A &ob){std::cout<<"\nCopy Constructor Running....\n"; a=ob.a; b=ob.b; c=ob.c;}
~A(void){std::cout<<"\nThis is Default Destructor of class A Running....\n";}
void Display(void) {std::cout<<"\nA = "<<a<<"\tB = "<<b<<"\tC = "<<c<<"\n\n";}
};
No comments:
Post a Comment