0% found this document useful (0 votes)
8 views

Code

Uploaded by

harishjain086
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Code

Uploaded by

harishjain086
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 15

1.

INPUT:

#includeciostream> using namespace std; class cons

Private:

Int a,b;

PROGRAM-23 (Copy constructor)

Public:

Cons(int x, int y)

A=x;bay;

Cout<<”CONSTRUCTOR OF 2 PARAMETER\n”<<a<<” and “<<b<<endl;

Cons (int x)

Ax;

Cout<<”CONSTRUCTOR OF 1 PARAMETER\n”<<<<endl;

Cout<<”CONSTRUCTOR OF PARAMETER\n”;

Cons()

Cons(cons &c)

Cout<<”INSIDE COPY CONSTRUCTOR\n”;

Cout<<c.a<<” and “<<c.b;

};

Int main()

Cons obj1(21,51);

Cons obj2(51);

Cons obj3;

Cons obj4-obj1;
C:\Users\ASUS\OneDrive\Desktop\New

Vscode.cpptools-1.17.5-win32-x64\debugAdapters\bin\WindowsDebugLauncher.exe”

Return 0;

OUTPUT:

PS

MIEngine-In-b2tmp14c.szt’

MIEngine-Error-bpo5jeyc.kyr’

CONSTRUCTOR OF 2 PARAMETER

21 and 51

CONSTRUCTOR OF 1 PARAMETER

Folder>

& ‘c:\Users\ASUS\.vscode\extensions\ms

--stdout-Microsoft-MIEngine-Out-1dymb4uo.isk’

--stdin-Microsof –stderr-Microsof

--pid-Microsoft-MIEngine-Pid-qclegju2.1ms

dbgExe=C:\msys64\mingw64\bin\gdb.exe’ –interpreter-mi

51

CONSTRUCTOR OF 8 PARAMETER

INSIDE COPY CONSTRUCTOR

21 and 51

PS C:\Users\ASUS\OneDrive\Desktop\New folder>

2.

INPUT:
#include<iostream>

Using namespace std;

Class decons

Public: decons()

PROGRAM-24 (Destructor)

Cout<<”HELLO, I AM A CONSTRUCTOR.”<<endl;

-decons()

};

Cout<<”BYE, I AM A DESTRUCTOR.”;

Int main()

Decons obj;

Return 0;

OUTPUT:

PS C:\Users\ASUS\OneDrive\Desktop\New folder> & ‘c:\Users\ASUS\.vscode\extensions \ms-


vscode.cpptools-1.17.5-win32-x64\debugAdapters\bin\WindowsDebugLauncher.exe’ ‘—stdin-Microsoft-

MIEngine-In-3mfhxu5g.okp –[email protected]’--stderr-Microsoft-
MIEngine-Error-czpu1143.1d3’

--pid-Microsoft-MIEngine-Pid-xgxmoaiw.2mh’—

dbgExe=C:\msys64\mingw64\bin\gdb.exe –interpreter-mi

HELLO, I AM A CONSTRUCTOR.

BYE, I AM A DESTRUCTOR.

PS C:\Users\ASUS\OneDrive\Desktop\New folder>
3.

INPUT:

#include<iostream>

#include<string>

Using namespace std;

Class mypgm

PROGRAM-25

(Create an object Called “myobj” and access the attributes) (

Public:

Int mynum;

String mystring;

};

Int main()

Mypgm myobj;

Myobj.mynum-90;

Myobj.mystring=”HELLO ENGINEERS!!”; cout<<myobj.mynum<<endl; cout<<myobj.mystring<<endl;

Return 0;

OUTPUT:

PS C:\Users\ASUS\OneDrive\Desktop\New folder> &’c:\Users\ASUS\.vscode\extensions\ms-


vscode.cpptools-1.17.5-win32-x64\debugAdapters\bin\WindowsDebugLauncher.exe –stdin-Microsoft-
MIEngine-In-ps3b0syz.30f’ ‘—stdout-Microsoft-MIEngine-Out-d13zagev.c3j’ ‘—stderr=Microsoft-
[email protected] –pid-Microsoft-MIEngine-Pid-r131ig3n.mws’ dbgExe=C:\msys64\
mingw64\bin\gdb.exe –interpreter-mi’

90

HELLO ENGINEERS!!

PS C:\Users\ASUS\OneDrive\Desktop\New folder>
4.

PROGRAM-26

(Create multiple objects of one class)

INPUT:

#include<iostream>

Using namespace std;

Class institute

Public:

String name; string branch; int rank; institute(string x,string y,int z)

Name=x; branch-y; rank=2;

Void display()

