Friday, 22 June 2012

program 30

#include<conio.h>
#include<stdlib.h>
#include<iostream.h>
int i,m;
class array
{
public:int *ptr,n;
public:void accept();
       void display();
       array operator +(array);
       array operator -(array);
       };
void array::accept()
{
ptr=new int[m];
cout<<"\nenter the number:-";
for(i=0;i<m;i++)
cin>>ptr[i];
}
void array::display()
{
for(i=0;i<m;i++)
cout<<"\n"<<ptr[i];
}
array array::operator +(array a2)
{
array a3;
for(i=0;i<m;i++)
a3.ptr[i]=ptr[i]+a2.ptr[i];
return a3;
}
array array::operator -(array a2)
{
array a3;
for(i=0;i<m;i++)
a3.ptr[i]=ptr[i]-a2.ptr[i];
return a3;
}

int main()
{
array A1,A2,A3;
int ch;
clrscr();
cout<<"how many number:-";
cin>>A3.n;
m=A3.n;
while(1)
{
cout<<"\n1:accept an array";
cout<<"\n2:display it";
cout<<"\n3:to add two array:";
cout<<"\n4:to substract two array";
cout<<"\n5:exit";
cout<<"\nenter your choice:-";
cin>>ch;
switch(ch)
{
case 1:A1.accept();
       break;
case 2:A1.display();
       break;
case 3:cout<<"\nto accept first array:-\n";
       A1.accept();
       cout<<"\nto accept second array:-\n";
       A2.accept();
       cout<<"\naddition of two array is:-\n";
       A3=A1+A2;
       A3.display();
       break;
case 4:cout<<"\nto accept first array:-\n";
       A1.accept();
       cout<<"\nto accept second array:-\n";
       A2.accept();
       cout<<"\naddition of two array is:-\n";
       cout<<"\nsubstraction of two array is:-\n";
       A3=A1-A2;
       A3.display();
       break;
case 5:exit(0);
}
}
getch();
return 0;
}
/*
how many number:-3

to accept first array:-

enter the number:-6
9
7

to accept second array:-

enter the number:-3
2
1

addition of two array is:-

9
11
8
substraction of two array is:-

3
7
6
*/

No comments: