c++ file grayscale
Embed Size (px)
TRANSCRIPT
-
8/9/2019 C++ File Grayscale
1/27
Submitted To: Submitted By:
Mr. Virender Kr. Yadav Sumit Kumar
07/IT/41
-
8/9/2019 C++ File Grayscale
2/27
INDEXS.No. Practical Date Sign.
01 TOIMPLEMENTTHECONCEPTOFCLASS Mar 02nd,09
02 TOIMPLEMENTTHECONCEPTOFCLASSUSINGMEMBERFUNCTION
DEFINEDOUTSIDECLASSANDPASSINGOBJECTSASFUNCTION
ARGUMENTS.
Mar 02nd,09
03 TOIMPLEMENTTHECONCEPTOFCLASSUSINGMEMBERFUNCTION
DEFINEDOUTSIDECLASS.
Mar 09th,09
04 TOIMPLEMENTTHECONCEPTOFCLASSUSINGMEMBERFUNCTION
DEFINEDOUSIDECLASSANDINITIALIZATIONOFDATAMEMBERS.
Mar 09th,09
05 TOIMPLEMENTTHEUSEOFFRIENDFUNCTIONUSINGMULTIPLECLASSES Mar 16th,09
06 TOIMPLEMENTTHEUSEOFCONSTRUCTOR. Mar 16th,09
07 TOIMPLEMENTTHEUSEOFDESTRUCTOR. Mar 23th,09
08 TOIMPLEMENTTHECONCEPTOFFUNCTIONOVERLOADING. Mar 23th,09
09 TOIMPLEMENTTHECONCEPTOFOPERATOROVERLOADING.(BINARY) Mar 30th,09
10 TOIMPLEMENTTHECONCEPTOFOPERATOROVERLOADING.(UNARY) Mar 30th,09
11 TOIMPLEMENTCONCEPTOFINHERITANCE. Apr 06th,09
12 TOIMPLEMENTCONCEPTOFVIRTUALBASECLASS Apr 06th,09
13 TOIMPLEMENTCONCEPTOFVIRTUALFUNCTION. Apr 13th,09
14 TOIMPLEMENTCONCEPTOFGENERICCLASSESUSINGTEMPLATES. Apr 13th,09
15 TOIMPLEMENTCONCEPTOF EXCEPTIONHANDLING. Apr 13th,09
Practical # 1
Objective: To implement the concept of class.
-
8/9/2019 C++ File Grayscale
3/27
// Header Files#include#includeclass raise{
int a,b; // Private by defaultpublic:
void input(int m,int n){
a=m;b=n;
}void power(int a,int b){
int c=1,i;for(i=0;i
-
8/9/2019 C++ File Grayscale
4/27
Practical # 2
Objective: To implement the concept of class using member
function defined outside class and passing objects as functionarguments.
// Header Files#include#includeclass point // Class Declaration{public:
int x,y;void getdata(int x,int y);
};
void point::getdata(int a,int b){
x=a;y=b;
}int main() // Main Function{
point p1,p2;int p,q;clrscr(); // Clears the screencoutp;coutq;p1.getdata(p,q);coutp;
coutq;p2.getdata(p,q);cout
-
8/9/2019 C++ File Grayscale
5/27
Practical # 3
Objective: To implement the concept of class using memberfunction defined outside class.
#include#include#includeclass calc{
int m,n;public:
void getdata(int a,int b){
m=a;n=b;
}void getchoice(char ch){
do{
int a,b;clrscr();cout
-
8/9/2019 C++ File Grayscale
6/27
cin>>a;coutb;cout
-
8/9/2019 C++ File Grayscale
7/27
char ch;int p,q;C.getchoice(ch);coutp>>q;C.getdata(p,q);
getch();return 0;}
Output:
-
8/9/2019 C++ File Grayscale
8/27
Practical # 4
Objective: To implement the concept of class using member
function defined ouside class and initialization of data members.
// Header Files#include#includeclass phone{public:
int code,exch;char no[10];
};int main(){
phone p1;clrscr();coutp1.code;coutp1.exch;cout
-
8/9/2019 C++ File Grayscale
9/27
cin>>p1.no;cout
-
8/9/2019 C++ File Grayscale
10/27
cin>>meter;coutcenti;
}friend void addvalue(dm,db);
};
class db{float inch,feet;
public:void set2(void){
coutfeet;coutinch;
}friend void addvalue(dm,db);
};void addvalue(dm m, db b){
cout
-
8/9/2019 C++ File Grayscale
11/27
-
8/9/2019 C++ File Grayscale
12/27
Practical # 6
Objective: To implement the use of constructor.
#include
#includeclass abc{public:
int a,b;abc(){
clrscr();coutb;cout
-
8/9/2019 C++ File Grayscale
13/27
Practical # 7
Objective: To implement the use of destructor.
#include#includeclass abc{public:
int a,b;void sum(){
cout
-
8/9/2019 C++ File Grayscale
14/27
Practical # 8
Objective: To implement the concept of function overloading.
#include#includeclass fo{
float rad,len,bth;public:
void area(float a){
float area;rad=a;area=3.14*a;cout
-
8/9/2019 C++ File Grayscale
15/27
Output:
Practical # 9
Objective: To implement the concept of operator overloading.
(binary)
#include#includeclass complex{
int x,y;public:
void getvalue(){
coutx;couty;
}void display(){
cout
-
8/9/2019 C++ File Grayscale
16/27
c1.getvalue();c2.getvalue();cout
-
8/9/2019 C++ File Grayscale
17/27
Practical # 10
Objective: To implement the concept of operator overloading.
(unary)#include#includeclass space{
int x,y,z;public:
void getdata(int a,int b,int c){
x=a;y=b;z=c;
}void display(void){
cout
-
8/9/2019 C++ File Grayscale
18/27
y=-y;z=-z;
}};int main(){
space S;int a,b,c;clrscr();couta>>b>>c;S.getdata(a,b,c);cout
-
8/9/2019 C++ File Grayscale
19/27
public:void sub(int p,int q){
int sub;sub=p-q;coutn;cout
-
8/9/2019 C++ File Grayscale
20/27
cout
-
8/9/2019 C++ File Grayscale
21/27
#includeclass base{public:
void display(){
cout
-
8/9/2019 C++ File Grayscale
22/27
Output:
-
8/9/2019 C++ File Grayscale
23/27
Practical # 13
Objective:To implement concept of virtual function.
#include#includeclass base{public:
void display(){cout
-
8/9/2019 C++ File Grayscale
24/27
getch();return 0;
}
Output:
-
8/9/2019 C++ File Grayscale
25/27
Practical # 14
Objective: To implement the concept of generic classes using
templates.
#include
#includetemplateclass test{
t1 a;t2 b;
public:test(t1 x,t2 y){
a=x;b=y;
}
void show(){
cout
-
8/9/2019 C++ File Grayscale
26/27
test test2(100,'W');test1.show();test2.show();getch();return 0;
}
Output:
Practical # 15
Objective: To implement the concept of Exception Handling.
#include#includevoid divide(int x,int y,int z){
cout
-
8/9/2019 C++ File Grayscale
27/27
{cout