Cout<<”NAME:”<<name<<”\nBRANCH:”<<branch<<”\nRANK: “<<rank<<endl;

};

Int main()

Institute obj1(“SWATANTRA”, “C.S”,1);

Institute obj2(“ANISH”,”MIN”,2);

Obj1.display(); obj2.display(); return 0;

OUTPUT:
PS C:\Users\ASUS\OneDrive\Desktop\New folder> &’c:\Users\ASUS\.vscode\extensions\ms-
vscode.cpptools-1.17.5-win32-x64\debugAdapters\bin\WindowsDebugLauncher.exe’ ‘—stdin-Microsoft-

MIEngine-In-Byqhf445.vyr’ ‘—stdout-Microsoft-MIEngine-Out-tzyezzm5.33t’—stderr=Microsoft-
MIEngine-Error-sklvnics.yhb –pid-Microsoft-MIEngine-Pid-ilpaltu2.riq’ ‘—dbgExe=C:\msys64\mingw64\
bin\gdb.exe –interpreter-mi’

NAME: SWATANTRA

BRANCH:C.S

RANK:1

NAME: ANISH

BRANCH:MIN

RANK: 2

PS C:\Users\ASUS\OneDrive\Desktop\New folder>

5.

INPUT:

#include<iostream> using namespace std;

Class pgm

Public:

Void display()

PROGRAM-27

(Define functions inside the class)

Cout<<”HELLO I AM DEFINED INSIDE THE CLASS”;

};

Int main()

{
}

Pgm obj;

Obj.display(); return 0;

OUTPUT:

PS C:\Users\ASUS\OneDrive\Desktop\New folder> &’c:\Users\ASUS\.vscode\extensions\ms-

Vscode.cpptools-1.17.5-win32-x64\debugAdapters\bin\WindowsDebugLauncher.exe’—stdin-Microsoft-
MIEngine-In-qhp3ubvj.kxb’ ‘—stdout-Microsoft-MIEngine-Out-stgjeqiz.2iq’ ‘—stderr=Microsoft-
MIEngine-Error-x15mkrrr.paj

--pid-Microsoft-MIEngine-Pid-q51sce3r.who

dbgExe=C:\msys64\mingw64\bin\gdb.exe’ –interpreter-mi’

HELLO I AM DEFINED INSIDE THE CLASS

PS C:\Users\ASUS\OneDrive\Desktop\New folder>

--

6.

INPUT:

#include<iostream>

Using namespace std;

Class pg

Public:

Void display();

};

Void pgn::display()

PROGRAM-28

(Defining function outside the class)

Cout<<”HELLO I AM DEFINED OUTSIDE THE CLASS”;


}

Int main()

Pgm obj; obj.display();

Return 0;

OUTPUT:

PS C:\Users\ASUS\OneDrive\Desktop\New folder> & ‘c:\Users\ASUS\.vscode\extensions\ms-


vscode.cpptools-1.17.5-win32-x64\debugAdapters\bin\WindowsDebugLauncher.exe –stdin-Microsoft-

--stderr=Microsoft-

MIEngine-In-m5uvnnxs.1et –stdout-Microsoft-MIEngine-Out-nm3vicdm.hiv MIEngine-Error-


tdobkkwx.4nc –pid-Microsoft-MIEngine-Pid-tqgzzect.rtc’ ‘—dbgExe-C:\msys64\mingw64\bin\gdb.exe’ –
interpreter-mi’ HELLO I AM DEFINED OUTSIDE THE CLASS

PS C:\Users\ASUS\OneDrive\Desktop\New folder>

7.

INPUT:

#include<iostream>

Using namespace std; class pgm

};

Public:

Int add(int x, int y);

Int pgm::add(int x, int y)

Cout<<x<<”+”<<y<<”=”;

Return(x+y);
Int main(){

Pgm obj;

Cout<<obj.add(20,35); return 0;

PROGRAM-29 (Defining parameterized function)

OUTPUT:

PS C:\Users\ASUS\OneDrive\Desktop\New folder> & ‘c:\Users\ASUS\.vscode\extensions\ms-


vscode.cpptools-1.17.5-win32-x64\debugAdapters\bin\WindowsDebugLauncher.exe –stdin-Microsoft-
MIEngine-In-3tdnrpke.wzu –[email protected]’ –stderr=Microsoft-
MIEngine-Error-dc44zebs.mfh’ –pid-Microsoft-MIEngine-Pid-1pbnajbo.rir’ ‘—dbgExe=C:\msys64\
mingw64\bin\gdb.exe –interpreter-mi’

28+35=55

PS C:\Users\ASUS\OneDrive\Desktop\New folder>

8.

INPUT:

#include<iostream>

Using namespace std; class base

Public:

PROGRAM-31 (Inheritance)

Void show()

Cout<<”\nHELLO, I am the base class.”;

Class sub public base

1
Public:

};

