468,512 Members | 1,360 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Class number (add subtract divide and multiply

Who can solve this?

Wrte a class number which represents all numbers. Implement member
functions to carry out the following arithmetic operations on class
instances, add- which returns an object of class number whose value is
the sum of the numbers added, subtract- returns an object of class
number and value is the result subtracting the second number object
from the first, multiply and divide (the return formats are the same as
for add and subtract). Provide a suitable user interface for your
program.
Have fun guys

Oct 13 '06 #1
8 3760
* ga***********@gmail.com:
Who can solve this?

Wrte a class number which represents all numbers. Implement member
functions to carry out the following arithmetic operations on class
instances, add- which returns an object of class number whose value is
the sum of the numbers added, subtract- returns an object of class
number and value is the result subtracting the second number object
from the first, multiply and divide (the return formats are the same as
for add and subtract). Provide a suitable user interface for your
program.
There's a ready-made solution in the FAQ, no need to look further.

<url: http://tinyurl.com/o5zw9>

Hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 13 '06 #2
ga***********@gmail.com wrote:
Who can solve this?

Wrte a class number which represents all numbers. Implement member
functions to carry out the following arithmetic operations on class
instances, add- which returns an object of class number whose value is
the sum of the numbers added, subtract- returns an object of class
number and value is the result subtracting the second number object
from the first, multiply and divide (the return formats are the same as
for add and subtract). Provide a suitable user interface for your
program.
Have fun guys
Perhaps you can try? Or else tell your teacher (I assume it is homework)
that you are not up to it... I.e. we will not do your homework for you.
Sincerely,

Peter Jansson
http://www.p-jansson.com/
http://www.jansson.net/
Oct 13 '06 #3

<ga***********@gmail.comwrote in message
news:11*********************@f16g2000cwb.googlegro ups.com...
Who can solve this?

Wrte a class number which represents all numbers.

Not possible. There is no way to represent "all numbers" on a computer with
finite resources. Assuming you mean integers: if you take the largest
possible integer representable using all the bits of your entire memory,
there exists a number larger than that. This number cannot be represented
on your computer, because you don't have enough bits. Likewise, if you're
talking about floating-point numbers (reals), then there exist an infinity
of numbers for which no exact representation is possible, only
approximations. Pi, for example.

But somehow I doubt that's the answer your instructor is looking for.

To correctly follow his/her instructions, might I suggest you do what he/she
says, and "write" the class instead of asking someone else to do so?

-H

Oct 13 '06 #4

ga***********@gmail.com wrote:
Who can solve this?

Wrte a class number which represents all numbers. Implement member
functions to carry out the following arithmetic operations on class
instances, add- which returns an object of class number whose value is
the sum of the numbers added, subtract- returns an object of class
number and value is the result subtracting the second number object
from the first, multiply and divide (the return formats are the same as
for add and subtract). Provide a suitable user interface for your
program.
Have fun guys
#include <fstream>

class numbers {
int num1;

public:
numbers() { num1 = 0; }
void add(int x) {
std::ofstream os;
os.open("a");
while(1) {
num1+=x;
os << num1;
}
}
};

int main() {
numbers n;
n.add(2);
return 0;
}

Oct 13 '06 #5
ga***********@gmail.com wrote:
Who can solve this?

Wrte a class number which represents all numbers. Implement member
functions to carry out the following arithmetic operations on class
instances, add- which returns an object of class number whose value is
the sum of the numbers added, subtract- returns an object of class
number and value is the result subtracting the second number object
from the first, multiply and divide (the return formats are the same as
for add and subtract). Provide a suitable user interface for your
program.
Have fun guys
You could try handing this one in:

#include <stdio.h>

class Number
{
public:
Number& operator/(Number& n) { printf("assignment\n"); return n; }
Number& operator-(Number& n) { printf("an F for "); return n; }
Number& operator+(Number& n) { printf("I deserve "); return n; }
Number& operator*(Number& n) { printf("this "); return n; }
};

int main(int argc, char **argv)
{
class Number n;

(n + n - n) * n / n;
return 0;
}
Oct 13 '06 #6
Gavin posted:
Wrte a class number which represents all numbers.

879.

Have fun guys

With your mother? I'd love too... but I have had my vaccinations.

--

Frederick Gotham
Oct 13 '06 #7
ga***********@gmail.com wrote:
Who can solve this?

Wrte a class number which represents all numbers. Implement member
functions to carry out the following arithmetic operations on class
instances, add- which returns an object of class number whose value is
the sum of the numbers added, subtract- returns an object of class
number and value is the result subtracting the second number object
from the first, multiply and divide (the return formats are the same as
for add and subtract). Provide a suitable user interface for your
program.
Have fun guys
int. long might also work.

you have fun too -

Tom
Oct 13 '06 #8
<ga***********@gmail.comwrote:
Who can solve this?

Wrte a class number which represents all numbers. Implement member
functions to carry out the following arithmetic operations on class
instances, add- which returns an object of class number whose value is
the sum of the numbers added, subtract- returns an object of class
number and value is the result subtracting the second number object
from the first, multiply and divide (the return formats are the same as
for add and subtract). Provide a suitable user interface for your
program.
Have fun guys
You just might have better luck getting useful answers if you didn't presume
the people you wanted help from were not a bunch of bumpkins who just fell
off the turnip truck.

There is no challenge here but it is likely to take a lot of time. I would
start by asking the instructor if you could restrict the solution to real
numbers. If he is really nice, he might even let you restrict it to
integers.
Oct 14 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by surrealtrauma | last post: by
4 posts views Thread by Jon | last post: by
reply views Thread by DarrenWeber | last post: by
1 post views Thread by learning | last post: by
2 posts views Thread by ankitnasa | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.