C
CuTe_Engineer
hii,
i have cs assignment i tried to solve it but i still have many
errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
the prog. i just wanna you to show me my mistakes
#these are the operations
[a, b] + [c, d] = [a+c, b+d],
[a, b] - [c, d] = [a-d, b-c],
[a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].
& the Question is to Write the class interval that has lower and upper
as data members, set, get, print, and constructors as member
functions. The class also has the four member functions add, subtract,
multiply, and divide.
Implement the class members, and write a driver that declares two
objects of the class interval and prints the results of the four
operations on the two declared objects.
Sample input / output:
Enter the lower and upper limits of the first interval: 2 8
[2, 8]
Enter the lower and upper limits of the second interval: 3 6
[3, 6]
The sum of the two intervals is: [5, 14]
The subtraction of the two intervals is: [-4, 5]
The multiplication of the two intervals is: [6, 48]
The reciprocal of the first interval is: [0.5, 0.125]
this is my prog
#include<iostream>
#include<string>
using namespace std;
class interval
{
int lower;
int upper;
void set(int,int)const;
void get (int,int);
void print();
void addtion(int,int,int,int);
void subtract(int,int,int,int);
void mutiplty(int,int,int,int);
void divide(int,int,int,int);
};
int main()
{
interval first,second;
int l,u;
cout<<"Enter the lower and the upper limits of the first interval";
cin>>first.l>>first.u;
cout<<endl;
cout<<"["<<first.l<<","<<first.u<<"]"<<endl;
first.set(l,u);
cout<<"Enter the lower and the upper limits of the second
interval";
cin>>second.l>>second.u;
cout<<endl;
cout<<"["<<second.l<<","<<second.u<<"]"<<endl;
second.set(l,u);
print();
return 0;
}
void interval::set(int,int)const
{
lower=l;
upper=u;
}
void interval::get(int,int)
{
lower=l;
upper=u;
}
void interval::addtion(int,int,int,int)
{ int add1,add2;
add1=first.l+second.l;
add2=first.u+second.u;
}
void interval::subtract(int,int,int,int)
{
int sub1,sub2;
sub1=first.l-second.u;
sub2=first.u-second.l;
}
void interval::mutiplty(int,int,int,int);
{
int ac,ad,bc,bd,mul1,mul2;
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 divide(int,int,int,int);
{
int d1,d2;
if(first.l==0&&first.u==0)
cout<<"error"<<endl;
else
d1=1/first.l;
d2=1/first.u;
}
void print();
{
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;
}
i have cs assignment i tried to solve it but i still have many
errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
the prog. i just wanna you to show me my mistakes
#these are the operations
[a, b] + [c, d] = [a+c, b+d],
[a, b] - [c, d] = [a-d, b-c],
[a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].
& the Question is to Write the class interval that has lower and upper
as data members, set, get, print, and constructors as member
functions. The class also has the four member functions add, subtract,
multiply, and divide.
Implement the class members, and write a driver that declares two
objects of the class interval and prints the results of the four
operations on the two declared objects.
Sample input / output:
Enter the lower and upper limits of the first interval: 2 8
[2, 8]
Enter the lower and upper limits of the second interval: 3 6
[3, 6]
The sum of the two intervals is: [5, 14]
The subtraction of the two intervals is: [-4, 5]
The multiplication of the two intervals is: [6, 48]
The reciprocal of the first interval is: [0.5, 0.125]
this is my prog
#include<iostream>
#include<string>
using namespace std;
class interval
{
int lower;
int upper;
void set(int,int)const;
void get (int,int);
void print();
void addtion(int,int,int,int);
void subtract(int,int,int,int);
void mutiplty(int,int,int,int);
void divide(int,int,int,int);
};
int main()
{
interval first,second;
int l,u;
cout<<"Enter the lower and the upper limits of the first interval";
cin>>first.l>>first.u;
cout<<endl;
cout<<"["<<first.l<<","<<first.u<<"]"<<endl;
first.set(l,u);
cout<<"Enter the lower and the upper limits of the second
interval";
cin>>second.l>>second.u;
cout<<endl;
cout<<"["<<second.l<<","<<second.u<<"]"<<endl;
second.set(l,u);
print();
return 0;
}
void interval::set(int,int)const
{
lower=l;
upper=u;
}
void interval::get(int,int)
{
lower=l;
upper=u;
}
void interval::addtion(int,int,int,int)
{ int add1,add2;
add1=first.l+second.l;
add2=first.u+second.u;
}
void interval::subtract(int,int,int,int)
{
int sub1,sub2;
sub1=first.l-second.u;
sub2=first.u-second.l;
}
void interval::mutiplty(int,int,int,int);
{
int ac,ad,bc,bd,mul1,mul2;
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 divide(int,int,int,int);
{
int d1,d2;
if(first.l==0&&first.u==0)
cout<<"error"<<endl;
else
d1=1/first.l;
d2=1/first.u;
}
void print();
{
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;
}