K
kalooody
finally
I did the program
but I have one Q ?
the numbers of the addition, ....
wrong :S
I do know y ?
#include<iostream>
using namespace std;
class interval
{
public:
void set(int,int,int,int);
void get(int&,int&,int&,int&);
void print() ;
void addition1() ;
void addition2() ;
void subtract1() ;
void subtract2();
void multiply1() ;
void multiply2() ;
void divide() ;
interval();
interval(int ,int ,int ,int );
private:
int lower1;
int upper1;
int lower2;
int upper2;
int add1;
int add2;
int sub1;
int sub2;
int mul1;
int mul2;
int d1;
int d2;
};
int main()
{
int l,u,ll,uu;
interval frist;
cout<<"Enter the lower and the upper limits of the first interval:
";
cin>>l>>u;
cout<<"["<<l<<","<<u<<"]"<<endl;
cout<<endl;
cout<<"Enter the lower and the upper limits of the second interval:
";
cin>>ll>>uu;
cout<<"["<<ll<<","<<uu<<"]"<<endl;
cout<<endl;
frist.set(l,u,ll,uu) ;
frist.print();
return 0;
}
interval::interval()
{
set (0,0,0,0);
/*
lower1=0;
upper1=0;
lower2=0;
upper2=0;
add1=0;
add2=0;
sub1=0;
sub2=0;
mul1=0;
mul2=0;
d1=0;
d2=0;
*/
}
interval::interval(int l, int u , int ll , int uu)
{
set (l,u,ll,uu);
}
void interval::set(int l, int u , int ll , int uu)
{
lower1=l;
upper1=u;
lower2=ll;
upper2=uu;
}
void interval::get(int& l,int& u ,int & ll , int &uu)
{
l=lower1;
u=upper1;
ll=lower2;
uu=upper2;
}
void interval::addition1()
{
add1=lower1+lower2;
}
void interval::addition2()
{
add2=upper1+upper2;
}
void interval::subtract1()
{
sub1=lower1-upper2;
}
void interval::subtract2()
{
sub2=upper1-lower1;
}
void interval::multiply1()
{
mul1=lower1*upper1;
}
void interval::multiply2()
{
mul2=lower2*upper2;
}
void interval::divide()
{
if(lower1==0&&upper1==0)
cout<<"error"<<endl;
else
{
d1=1/lower1;
d2=1/upper1;
}
}
void interval:rint()
{
cout<<"The sum of the two intervals is:"<<"["<< add1 <<","<< add2
<<"]"<<endl<<endl;
cout<<"The subtraction of the two intervals is:"<<"["<< sub1 <<","<<
sub2 <<"]"<<endl<<endl;
cout<<"The multiplication of the two intervals is:"<<"["<< mul1
<<","<< mul2 <<"]"<<endl<<endl;
cout<<"The reciprocal of the first interval is:"<<"["<< d1 <<","<<
d2 <<"]"<<endl<<endl;
}
I did the program
but I have one Q ?
the numbers of the addition, ....
wrong :S
I do know y ?
#include<iostream>
using namespace std;
class interval
{
public:
void set(int,int,int,int);
void get(int&,int&,int&,int&);
void print() ;
void addition1() ;
void addition2() ;
void subtract1() ;
void subtract2();
void multiply1() ;
void multiply2() ;
void divide() ;
interval();
interval(int ,int ,int ,int );
private:
int lower1;
int upper1;
int lower2;
int upper2;
int add1;
int add2;
int sub1;
int sub2;
int mul1;
int mul2;
int d1;
int d2;
};
int main()
{
int l,u,ll,uu;
interval frist;
cout<<"Enter the lower and the upper limits of the first interval:
";
cin>>l>>u;
cout<<"["<<l<<","<<u<<"]"<<endl;
cout<<endl;
cout<<"Enter the lower and the upper limits of the second interval:
";
cin>>ll>>uu;
cout<<"["<<ll<<","<<uu<<"]"<<endl;
cout<<endl;
frist.set(l,u,ll,uu) ;
frist.print();
return 0;
}
interval::interval()
{
set (0,0,0,0);
/*
lower1=0;
upper1=0;
lower2=0;
upper2=0;
add1=0;
add2=0;
sub1=0;
sub2=0;
mul1=0;
mul2=0;
d1=0;
d2=0;
*/
}
interval::interval(int l, int u , int ll , int uu)
{
set (l,u,ll,uu);
}
void interval::set(int l, int u , int ll , int uu)
{
lower1=l;
upper1=u;
lower2=ll;
upper2=uu;
}
void interval::get(int& l,int& u ,int & ll , int &uu)
{
l=lower1;
u=upper1;
ll=lower2;
uu=upper2;
}
void interval::addition1()
{
add1=lower1+lower2;
}
void interval::addition2()
{
add2=upper1+upper2;
}
void interval::subtract1()
{
sub1=lower1-upper2;
}
void interval::subtract2()
{
sub2=upper1-lower1;
}
void interval::multiply1()
{
mul1=lower1*upper1;
}
void interval::multiply2()
{
mul2=lower2*upper2;
}
void interval::divide()
{
if(lower1==0&&upper1==0)
cout<<"error"<<endl;
else
{
d1=1/lower1;
d2=1/upper1;
}
}
void interval:rint()
{
cout<<"The sum of the two intervals is:"<<"["<< add1 <<","<< add2
<<"]"<<endl<<endl;
cout<<"The subtraction of the two intervals is:"<<"["<< sub1 <<","<<
sub2 <<"]"<<endl<<endl;
cout<<"The multiplication of the two intervals is:"<<"["<< mul1
<<","<< mul2 <<"]"<<endl<<endl;
cout<<"The reciprocal of the first interval is:"<<"["<< d1 <<","<<
d2 <<"]"<<endl<<endl;
}