473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

yessssssss, I did it

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

Sep 20 '07 #1
5 1255
<ka******@gmail.comwrote:
finally :)
I did the program
but I have one Q ?
the numbers of the addition, ....
wrong :S
I do know y ?
<snip>

Now you have written a second program, new and different, and ignored my
advise from earlier today about writing too much without testing.

I can see three reasons for doing this:

o You didn't see what I wrote.
o You didn't understand what I wrote.
o You think my advise is not worth bothering with.

In any event I see that I wasted my time in trying to help you.


Sep 20 '07 #2
ka******@gmail.com wrote:
finally :)
I did the program
Good for you.
but I have one Q ?
You should. I also got one Q - it's next to W and A.
the numbers of the addition, ....
wrong :S
I do know y ?
I tried hardly to understand, but failed
Sep 20 '07 #3

kaloo...@gmail.com wrote:
finally :)
I did the program
but I have one Q ?
the numbers of the addition, ....
wrong :S
I do know y ?
Thankssssssssssssssssss for sharing that with us.

Sep 20 '07 #4
LR
ka******@gmail.com wrote:
finally :)
I did the program
but I have one Q ?
the numbers of the addition, ....
wrong :S

I don't know.

I suggest the following.

1) Post an example that will compile and demonstrate the error. Please
make it easy for those who might be willing to help you and make the
sample code as short as possible, and since your error seems unrelated
to io problems, please initialize all variables in the code.

2) Tell us what the answer should have been.

3) Post a short description of whatever assignment you're working on.
It can be very difficult to tell you if you're right if we don't know
what your objective is.

4) Before you do that, see if your development environment has a
debugger and use it to see whats happening in your code at runtime. Or
if there is no debugger available, then use std::cout to print things to
see what's happening.

Also, could you please spell out the words you're using in full? There
are many people here for whom english is not their first language and
they may have trouble understanding what you mean. IMHO, some native
speakers may have trouble too. I think if you do this you may get more
people trying to figure out your problem rather than figuring that the
head-scratching isn't worth their time.

And finally, could you please describe what an interval is supposed to
be. Of course, classes don't have to be named in ways that are obvious,
struct Square { double centerX_, centerY_, radius_ }; might make sense
to someone. But my understanding of what an interval is seems at odds
with the class you're creating. Maybe just my own ignorance.

TIA,

LR
Sep 20 '07 #5
<ka******@gmail.comwrote in message
news:11*********************@d55g2000hsg.googlegro ups.com...
finally :)
I did the program
but I have one Q ?
the numbers of the addition, ....
wrong :S
I do know y ?
If you're trying to do interval arithmetic, do you mean something more like
this?

#include <iostream>

template <typename T>
class Interval
{
template <typename Ufriend class Interval;
private:
T m_lower;
T m_upper;
public:
Interval(const T& lower, const T& upper)
: m_lower(lower), m_upper(upper)
{}

template <typename UInterval& operator+=(const Interval<U>& rhs)
{
/*
[a,b] + [c,d] = [a+c,b+d]
*/
m_lower += rhs.m_lower;
m_upper += rhs.m_upper;
return *this;
}

template <typename UInterval& operator-=(const Interval<U>& rhs)
{
/*
[a,b] - [c,d] = [a-d,b-c]
*/
m_lower -= rhs.m_upper;
m_upper -= rhs.m_lower;
return *this;
}

//...

const T& lower() const
{
return m_lower;
}

const T& upper() const
{
return m_upper;
}
};

template <typename T, typename U>
Interval<Toperator+(const Interval<T>& lhs, const Interval<U>& rhs) //
may not always want to return Interval<There...
{
Interval<Tret(lhs);
ret += rhs;
return ret;
}

template <typename T, typename U>
Interval<Toperator-(const Interval<T>& lhs, const Interval<U>& rhs) //
ditto
{
Interval<Tret(lhs);
ret -= rhs;
return ret;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const Interval<T>& interval)
{
os << '[' << interval.lower() << ',' << interval.upper() << ']';
return os;
}

It's late and I'm tired, so there are probably various problems with it
which can usefully be observed (indeed I welcome helpful criticism!), but I
think it's more the sort of thing you might be after.

HTH,
Stu

<snip>
Sep 21 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Skybuck Flying | last post by:
Hi, I think I understand now a bit better what the difference is between a c compiler and a pascal compiler. For example: When compiling source code with a pascal compiler. The pascal...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.