Class number (add subtract divide and multiply

Discussion in 'C++' started by gavinstone007@gmail.com, Oct 13, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. * :
    > 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?
     
    Alf P. Steinbach, Oct 13, 2006
    #2
    1. Advertising

  3. 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/
     
    Peter Jansson, Oct 13, 2006
    #3
  4. Howard Guest

    <> wrote in message
    news:...
    > 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
     
    Howard, Oct 13, 2006
    #4
  5. Guest

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

    int main() {
    numbers n;
    n.add(2);
    return 0;
    }
     
    , Oct 13, 2006
    #5
  6. 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;
    }
     
    Walter Bright, Oct 13, 2006
    #6
  7. 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
     
    Frederick Gotham, Oct 13, 2006
    #7
  8. Tom Smith Guest

    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
     
    Tom Smith, Oct 13, 2006
    #8
  9. osmium Guest

    <> 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 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.
     
    osmium, Oct 14, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    19,227
    Thomas Stanka
    Dec 15, 2005
  2. Nobody
    Replies:
    6
    Views:
    11,912
    Niels Dybdahl
    Nov 15, 2004
  3. Replies:
    5
    Views:
    591
    Christian Bau
    Sep 1, 2005
  4. Multibyte add & subtract

    , Apr 28, 2006, in forum: C Programming
    Replies:
    2
    Views:
    374
    Rod Pemberton
    Apr 29, 2006
  5. Default User
    Replies:
    16
    Views:
    733
    James Kanze
    Jul 3, 2008
Loading...

Share This Page