Vous êtes sur la page 1sur 38

/*---------------------------------------------------------------------------------------------Name

: Pradip Rajendra Girase.


Roll no: 102130
Assignment no :6
Date :
Title
: WRITE A PROGRAM USNING CONSTANT ARGUMENT
----------------------------------------------------------------------------------------------*/
#include<conio.h>
#include<iostream.h>
float value(const float p,int n,float r)
{
int year=1;
float sum=p;

while(year<=n)
{
sum=sum*(1+r);
year=year+1;
}
return(sum);

void main()
{
float amount;

float value(const float p,int n,float r=0.15);


amount=value(6000.00,5);
cout<<"\n \n";
cout<<"Final Values is : "<<amount;
getch();

/* OUTPUT:
-------------------------------------------------Final Values is : 12068.142578
-------------------------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no :7
Date :
Title
: WRITE A PROGRAM USING FUNCTION OVERLOADING
FOR ADD() FUNCTION THAT ADD TWO NUMBERS
----------------------------------------------------------------------------------------------*/
#include<conio.h>
#include<iostream.h>
int add(int,int);
long add(long,long);
void main()
{
cout<< add(10,2)<<"\n";
cout<< add(3080,2720);
getch();
}
int add(int a,int b)
{
return(a+b);
}
long add(long x,long y)
{
return(x+y);
}

/* OUTPUT:
-------------------------------------------------12
5800
--------------------------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no :8
Date :
Title
: WRITE A MENU BASED PROGRAM TO ADD ITEM,
DISPLAY TOTAL VALUE OF ITEM,DELETE AN ITEM,
DISPLAY ALL ITEMSAND QUIT .THE MEMBER DATA
MUST BE-ITEM CODE,ITEMPRICE.USE ARRAY
WITHIN CALSS.
----------------------------------------------------------------------------------------------*/
#include<iostream.h>
#include<conio.h>
const m=50;
class item
{
private:
int itemcode[m];
float itemprise[m];
int count;
public:
void cnt()
{
count=0;
}
void getitem();
void displaysum();
void remove();
void displayitem();
};
void item::getitem()
{
cout<<"\t Enter the Item Code = ";
cin>>itemcode[count];
cout<<"\t Enter the Item Prise = ";
cin>>itemprise[count];
count++;
}
void item::displaysum()
{
float sum=0;
for(int i=0; i<count; i++)
sum=sum+itemprise[i];
cout<<"\t Total Prise of "<<count<<" Item = "<<sum<<"\n";
}
void item::remove()
{
int a;
cout<<"\t Enter the Item Code = ";
cin>>a;
for(int i=0; i<count; i++)
if(itemcode[i]==a)
{
itemprise[i]=0;
cout<<"\t Item Code "<<itemcode[i]<<" is deleted \n";
}

}
void item::displayitem()
{
cout<<"\t Code \t Prise \n";
for(int i=0; i<count; i++)
{
cout<<"\n \t "<<itemcode[i];
cout<<"\t "<<itemprise[i];
}
cout<<"\n";
}
int main()
{
item order;
clrscr();
order.cnt();
int x;
cout<<"\n \n \t -------------------------------";
do
{
cout<<"\n \t 1.Add an Item";
cout<<"\n \t 2.Display Total Value";
cout<<"\n \t 3.Delete an Item";
cout<<"\n \t 4.Display All Item";
cout<<"\n \t 5.Quit";
cout<<"\n \t Enter Your Choice = ";
cin>>x;
switch(x)
{
case 1:
order.getitem();
break;
case 2:
order.displaysum();
break;
case 3:
order.remove();
break;
case 4:
order.displayitem();
break;
case 5:
break;
default:
cout<<"\t Wrong Your Choice \n";
}
cout<<"\t -------------------------------";
}while(x!=5);
getch();
return 0;
}

/* OUTPUT:
-------------------------------------------------Enter the Item Prise = 345
------------------------------1.Add an Item
2.Display Total Value
3.Delete an Item
4.Display All Item
5.Quit
Enter Your Choice = 1
Enter the Item Code = 103
Enter the Item Prise = 550
------------------------------1.Add an Item
2.Display Total Value
3.Delete an Item
4.Display All Item
5.Quit
Enter Your Choice = 4
Code Prise
101 250
102 345
103 550
------------------------------1.Add an Item
2.Display Total Value
3.Delete an Item
4.Display All Item
5.Quit
Enter Your Choice = 3
Enter the Item Code = 103
Item Code 103 is deleted
------------------------------1.Add an Item
2.Display Total Value
3.Delete an Item
4.Display All Item
5.Quit
Enter Your Choice = 4
Code Prise
101 250
102 345
103 0
------------------------------1.Add an Item
2.Display Total Value
3.Delete an Item
4.Display All Item
5.Quit
Enter Your Choice = 6
Wrong Your Choice
------------------------------1.Add an Item
2.Display Total Value
3.Delete an Item
4.Display All Item
5.Quit
Enter Your Choice = 5
---------------------------------------- */

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no :9
Date :
Title
: WAP using static member data and static
member function.
----------------------------------------------------------------------------------------------*/
#include<iostream.h>
#include<conio.h>
class test
{
int code;
static int count;
public:
void setcode(void)
{
code=++count;
}
void showcode(void)
{
cout<<"Object number: "<< code <<"\n";
}
static void showcount(void) // Static Member Function
{
cout<<"Count: "<< count <<"\n";
}
};
int test :: count;
// Defination Of Static Data Member
int main()
{
clrscr();
test t1,t2;
t1.setcode();
t2.setcode();
test::showcount();
test t3;
t3.setcode();
test::showcount();
t1.showcode();
t2.showcode();
t3.showcode();
getch();
return 0;
}

/* OUTPUT:
-------------------------------------------Count: 2
Count: 3
Object number: 1
Object number: 2
Object number: 3
-------------------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no :10
Date :
Title
: Write a program to accept 5 students details and
display them (Using array of student class)
----------------------------------------------------------------------------------------------*/
#include<iostream.h>
#include<conio.h>
class student
{
int rno,marks;
char name[20];
public:
void getdata()
{
cout<<"Enter Rollno of student:";
cin>>rno;
cout<<"Enter Name of student:";
cin>>name;
cout<<"Enter Marks of student:";
cin>>marks;
}
void disp()
{
cout<<"Student Rollno is ="<<rno<<endl;
cout<<"Student Name is="<<name<<endl;
cout<<"Student Marks is="<<marks<<endl;
}
};
int main()
{
clrscr();
class student stud[5];
for(int i=0;i<5;i++)
{
stud[i].getdata();
stud[i].disp();
}
getch();
return 0;
}

/* OUTPUT:
------------------------------------------------------Enter Rollno of student:1
Enter Name of student:Sunita
Enter Marks of student:78
Student Rollno is=1

Student name is=Sunita


Student Marks is= 78
Enter Rollno of student:2
Enter Name of student:Gauri
Enter Marks of student:76
Student Rollno is=2
Student name is=Gauri
Student Marks is= 76
Enter Rollno of student:3
Enter Name of student:Vanita
Enter Marks of student:77
Student Rollno is=3
Student name is=Vanita
Student Marks is= 77
Enter Rollno of student:4
Enter Name of student:Prashant
Enter Marks of student:81
Student Rollno is=4
Student name is=Prashant
Student Marks is= 81
Enter Rollno of student:5
Enter Name of student:Aasha
Enter Marks of student:79
Student Rollno is=5
Student name is=Aasha
Student Marks is= 79
-------------------------------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no :11
Date :
Title
: WRITE A FUNCTION MAX THAT FINDS THE MAX OF
TWO NUMBERS & IS FRIEND OF TWO CLASSES
XYZ & ABC. THE MAX()SHOULD NOT BE A MEMBER
OF ANY OF THESE CLASSES
----------------------------------------------------------------------------------------------*/

#include<conio.h>
#include<iostream.h>
class ABC;
class XYZ
{
int x;
public:
void value(int i)
{
x=i;
}
friend void max(XYZ,ABC);
};
class ABC
{
int a;
public:
void value(int i)
{
a=i;
}
friend void max(XYZ,ABC);
};
void max(XYZ m,ABC n)
{
if(m.x>=n.a)
{
gotoxy(35,12);cout<<"Maximum Value is :"<<m.x;
}
else
{
cout<<n.a;
}
}
void main()
{
ABC abc;
abc.value(100);
XYZ xyz;
xyz.value(200);
max(xyz,abc);
getch();
}

/* OUTPUT:
-------------------------------------------Maximum Value is :200
------------------------------------------ */

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no :12
Date :
Title
: Write a comman friend function to exchange the
private values of two class
----------------------------------------------------------------------------------------------*/

#include<conio.h>
#include<iostream.h>
class xyz;
class abc
{
int value1;
public:
void indata(int a);
void display();
friend void exchange(abc &,xyz &);
};
class xyz
{
int value2;
public:
void indata(int a);
void display();
friend void exchange(abc &,xyz &);
};
void exchange(abc &x,xyz &y)
{
int tmp;
tmp=x.value1;
x.value1=y.value2;
y.value2=tmp;
}
void main()
{
abc c1;
xyz c2;
c1.indata(5004);
c2.indata(4005);
cout<<"Values before Exchange: \n";
c1.display();
c2.display();
exchange(c1,c2);
cout<<"Values After Swapping: \n";
c1.display();
c2.display();
getch();

/* OUTPUT:
-------------------------------------------Values before Exchange:
5004
4005
values After Swapping:
4005
5004
------------------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no :13
Date :
Title
: write a program of constructor overloading.
----------------------------------------------------------------------------------------------*/
#include<conio.h>
#include<iostream.h>
class complex
{
int real;
int img;
public:
complex();
complex(int,int);
void sum(complex,complex);
void show();
};
complex::complex(int a,int b)
{
real=a;
img=b;
}
complex::complex()
{
}
void complex::sum(complex c1,complex c2)
{
real=c1.real+c2.real;
img=c1.img+c2.img;
}
void complex::show()
{
cout<<"The Addition Of Two Complex No. Is : \n \n";
cout<<real<<"+ "<<img<<" i"<<"\n";
cout<<"\n OR";
cout<<"\n";
cout<<real<<"+ j "<<img;
}
void main()
{
complex c1(2,6);
complex c2(4,5);
complex c3;
c3.sum(c1,c2);
c3.show();
}

getch();

/* OUTUT:
--------------------------------------------------------------The Addition Of Two Complex No. Is :
6+ 11 i
OR
6+ j 11
-------------------------------------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no : 14
Date :
Title
: write a program for dynamicinitialization
of objects using constructor.
----------------------------------------------------------------------------------------------*/
#include<conio.h>
#include<iostream.h>
class fixdepo
{
int pamt;
int yrs;
float rate;
float rval;
public:
fixdepo();
fixdepo(int p,int y,float r=0.12);
fixdepo(int p,int y,int r);
void display();
};
fixdepo::fixdepo(int p,int y,float r)
{

pamt=p;
yrs=y;
rate=r;
rval=pamt;
for(int i=1;i<=y;i++)
{
rval=rval*(1.0+r);
}

fixdepo::fixdepo(int p,int y,int r)


{

pamt=p;
yrs=y;
rate=r;
rval=pamt;
for(int i=1;i<=y;i++)
{
rval=rval*(1.0+float(r)/100);
}

void fixdepo::display()
{
cout<<"\n"<<"Princlipal Amount: "<<pamt<<"\n"<<"Return Value: "<<rval<<"\n";
}
void main()
{

fixdepo f1,f2,f3;
int p;
int y;
float r;
int R;
cout<<"Enter the amount,period,interest rate pencent \n";
cin>>p>>y>>R;
f1=fixdepo(p,y,R);
cout<<"Enter the amount details and interest rate in decimal: \n";
cin>>p>>y>>r;
f2=fixdepo(p,y,r);
cout<<"Enter Amount and period: \n";
cin>>p>>y;
f3=fixdepo(p,y);
cout<<"\n Deposit 1: ";
f1.display();
cout<<"\n Deposit 2: ";
f2.display();
cout<<"\n Deposit 3: ";
f3.display();
}

getch();

/* OUTPUT:
-----------------------------------------------------------------------------Enter the amount,period,interest rate pencent
10000 3 18
Enter the amount details and interest rate in decimal:
10000 3 0.18
Enter Amount and period:
10000 3
Deposit 1:
Princlipal Amount: 10000
Return Value: 16430.3
Deposit 2:
Princlipal Amount: 10000
Return Value: 16430.3
Deposit 3:
Princlipal Amount: 10000
Return Value: 14049.3

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no : 15
Date :
Title
: write a program of copy constructor.
----------------------------------------------------------------------------------------------*/
#include<conio.h>
#include<iostream.h>
class sample
{
int hrs,min;
public:
sample();
sample(int,int);
void sum(sample,sample);
void show();
};
sample::sample(int a,int b)
{
hrs=a;
min=b;
}
void sample::sum(sample s1,sample s2)
{
min=s1.min+s2.min;
hrs=min/60;
min=min%60;
hrs=hrs+s1.hrs+s2.hrs;
}
void sample::show()
{
cout<<"Addition Of tow Time Values is: \n\n";
cout<<hrs<<" Hours"<<" : "<<min<<" minutes";
}
sample::sample()
{
}
void main()
{
sample s1(2,50);
sample s2(s1);
sample s3;
s3.sum(s1,s2);
s3.show();
}

getch();

/* OUTPUT:
---------------------------------------------------Addition Of tow Time Values is:
5 Hours : 40 minutes
--------------------------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no : 16
Date :
Title
: write a program of dynamic constructor
----------------------------------------------------------------------------------------------*/
#include<conio.h>
#include<iostream.h>
class emp
{
int i,n,*p;
char *q;
float *r;
public:
emp()
{
cout<<"enter how many records do you want: \n";
cin>>n;
}
void create()
{
p=new int[n];
q=new char[n];
r=new float[n];
}
void getdata();
void putdata();
};
void emp::getdata()
{
for(i=0;i<n;i++)
{
cout<<"Enter Employee Number:\n";
cin>>p[i];
cout<<"\nEnter Employee Name: \n";
cin>>q[i];

cout<<"\nEnter The Employee's Salary:";


cin>>r[i];

void emp::putdata()
{
for(i=0;i<n;i++)
{
cout<<"\n Employee NUmber: "<<p[i]<<"\n"<<"Employee Name: "
<<q[i]<<"\n"<<"Employee Salary: "<<r[i];
}
}
void main()

emp e;
e.create();
e.getdata();
e.putdata();
getch();

/* OUTPUT:
-----------------------------------------------------------------enter how many records do you want:
2
Enter Employee Number:
11
Enter Employee Name:
Sushma
Enter The Employee's Salary:
35000
Enter Employee Number:
22
Enter Employee Name:
sagar
Enter The Employee's Salary:
45000

Employee NUmber: 11
Employee Name: Sushma
Employee Salary: 35000
Employee NUmber: 22
Employee Name: sagar
Employee Salary: 45000
-------------------------------------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no : 17
Date :
Title
: WRITE A PROGRAM FOR UNARY (-) OPERATOR
OVERLOADING
---------------------------------------------------------------------------------------------#include<iostream.h>
#include<conio.h>
class space
{
int x ;
int y;
int z;
public:
void getdata(int,int,int);
void show();
void operator-();
};
void space::getdata(int a,int b,int c)
{
x=a;
y=b;
z=c;
}
void space::show()
{
cout<<"x= "<<x<<" ";
cout<<"y= "<<y<<" ";
cout<<"z= "<<z<<"\n";
}
void space::operator-()
{
x=-x;
y=-y;
z=-z;
}
void main()
{
space s;
s.getdata(10,-20,11);
cout<<"-s : "<<"\n";

s.show();
cout<<"s : ";
s.show();
getch();

/* OUTPUT:
------------------------------------------------s : x= -10 y= 20 z= -11
s : x= -10 y= 20 z= -11
-------------------------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no : 18
Date :
Title
: WRITE A PROGRAM FOR INCREMENT(++)
OPERATOR OVERLOADING
----------------------------------------------------------------------------------------------*/
#include<iostream.h>
#include<conio.h>
class space
{
int x ;
int y;
int z;
public:
void getdata(int,int,int);
void show();
void operator++();
};
void space::getdata(int a,int b,int c)

x=a;
y=b;
z=c;

void space::show()
{
cout<<"x= "<<x<<" ";
cout<<"y= "<<y<<" ";
cout<<"z= "<<z<<"\n";
}
void space::operator ++()
{
x++;
y++;
z++;
}
void main()
{
space s;
s.getdata(2,4,3);
cout<<"s : ";
s.show();
s++;
cout<<"\ns++ : ";
s.show();
getch();
}
/* OUTPUT:
----------------------------------------s : x= 2 y= 4 z= 3
s++ : x= 3 y= 5 z= 4
---------------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no : 19
Date :
Title
: WRITE A RPOGRAM FOR BINARY (+) OPERATOR
OVERLOADING FOR ADDITION OF 2 COMPLEX NO.
----------------------------------------------------------------------------------------------*/
#include<iostream.h>
#include<conio.h>
class complex
{
float x;
float y;
public:
complex();
complex(float real,float img)
{
x=real;
y=img;
}
complex operator + (complex);
void show();
};
complex complex::operator + (complex c)
{
complex temp;
temp.x = x+c.x;
temp.y = y+c.y;
return(temp);
}
void complex::show()
{
cout<<"x"<<" + j"<<y<<"\n";
}
void main()
{
complex c1,c2,c3;
c1=complex(2.5,3.5);
c2=complex(1.6,2.7);
c3=c1+c2;
cout<<"c1 = ";c1.show();
cout<<"c2= ";c2.show();
cout<<"c3= ";c3.show();
getch();
}

/* OUTPUT:
---------------------------------------c1 = 2.5 + j3.5
c 2 = 1.6 + j2.7
c3 = 4.1 + j6.2
-------------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no : 20
Date :
Title
: WRITE A PROGRAM FOR PRIVATE DERIVATION
IN SINGLE INHERITANCE.
----------------------------------------------------------------------------------------------*/
#include<iostream.h>
#include<conio.h>
class b
{
int a;
public:
int b;
void get_ab();
int get_a();
void show_a();
};
class d: private b
{
int c;
public:
void mul();
void display();
};
void b: get_ab()
{
cout<<"Enter values of a and b: ";
cin>>a>>b;
}
int b:: get_a()
{
return a;
}
void b::show_a()
{
cout<<"a= "<<a<<"\n";
}
void d::mul()
{
get_ab();
c=b*get_a();
}
void d::display()
{
show_a();
cout<<"b= "<<b<<"\n";
cout<<"c= "<<c<<"\n";
}

void main()
{
d d1;
d1.mul();
d1.display();
d1.mul();
d1.display();
getch();
}

/* OUTPUT:
-----------------------------------------------------Enter value of a and b: 5 10
a=5
b = 10
c = 50
Enter value of a and b: 12 20
a = 12
b = 20
c = 240
------------------------------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no : 21
Date :
Title
: WRITE A PROGRAM FOR MULTILEVEL INHERITANCE.
----------------------------------------------------------------------------------------------*/
#include<iostream.h>
#include<conio.h>
class stud
{
protected:
int rn;
public:
void get(int);
void put();
};
void stud::get(int a)
{
rn=a;
}
void stud::put()
{
cout<<"Roll Number : "<<rn<<"\n";
}
class test : public stud
{
protected:
float sub1,sub2;
public:
void getmark(float,float);
void putmark();
};
void test::getmark(float x,float y)
{
sub1=x;
sub2=y;
}
void test::putmark()
{
cout<<"Marks Of Sub 1: "<<sub1<<"\n";
cout<<"Marks Of Sub 2: "<<sub2;
}
class result
{
float total;
public:
void display();
};
void result::display()

total=sub1+sub2;
put();
putmark();
cout<<"total = "<<total<<"\n";

void main()
{
result s;
s.get(102121);
s.getmark(78.0,81.5);
s.display();
getch();
}

/* OUTPUT:
-----------------------------------------------Roll Number : 102121
Marks Of Sub 1: 78.0
Marks Of Sub 2: 81.5
total= 159.5
---------------------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no : 22
Date :
Title
: WRITE A PROGRAM FOR MULTIPLE INHERITANCE
USING VIRTUAL BASE CLASS
----------------------------------------------------------------------------------------------*/
#include <iostream>
using std::cout;
using std::endl;
class Base
{
public:
virtual void print() const = 0; // pure virtual
}; // end class Base
// class DerivedOne definition
//class DerivedOne : public Base - REF1
class DerivedOne : virtual public Base
{
public:
// override print function
void print() const
{
cout << "DerivedOne\n";
} // end function print
}; // end class DerivedOne
// class DerivedTwo definition
//class DerivedTwo : public Base - REF2
class DerivedTwo : virtual public Base
{
public:
// override print function
void print() const
{
cout << "DerivedTwo\n";
} // end function print
}; // end class DerivedTwo
// class Multiple definition
class Multiple : public DerivedOne, DerivedTwo
{
public:
// qualify which version of function print
void print() const
{
DerivedTwo::print();
} // end function print
}; // end class Multiple
int main()

Multiple both; // instantiate Multiple object


DerivedOne one; // instantiate DerivedOne object
DerivedTwo two; // instantiate DerivedTwo object
Base *array[ 3 ]; // create array of base-class pointers
array[ 0 ] = &both; // ERROR - ambiguous if REF1 and REF2 used
array[ 1 ] = &one;
array[ 2 ] = &two;
// polymorphically invoke print
for ( int i = 0; i < 3; i++ )
array[ i ] -> print();

return 0;
} // end main

/* OUTPUT:
----------------------------------------------------DerivedTwo
DerivedOne
DerivedTwo
Press any key to continur . . .
----------------------------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no : 23
Date :
Title
: WRITE A PROGRAM TO EXPLAIN THE CONSTRUCTOR
CALLING MULTILEVEL INHERITANCE.
----------------------------------------------------------------------------------------------*/
#include <iostream.h>
#include <conio.h>
class base
{
private:
int x;
public:
base (int x1)
{
cout << " Base's single parameter constructor executed n ";
x = x1;
}
};
class derv1 : public base
{
private:
int y;
public:
derv1 (int yy, int xx) : base (xx)
{
cout << " Derv1's constructor with two parameters executed n ";
y = yy;
}
};
class derv2 : public derv1
{
private:
int z;
public:
derv2 (int zz, int yy, int xx) : derv1 (yy, xx)
{
cout << " Derv2's constructor with three parameters executed ";
z = zz;
}
};
int main ( )
{
clrscr ( );
derv2 d (10, 20, 30);
getch ( );
return 0;
}

/* OUTPUT:
----------------------------------------------------------------------------------Bases single parameter constructor executed

Derv1's constructor with two parameters executed


Derv2's constructor with three parameters executed
--------------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no : 27
Date :
Title
: CREATE A CLASS TEMPLATE VECTOR AND PRINT SCALAR
PRODUCT OF 2 VECTORS.
------------------------------------------------------------------------------------------------*/
#include<iostream.h>
#include<conio.h>
const size=3;
template <class T>
class vector
{
T*v;
public:
vector()
{
v=new T(size);
for(int i=0;i<size;i++)
v[i]=0;
}
vector(T*a)
{
for(int i=0;i<size;i++)
v[i]=a[i];
}
T operator *(vector &y)
{
T sum=0;
for(int i=0;i<size;i++)
sum +=this -> v[i] * y.v[i];

return sum;
}
void display()
{
for(int i=0;i<size;i++)
cout<<v[i]<<"\t";
cout<<"\n";
}
};
void main()
{
int x[3]={1,2,3};
int y[3]={4,5,6};
vector <int>v1;
vector <int>v2;
v1=x;
v2=y;
cout<<"v1 = ";
v1.display();
cout<<"v2 = ";
v2.display();
cout<<"V1 X V2 = "<<v1*v2;
getch();
}
/* OUTPUT:
---------------------------------v1 = 1 2

v2 = 4 5

V1 X V2 = 32
--------------------------------*/

/*---------------------------------------------------------------------------------------------Name
: Pradip Rajendra Girase.
Roll no: 102130
Assignment no : 28
Date :
Title
: CREATE A FUNCTION TEMPLATE TO SWAP TWO
NUMBERS.
------------------------------------------------------------------------------------------------*/
#include<iostream.h>
#include<conio.h>
template<class T>
void swap(T &x, T &y)
{

T tem=x;
x=y;
y=tem;
}
void fun(int m,int n)
{
cout<<"M and N , Before swap: "<<m<<"\t"<<n;
swap(m,n);
cout<<"\n\n M and N After Swap: "<<m<<"\t"<<n;
}
void main()
{
fun(100,200);
getch();
}

/* OUTPUT:
---------------------------------------------------------M and N , Before swap: 100
M and N After Swap: 200

200
100

--------------------------------------------------------*/

Vous aimerez peut-être aussi