Void print()

Cout<<”HELLO,I am derived class and I am going to call member function of the base class”;

Int main()

Sub ob; ob.print(); ob.show(); return 0;

OUTPUT:

PS C:\Users\ASUS \OneDrive\Desktop\10pgms> cd “c:\Users\ASUS \OneDrive\Desktop\10pgms\”; if ($?)


{ g++ inherit.cpp -o inherit; if ($?) .\inherit }

HELLO, I am derived class and I am going to call member function of the base class.f HELLO,I am the base
class.

PROGRAM-32

(Function overriding)

INPUT:

#include<iostream>

Using namespace std;

Class base

Public:

Void show()

}
};

Cout<<”HELLO, I am member function of base class.”;

Class sub: public base

Public:

Void show()

Cout<<”HELLO, I am the overidden function of base class inside the sub class.”;

};

Int main()

Sub ob; ob.show();

OUTPUT:

PS C:\Users\ASUS\OneDrive\Desktop\10pgms> cd “c:\Users\ASUS \OneDrive\Desktop\10pgms\”; if ($?)


{ g++ funover.cpp -o funover }; if ($?) { .\funover }

HELLO, I am the overidden function of base class inside the sub class.

10.

(Function overriding)

INPUT:

#include<iostream>

Using namespace std; class base

Public:

Void show()

{
}

};

Cout<<”HELLO, I am member function of base class.”;

Class sub: public base

};

Public:

Void show()

Cout<<”HELLO, I am the overidden function of base class inside the sub class.”;

Int main()

Sub ob;

Ob.show();

11.

PROGRAM-23 (Copy constructor)

TNPUT:

#include<iostream> using namespace std;

Class cons

Private:

Int a,b;

Public:

Cons (int x, int y)

(
Awx;bay;

Cout<<”CONSTRUCTOR OF 2 PARAMETER\n”<cac<” and “<<b<<endl;

Cons(int x)

A=x;

Cout<<”CONSTRUCTOR OF 1 PARAMETER\n”<<a<<endl;

Cons()

Cout<<”CONSTRUCTOR OF PARAMETER\n”;

Cons(cons &c)

};

Cout<<”INSIDE COPY CONSTRUCTOR \n”;

Cout<<c.a<<” and “<<c.b;

Int main()

Cons obj1 (21,51);

Cons obj2(51);

Cons obj3;

Cons obj4-obj1;

Return 0;

OUTPUT:

PS

C:\Users\ASUS\OneDrive\Desktop\New

Folder>

&
Vscode.cpptools-1.17.5-win32-x64\debugAdapters\bin\WindowsDebugLauncher.exe” –stdin-Microsoft –
stdout Microsoft-MIEngine-Out-1dymb4uo.isk’

MIEngine-In-b2tmp14c.szt’

‘c:\Users\ASUS\.vscode\extensions\ms

--stderr=Microsoft

MIEngine-Error-bpo5jeyc.kyr’

--pid-Microsoft-MIEngine-Pid-qclegju2.1ms’

dbgExe=C:\msys64\mingw64\bin\gdb.exe’ –interpreter-mi

CONSTRUCTOR OF 2 PARAMETER

21 and 51

CONSTRUCTOR OF 1 PARAMETER

51

CONSTRUCTOR OF PARAMETER

INSIDE COPY CONSTRUCTOR

21 and 51

PS C:\Users\ASUS\OneDrive\Desktop\New folder>

12.

INPUT:

#include<iostream>

Using namespace std;

Class functoverload

Public:

PROGRAM-35

(Function overloading)

Void show(int x, int y)


}

Cout<<”The numbers are: “<<x<<”, “<<y<<”\n”;

Void show(int x)

Cout<<”The numbers is: “<<x<<”\n”;

Void show(int x, double y)

Cout<<”The numbers are: “<<x<<”, “<<y<<”\n”;

};

Int main()

Functoverload ob;

Ob.show(21,11);

Ob.show(101);

Ob.show(181,121.11);

Return 0;

OUTPUT:

PS C:\Users\ASUS\OneDrive\Desktop\10pgms> cd “c:\Users\ASUS \OneDrive\Desktop\10pgms\”; if ($?)


{ g++ funoverload.cpp -o funoverload); if ($?) .\funoverload }

The numbers are: 21, 11

The numbers is: 101

The numbers are: 101 › 121.11

You might also like