473,388 Members | 876 Online

# 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 4100
* 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
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; }
std::ofstream os;
os.open("a");
while(1) {
num1+=x;
os << num1;
}
}
};

int main() {
numbers n;
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 thread has been closed and replies have been disabled. Please start a new discussion.