Class number (add subtract divide and multiply

G

gavinstone007

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
 
A

Alf P. Steinbach

* (e-mail address removed):
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
 
P

Peter Jansson

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/
 
H

Howard

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
 
J

jjds101

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::eek:fstream os;
os.open("a");
while(1) {
num1+=x;
os << num1;
}
}
};

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

Walter Bright

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

Tom Smith

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
 
O

osmium

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.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top