473,396 Members | 1,892 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,396 software developers and data experts.

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 4105
* 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: surrealtrauma | last post by:
the requirement is : Create a class called Rational (rational.h) for performing arithmetic with fractions. Write a program to test your class. Use Integer variables to represent the private data...
37
by: Protoman | last post by:
Hi!!! Protoman here, I need to write an infinite precision number class b/c I want to compute pi. Give me some sample code. Also, when I run my program and it computes pi, will my computer freeze...
6
by: Sami | last post by:
Problem: Social Security number being used in a database. First problem is that it will not permit numbers beginning in zero to be entered - it sees it as a null or empty space from what I can...
4
by: Jon | last post by:
This seems strange, but maybe there's some basic concept I'm missing. When I assign one class member to another, any methods that are applied to one are applied to both variables.I can't get the...
0
by: DarrenWeber | last post by:
# Copyright (C) 2007 Darren Lee Weber # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free...
1
by: learning | last post by:
Hi how can I instaltiate a class and call its method. the class has non default constructor. all examples i see only with class of defatul constructor. I am trying to pull the unit test out from...
2
by: ankitnasa | last post by:
Complete the following Java Class that may be used to represent a Rational number (i.e. a number of the form a /b where a and b are ints). Implement the constructors and methods to subtract, multiply...
0
by: zephyrus360 | last post by:
This is about a technique to find the mod of a very large integer with a normal small integer. I recently encountered this problem when I needed to compute the modulus of a very large number with...
2
by: rjddude1 | last post by:
I created a rational class, created member functions to add, subtract, multiply and divide. The reduction function however doesn't work. And the Dev cpp compiler gives a linker error. I have attached...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.