plzzzzzzzzzzzzzzzzzzzzzz help

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::print() 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;
}
 
I

Ian Collins

(e-mail address removed) wrote:

<Some code.>

Your z key is stuck.

Do you have a question?
 
O

osmium

You have incredible patience, a good quality for a programmer.

The following compiles. The errors were numerous and I didn't mark them
I gutted the program by liberally inserting \\ to form comments and #if 0
#endif to eliminate larger blocks of stuff.

Get this working to your satisfaction, try to reason what was wrong, and put
the missing functions back in. The cin.get() were added simply to make my
compiler happy, they should be harmless to you, just be aware that they
*are* there when you run it.

#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 &) ;
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()
{
int l, u;

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);
first.print();
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(second);
first.print();
//first.subtract();
//first.mutiplty();
//first.divide();


//second.addtion();
//second.subtract();
//second.mutiplty();
//second.divide();




cin.get();
cin.get();

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 & x)
{

lower = lower + x.lower; // long form for clarity
upper = upper + x.upper;
//add1=first.l+second.l;
// add2=first.u+second.u;
}

#if 0
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;
}
#endif
void interval::print() const
{

cout<< "lower:" << lower << '\n'
<< "upper:" << upper << endl;


#if 0
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;
#endif
}
 
O

osmium

osmium said:
You have incredible patience, a good quality for a programmer.

PS. I forgot to mention, you wrote too much code without testing. I would
hope that is obvious to you now.
 
O

osmium

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;
}

That is not division, that is taking the reciprocal. The *example* from
your instructor wants to compute the reciprocal, but that has to be done in
main. The *function* performs division, not reciprocal. Get subtract
working. Test.Get multiply working. Test. Get divide working. Test. Get
reciprocal working. Test. Turn it in.
 
K

kalooody

I have to submit this program tomorrow moring .......

plzzzzzzzz .. I wanna the solution if they don't mind :( :( :(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top