K
kalooody
#include<iostream>
#include<string>
using namespace std;
class interval
{
public:
void set(int,int);
void get (int &,int &) const;
void print() const;
void addtion(const interval &) const;
void subtract(const interval &) const;
void mutiplty(const interval &) const;
void divide(const interval &) const;
interval(int,int);
private:
int lower;
int upper;
int add1;
int add2;
int sub1;
int sub2;
int mul1;
int mul2;
double d1;
double d2;
};
int main()
{
interval first(l,u)
interval second(u,l);
cout<<"Enter the lower and the upper limits of the first interval";
cin>>l>>u;
cout<<"["<<l<<","<<u<<"]"<<endl;
cout<<endl;
first.set(l,u);
cout<<"Enter the lower and the upper limits of the second interval";
cin>>l>>u;
cout<<endl;
cout<<"["<<l<<","<<u<<"]"<<endl;
second.set(l,u);
first.addtion();
first.subtract();
first.mutiplty();
first.divide();
second.addtion();
second.subtract();
second.mutiplty();
second.divide();
print();
return 0;
}
interval::interval(int l, int u)
{
set (l,u);
}
void interval::set(int l,int u)
{
lower=l;
upper=u;
}
void interval::get(int & l,int & u) const
{
l=lower;
u=upper;
}
void interval::addtion(const interval &) const
{
add1=first.l+second.l;
add2=first.u+second.u;
}
void interval::subtract(const interval &) const
{
sub1=first.l-second.u;
sub2=first.u-second.l;
}
void interval::mutiplty(const interval &) const
{
int ac,ad,bc,bd;
ac=first.l*second.l;
ad=first.l*second.u;
bc=first.u*second.l;
bd=first.u*second.u;
mul1=min(ac,ad,bc,bd);
mul2=max(ac,ad,bc,bd);
}
void interval::divide(const interval &) const
{
if(first.l==0&&first.u==0)
cout<<"error"<<endl;
else
d1=1/first.l;
d2=1/first.u;
}
void interval:
rint() const
{
cout<<"The sum of the two intervals is:
[ "<<add1<<","<<add2<<"]"<<endl;
cout<<"The subtraction of the two intervals is:
[ "<<sub1<<","<<sub2<<"]"<<endl;
cout<<"The mutiplication of the two intervals is:
[ "<<mul1<<","<<mul2<<"]"<<endl;
cout<<"The reciprocal of the first interval is:
[ "<<d1<<","<<d2<<"]"<<endl;
}
#include<string>
using namespace std;
class interval
{
public:
void set(int,int);
void get (int &,int &) const;
void print() const;
void addtion(const interval &) const;
void subtract(const interval &) const;
void mutiplty(const interval &) const;
void divide(const interval &) const;
interval(int,int);
private:
int lower;
int upper;
int add1;
int add2;
int sub1;
int sub2;
int mul1;
int mul2;
double d1;
double d2;
};
int main()
{
interval first(l,u)
interval second(u,l);
cout<<"Enter the lower and the upper limits of the first interval";
cin>>l>>u;
cout<<"["<<l<<","<<u<<"]"<<endl;
cout<<endl;
first.set(l,u);
cout<<"Enter the lower and the upper limits of the second interval";
cin>>l>>u;
cout<<endl;
cout<<"["<<l<<","<<u<<"]"<<endl;
second.set(l,u);
first.addtion();
first.subtract();
first.mutiplty();
first.divide();
second.addtion();
second.subtract();
second.mutiplty();
second.divide();
print();
return 0;
}
interval::interval(int l, int u)
{
set (l,u);
}
void interval::set(int l,int u)
{
lower=l;
upper=u;
}
void interval::get(int & l,int & u) const
{
l=lower;
u=upper;
}
void interval::addtion(const interval &) const
{
add1=first.l+second.l;
add2=first.u+second.u;
}
void interval::subtract(const interval &) const
{
sub1=first.l-second.u;
sub2=first.u-second.l;
}
void interval::mutiplty(const interval &) const
{
int ac,ad,bc,bd;
ac=first.l*second.l;
ad=first.l*second.u;
bc=first.u*second.l;
bd=first.u*second.u;
mul1=min(ac,ad,bc,bd);
mul2=max(ac,ad,bc,bd);
}
void interval::divide(const interval &) const
{
if(first.l==0&&first.u==0)
cout<<"error"<<endl;
else
d1=1/first.l;
d2=1/first.u;
}
void interval:
{
cout<<"The sum of the two intervals is:
[ "<<add1<<","<<add2<<"]"<<endl;
cout<<"The subtraction of the two intervals is:
[ "<<sub1<<","<<sub2<<"]"<<endl;
cout<<"The mutiplication of the two intervals is:
[ "<<mul1<<","<<mul2<<"]"<<endl;
cout<<"The reciprocal of the first interval is:
[ "<<d1<<","<<d2<<"]"<<endl;
}