i need help:""<

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CuTe_Engineer

    i need help:""<

    hii,
    i have cs assignment i tried to solve it but i still have many
    errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
    the prog. i just wanna you to show me my mistakes

    #these are the operations
    [a, b] + [c, d] = [a+c, b+d],
    [a, b] - [c, d] = [a-d, b-c],
    [a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
    1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].

    & the Question is to Write the class interval that has lower and upper
    as data members, set, get, print, and constructors as member
    functions. The class also has the four member functions add, subtract,
    multiply, and divide.

    Implement the class members, and write a driver that declares two
    objects of the class interval and prints the results of the four
    operations on the two declared objects.

    Sample input / output:

    Enter the lower and upper limits of the first interval: 2 8
    [2, 8]


    Enter the lower and upper limits of the second interval: 3 6
    [3, 6]

    The sum of the two intervals is: [5, 14]

    The subtraction of the two intervals is: [-4, 5]

    The multiplication of the two intervals is: [6, 48]

    The reciprocal of the first interval is: [0.5, 0.125]



    this is my prog

    #include<iostre am>
    #include<string >

    using namespace std;

    class interval
    {
    int lower;
    int upper;
    void set(int,int)con st;
    void get (int,int);
    void print();
    void addtion(int,int ,int,int);
    void subtract(int,in t,int,int);
    void mutiplty(int,in t,int,int);
    void divide(int,int, int,int);
    };

    int main()
    {
    interval first,second;
    int l,u;

    cout<<"Enter the lower and the upper limits of the first interval";
    cin>>first.l>>f irst.u;
    cout<<endl;
    cout<<"["<<first.l<<"," <<first.u<<"]"<<endl;
    first.set(l,u);
    cout<<"Enter the lower and the upper limits of the second
    interval";
    cin>>second.l>> second.u;
    cout<<endl;
    cout<<"["<<second.l<<", "<<second.u <<"]"<<endl;

    second.set(l,u) ;
    print();

    return 0;
    }

    void interval::set(i nt,int)const
    {
    lower=l;
    upper=u;
    }
    void interval::get(i nt,int)
    {
    lower=l;
    upper=u;
    }
    void interval::addti on(int,int,int, int)
    { int add1,add2;

    add1=first.l+se cond.l;
    add2=first.u+se cond.u;
    }
    void interval::subtr act(int,int,int ,int)
    {
    int sub1,sub2;
    sub1=first.l-second.u;
    sub2=first.u-second.l;
    }
    void interval::mutip lty(int,int,int ,int);
    {
    int ac,ad,bc,bd,mul 1,mul2;

    ac=first.l*seco nd.l;
    ad=first.l*seco nd.u;
    bc=first.u*seco nd.l;
    bd=first.u*seco nd.u;

    mul1=min(ac,ad, bc,bd);
    mul2=max(ac,ad, bc,bd);
    }
    void divide(int,int, int,int);
    {
    int d1,d2;

    if(first.l==0&& first.u==0)
    cout<<"error"<< endl;
    else
    d1=1/first.l;
    d2=1/first.u;
    }
    void print();
    {
    cout<<"The sum of the two intervals is:
    [ "<<add1<<","<<a dd2<<"]"<<endl;
    cout<<"The subtraction of the two intervals is:
    [ "<<sub1<<","<<s ub2<<"]"<<endl;
    cout<<"The mutiplication of the two intervals is:
    [ "<<mul1<<","<<m ul2<<"]"<<endl;
    cout<<"The reciprocal of the first interval is:
    [ "<<d1<<","<<d2< <"]"<<endl;
    }

  • osmium

    #2
    Re: i need help:&quot;&quo t;&lt;

    "CuTe_Engin eer" writes:
    i have cs assignment i tried to solve it but i still have many
    errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
    the prog. i just wanna you to show me my mistakes
    >
    #these are the operations
    [a, b] + [c, d] = [a+c, b+d],
    [a, b] - [c, d] = [a-d, b-c],
    [a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
    1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].
    >
    & the Question is to Write the class interval that has lower and upper
    as data members, set, get, print, and constructors as member
    functions. The class also has the four member functions add, subtract,
    multiply, and divide.
    >
    Implement the class members, and write a driver that declares two
    objects of the class interval and prints the results of the four
    operations on the two declared objects.
    >
    Sample input / output:
    >
    Enter the lower and upper limits of the first interval: 2 8
    [2, 8]
    >
    >
    Enter the lower and upper limits of the second interval: 3 6
    [3, 6]
    >
    The sum of the two intervals is: [5, 14]
    >
    The subtraction of the two intervals is: [-4, 5]
    >
    The multiplication of the two intervals is: [6, 48]
    >
    The reciprocal of the first interval is: [0.5, 0.125]
    >
    >
    >
    this is my prog
    >
    #include<iostre am>
    #include<string >
    >
    using namespace std;
    >
    class interval
    {
    int lower;
    int upper;
    Private:

    That's the first error I note. The lack makes the functions private.
    void set(int,int)con st;
    void get (int,int);
    void print();
    void addtion(int,int ,int,int);
    void subtract(int,in t,int,int);
    void mutiplty(int,in t,int,int);
    void divide(int,int, int,int);
    };
    >
    int main()
    {
    interval first,second;
    int l,u;
    >
    cout<<"Enter the lower and the upper limits of the first interval";
    cin>>first.l>>f irst.u;
    cout<<endl;
    cout<<"["<<first.l<<"," <<first.u<<"]"<<endl;
    first.set(l,u);
    cout<<"Enter the lower and the upper limits of the second
    interval";
    cin>>second.l>> second.u;
    cout<<endl;
    cout<<"["<<second.l<<", "<<second.u <<"]"<<endl;
    >
    second.set(l,u) ;
    print();
    >
    return 0;
    }
    >
    void interval::set(i nt,int)const
    {
    lower=l;
    upper=u;
    }
    void interval::get(i nt,int)
    {
    lower=l;
    upper=u;
    }
    void interval::addti on(int,int,int, int)
    { int add1,add2;
    >
    add1=first.l+se cond.l;
    add2=first.u+se cond.u;
    }
    void interval::subtr act(int,int,int ,int)
    {
    int sub1,sub2;
    sub1=first.l-second.u;
    sub2=first.u-second.l;
    }
    void interval::mutip lty(int,int,int ,int);
    {
    int ac,ad,bc,bd,mul 1,mul2;
    >
    ac=first.l*seco nd.l;
    ad=first.l*seco nd.u;
    bc=first.u*seco nd.l;
    bd=first.u*seco nd.u;
    >
    mul1=min(ac,ad, bc,bd);
    mul2=max(ac,ad, bc,bd);
    }
    void divide(int,int, int,int);
    {
    int d1,d2;
    >
    if(first.l==0&& first.u==0)
    cout<<"error"<< endl;
    else
    d1=1/first.l;
    d2=1/first.u;
    }
    void print();
    {
    cout<<"The sum of the two intervals is:
    [ "<<add1<<","<<a dd2<<"]"<<endl;
    cout<<"The subtraction of the two intervals is:
    [ "<<sub1<<","<<s ub2<<"]"<<endl;
    cout<<"The mutiplication of the two intervals is:
    [ "<<mul1<<","<<m ul2<<"]"<<endl;
    cout<<"The reciprocal of the first interval is:
    [ "<<d1<<","<<d2< <"]"<<endl;
    }
    >

    Comment

    • =?ISO-8859-1?Q?Erik_Wikstr=F6m?=

      #3
      Re: i need help:&quot;&quo t;&lt;

      On 2007-09-14 15:06, CuTe_Engineer wrote:
      hii,
      i have cs assignment i tried to solve it but i still have many
      errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
      the prog. i just wanna you to show me my mistakes
      >
      #these are the operations
      [a, b] + [c, d] = [a+c, b+d],
      [a, b] - [c, d] = [a-d, b-c],
      [a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
      1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].
      >
      & the Question is to Write the class interval that has lower and upper
      as data members, set, get, print, and constructors as member
      functions. The class also has the four member functions add, subtract,
      multiply, and divide.
      >
      Implement the class members, and write a driver that declares two
      objects of the class interval and prints the results of the four
      operations on the two declared objects.
      >
      Sample input / output:
      >
      Enter the lower and upper limits of the first interval: 2 8
      [2, 8]
      >
      >
      Enter the lower and upper limits of the second interval: 3 6
      [3, 6]
      >
      The sum of the two intervals is: [5, 14]
      >
      The subtraction of the two intervals is: [-4, 5]
      >
      The multiplication of the two intervals is: [6, 48]
      >
      The reciprocal of the first interval is: [0.5, 0.125]
      >
      >
      >
      this is my prog
      >
      #include<iostre am>
      #include<string >
      >
      using namespace std;
      >
      class interval
      {
      int lower;
      int upper;
      public:
      interval(int l, int u);

      Do not forget the constructor.
      void set(int,int)con st;
      Not const, see below for explanation.
      void get (int,int);
      Will not work, see below.
      void print();
      void print() const;
      void addtion(int,int ,int,int);
      void add(const interval&) const;
      void subtract(int,in t,int,int);
      void subtract(const interval&) const;
      void mutiplty(int,in t,int,int);
      void multiply(const interval&) const;
      void divide(int,int, int,int);
      void divide(const interval&) const;
      };
      >
      int main()
      {
      interval first,second;
      Remove those, you (now) have a constructor, make sure to also use it.
      int l,u;
      >
      cout<<"Enter the lower and the upper limits of the first interval";
      cin >l >u;

      interval first(l, u);
      cout<<"["<<first.l<<"," <<first.u<<"]"<<endl;
      first.set(l,u);
      No! 1) they are called lower and upper, not l and u, 2) they are
      private, you should never change them unless through the usage of member
      functions, 3) you should use print() to show their value.
      Same goes for this the second one.
      print();
      print() is a member, you need an object to call it.
      >
      return 0;
      }
      >
      interval::inter val(int l, int u)
      {
      // Insert code here, unless you know about initialisation lists in
      // which case you should use them.
      }
      void interval::set(i nt,int)const
      Cannot use const here, it indicates that this function does not make any
      changes to the object, which is obviously does.
      {
      lower=l;
      upper=u;
      }
      void interval::get(i nt,int)
      No, this does not work, you need to pass them as references, or return a
      struct containing their values or make get_upper() and get_lower()
      functions.

      void interval::addti on(int,int,int, int)
      You should pass another interval as parameters

      void interval::addit ion(const interval&) const
      { int add1,add2;
      >
      add1=first.l+se cond.l;
      add2=first.u+se cond.u;
      }
      And you should use the constructor to create the new object.
      The same goes for the rest of the functions.
      void print();
      void interval::print () const
      {
      cout<<"The sum of the two intervals is:
      [ "<<add1<<","<<a dd2<<"]"<<endl;
      cout<<"The subtraction of the two intervals is:
      [ "<<sub1<<","<<s ub2<<"]"<<endl;
      cout<<"The mutiplication of the two intervals is:
      [ "<<mul1<<","<<m ul2<<"]"<<endl;
      cout<<"The reciprocal of the first interval is:
      [ "<<d1<<","<<d2< <"]"<<endl;
      }
      And what are add1 and add2? All those operations should be performed in
      main() and it should look something like

      cout << "The sum of the two intervals is: ";
      (first + second).print() ;

      I hope you have much time left until you need to turn the assignment in
      because you have obviously not been paying attention during the lessons
      (or your instructor is *really* bad).

      --
      Erik Wikström

      Comment

      • CuTe_Engineer

        #4
        Re: i need help:&quot;&quo t;&lt;


        On Sep 14, 8:47 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
        On 2007-09-14 15:06, CuTe_Engineer wrote:
        >
        >
        >
        >
        >
        hii,
        i have cs assignment i tried to solve it but i still have many
        errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
        the prog. i just wanna you to show me my mistakes
        >
        #these are the operations
        [a, b] + [c, d] = [a+c, b+d],
        [a, b] - [c, d] = [a-d, b-c],
        [a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
        1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].
        >
        & the Question is to Write the class interval that has lower and upper
        as data members, set, get, print, and constructors as member
        functions. The class also has the four member functions add, subtract,
        multiply, and divide.
        >
        Implement the class members, and write a driver that declares two
        objects of the class interval and prints the results of the four
        operations on the two declared objects.
        >
        Sample input / output:
        >
        Enter the lower and upper limits of the first interval: 2 8
        [2, 8]
        >
        Enter the lower and upper limits of the second interval: 3 6
        [3, 6]
        >
        The sum of the two intervals is: [5, 14]
        >
        The subtraction of the two intervals is: [-4, 5]
        >
        The multiplication of the two intervals is: [6, 48]
        >
        The reciprocal of the first interval is: [0.5, 0.125]
        >
        this is my prog
        >
        #include<iostre am>
        #include<string >
        >
        using namespace std;
        >
        class interval
        {
        int lower;
        int upper;
        >
        public:
        interval(int l, int u);
        >
        Do not forget the constructor.
        >
        void set(int,int)con st;
        >
        Not const, see below for explanation.
        >
        void get (int,int);
        >
        Will not work, see below.
        >
        void print();
        >
        void print() const;
        >
        void addtion(int,int ,int,int);
        >
        void add(const interval&) const;
        >
        void subtract(int,in t,int,int);
        >
        void subtract(const interval&) const;
        >
        void mutiplty(int,in t,int,int);
        >
        void multiply(const interval&) const;
        >
        void divide(int,int, int,int);
        >
        void divide(const interval&) const;
        >
        };
        >
        int main()
        {
        interval first,second;
        >
        Remove those, you (now) have a constructor, make sure to also use it.
        >
        int l,u;
        >
        cout<<"Enter the lower and the upper limits of the first interval";
        >
        cin >l >u;
        >
        interval first(l, u);
        >
        cout<<"["<<first.l<<"," <<first.u<<"]"<<endl;
        first.set(l,u);
        >
        No! 1) they are called lower and upper, not l and u, 2) they are
        private, you should never change them unless through the usage of member
        functions, 3) you should use print() to show their value.
        Same goes for this the second one.
        >
        print();
        >
        print() is a member, you need an object to call it.
        >
        >
        >
        return 0;
        }
        >
        interval::inter val(int l, int u)
        {
        // Insert code here, unless you know about initialisation lists in
        // which case you should use them.
        >
        }
        void interval::set(i nt,int)const
        >
        Cannot use const here, it indicates that this function does not make any
        changes to the object, which is obviously does.
        >
        {
        lower=l;
        upper=u;
        }
        void interval::get(i nt,int)
        >
        No, this does not work, you need to pass them as references, or return a
        struct containing their values or make get_upper() and get_lower()
        functions.
        >
        void interval::addti on(int,int,int, int)
        >
        You should pass another interval as parameters
        >
        void interval::addit ion(const interval&) const
        >
        { int add1,add2;
        >
        add1=first.l+se cond.l;
        add2=first.u+se cond.u;
        }
        >
        And you should use the constructor to create the new object.
        The same goes for the rest of the functions.
        >
        void print();
        >
        void interval::print () const
        >
        {
        cout<<"The sum of the two intervals is:
        [ "<<add1<<","<<a dd2<<"]"<<endl;
        cout<<"The subtraction of the two intervals is:
        [ "<<sub1<<","<<s ub2<<"]"<<endl;
        cout<<"The mutiplication of the two intervals is:
        [ "<<mul1<<","<<m ul2<<"]"<<endl;
        cout<<"The reciprocal of the first interval is:
        [ "<<d1<<","<<d2< <"]"<<endl;
        }
        >
        And what are add1 and add2? All those operations should be performed in
        main() and it should look something like
        >
        cout << "The sum of the two intervals is: ";
        (first + second).print() ;
        >
        I hope you have much time left until you need to turn the assignment in
        because you have obviously not been paying attention during the lessons
        (or your instructor is *really* bad).
        >
        --
        Erik Wikström- Hide quoted text -
        >
        - Show quoted text -
        Erik thanks for helping me you are soo kind by the way my teacher is
        not *really* bad i like him but maybe there is some thing wrong with
        me loOol

        ok now i understood your explaination but not everthing :"
        can you show me example of how to use the constructor & when should we
        use it ? i believe it is used to assgin values to the members in
        class ..

        void interval::addit ion(const interval&) const
        >
        { int add1,add2;
        >
        add1=first.l+se cond.l;
        add2=first.u+se cond.u;
        }
        >
        And you should use the constructor to create the new object.
        The same goes for the rest of the functions.( can you show me how i don`tknow how to use constuctor*)
        void interval::print () const
        >
        {
        cout<<"The sum of the two intervals is:
        [ "<<add1<<","<<a dd2<<"]"<<endl;
        cout<<"The subtraction of the two intervals is:
        [ "<<sub1<<","<<s ub2<<"]"<<endl;
        cout<<"The mutiplication of the two intervals is:
        [ "<<mul1<<","<<m ul2<<"]"<<endl;
        cout<<"The reciprocal of the first interval is:
        [ "<<d1<<","<<d2< <"]"<<endl;
        }
        >
        And what are add1 and add2? All those operations should be performed in
        main() and it should look something like
        >
        cout << "The sum of the two intervals is: ";
        (first + second).print() ;
        if i wrote all these in the main then what should i write in
        print!!!
        sorry i know that i`m annoying you :""

        thhhhhhhhhaaaaa aaaaank you very much for helping me
        i should submit my assign on thursday i still have 5 days it`s okey :)

        Comment

        • CuTe_Engineer

          #5
          Re: i need help:&quot;&quo t;&lt;

          On Sep 15, 4:40 am, CuTe_Engineer <men_3eyoo...@h otmail.comwrote :
          On Sep 14, 8:47 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
          >
          >
          >
          >
          >
          On 2007-09-14 15:06, CuTe_Engineer wrote:
          >
          hii,
          i have cs assignment i tried to solve it but i still have many
          errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
          the prog. i just wanna you to show me my mistakes
          >
          #these are the operations
          [a, b] + [c, d] = [a+c, b+d],
          [a, b] - [c, d] = [a-d, b-c],
          [a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
          1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].
          >
          & the Question is to Write the class interval that has lower and upper
          as data members, set, get, print, and constructors as member
          functions. The class also has the four member functions add, subtract,
          multiply, and divide.
          >
          Implement the class members, and write a driver that declares two
          objects of the class interval and prints the results of the four
          operations on the two declared objects.
          >
          Sample input / output:
          >
          Enter the lower and upper limits of the first interval: 2 8
          [2, 8]
          >
          Enter the lower and upper limits of the second interval: 3 6
          [3, 6]
          >
          The sum of the two intervals is: [5, 14]
          >
          The subtraction of the two intervals is: [-4, 5]
          >
          The multiplication of the two intervals is: [6, 48]
          >
          The reciprocal of the first interval is: [0.5, 0.125]
          >
          this is my prog
          >
          #include<iostre am>
          #include<string >
          >
          using namespace std;
          >
          class interval
          {
          int lower;
          int upper;
          >
          public:
          interval(int l, int u);
          >
          Do not forget the constructor.
          >
          void set(int,int)con st;
          >
          Not const, see below for explanation.
          >
          void get (int,int);
          >
          Will not work, see below.
          >
          void print();
          >
          void print() const;
          >
          void addtion(int,int ,int,int);
          >
          void add(const interval&) const;
          >
          void subtract(int,in t,int,int);
          >
          void subtract(const interval&) const;
          >
          void mutiplty(int,in t,int,int);
          >
          void multiply(const interval&) const;
          >
          void divide(int,int, int,int);
          >
          void divide(const interval&) const;
          >
          };
          >
          int main()
          {
          interval first,second;
          >
          Remove those, you (now) have a constructor, make sure to also use it.
          >
          int l,u;
          >
          cout<<"Enter the lower and the upper limits of the first interval";
          >
          cin >l >u;
          >
          interval first(l, u);
          >
          cout<<"["<<first.l<<"," <<first.u<<"]"<<endl;
          first.set(l,u);
          >
          No! 1) they are called lower and upper, not l and u, 2) they are
          private, you should never change them unless through the usage of member
          functions, 3) you should use print() to show their value.
          Same goes for this the second one.
          >
          print();
          >
          print() is a member, you need an object to call it.
          >
          return 0;
          }
          >
          interval::inter val(int l, int u)
          {
          // Insert code here, unless you know about initialisation lists in
          // which case you should use them.
          >
          }
          void interval::set(i nt,int)const
          >
          Cannot use const here, it indicates that this function does not make any
          changes to the object, which is obviously does.
          >
          {
          lower=l;
          upper=u;
          }
          void interval::get(i nt,int)
          >
          No, this does not work, you need to pass them as references, or return a
          struct containing their values or make get_upper() and get_lower()
          functions.
          >
          void interval::addti on(int,int,int, int)
          >
          You should pass another interval as parameters
          >
          void interval::addit ion(const interval&) const
          >
          { int add1,add2;
          >
          add1=first.l+se cond.l;
          add2=first.u+se cond.u;
          }
          >
          And you should use the constructor to create the new object.
          The same goes for the rest of the functions.
          >
          void print();
          >
          void interval::print () const
          >
          {
          cout<<"The sum of the two intervals is:
          [ "<<add1<<","<<a dd2<<"]"<<endl;
          cout<<"The subtraction of the two intervals is:
          [ "<<sub1<<","<<s ub2<<"]"<<endl;
          cout<<"The mutiplication of the two intervals is:
          [ "<<mul1<<","<<m ul2<<"]"<<endl;
          cout<<"The reciprocal of the first interval is:
          [ "<<d1<<","<<d2< <"]"<<endl;
          }
          >
          And what are add1 and add2? All those operations should be performed in
          main() and it should look something like
          >
          cout << "The sum of the two intervals is: ";
          (first + second).print() ;
          >
          I hope you have much time left until you need to turn the assignment in
          because you have obviously not been paying attention during the lessons
          (or your instructor is *really* bad).
          >
          --
          Erik Wikström- Hide quoted text -
          >
          - Show quoted text -
          >
          Erik thanks for helping me you are soo kind by the way my teacher is
          not *really* bad i like him but maybe there is some thing wrong with
          me loOol
          >
          ok now i understood your explaination but not everthing :"
          can you show me example of how to use the constructor & when should we
          use it ? i believe it is used to assgin values to the members in
          class ..
          >
          void interval::addit ion(const interval&) const
          >
          >
          >
          >
          >
          >
          >
          { int add1,add2;
          >
          add1=first.l+se cond.l;
          add2=first.u+se cond.u;
          }
          >
          And you should use the constructor to create the new object.
          The same goes for the rest of the functions.( can you show me how i don`t know how to use constuctor*)
          void interval::print () const
          >
          {
          cout<<"The sum of the two intervals is:
          [ "<<add1<<","<<a dd2<<"]"<<endl;
          cout<<"The subtraction of the two intervals is:
          [ "<<sub1<<","<<s ub2<<"]"<<endl;
          cout<<"The mutiplication of the two intervals is:
          [ "<<mul1<<","<<m ul2<<"]"<<endl;
          cout<<"The reciprocal of the first interval is:
          [ "<<d1<<","<<d2< <"]"<<endl;
          }
          >
          And what are add1 and add2? All those operations should be performed in
          main() and it should look something like
          >
          cout << "The sum of the two intervals is: ";
          (first + second).print() ;
          >
          if i wrote all these in the main then what should i write in
          print!!!
          sorry i know that i`m annoying you :""
          >
          thhhhhhhhhaaaaa aaaaank you very much for helping me
          i should submit my assign on thursday i still have 5 days it`s okey :)- Hide quoted text -
          >
          - Show quoted text -- Hide quoted text -
          >
          - Show quoted text -
          You should pass another interval as parameters

          void interval::addit ion(const interval&) const <<<<why???

          is my operations rigth or wrong???


          Comment

          • =?ISO-8859-1?Q?Erik_Wikstr=F6m?=

            #6
            Re: i need help:&quot;&quo t;&lt;

            On 2007-09-14 23:40, CuTe_Engineer wrote:
            On Sep 14, 8:47 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
            >On 2007-09-14 15:06, CuTe_Engineer wrote:
            >>
            >>
            >>
            >>
            >>
            hii,
            i have cs assignment i tried to solve it but i still have many
            errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
            the prog. i just wanna you to show me my mistakes
            >>
            #these are the operations
            [a, b] + [c, d] = [a+c, b+d],
            [a, b] - [c, d] = [a-d, b-c],
            [a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
            1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].
            >>
            & the Question is to Write the class interval that has lower and upper
            as data members, set, get, print, and constructors as member
            functions. The class also has the four member functions add, subtract,
            multiply, and divide.
            >>
            Implement the class members, and write a driver that declares two
            objects of the class interval and prints the results of the four
            operations on the two declared objects.
            >>
            Sample input / output:
            >>
            Enter the lower and upper limits of the first interval: 2 8
            [2, 8]
            >>
            Enter the lower and upper limits of the second interval: 3 6
            [3, 6]
            >>
            The sum of the two intervals is: [5, 14]
            >>
            The subtraction of the two intervals is: [-4, 5]
            >>
            The multiplication of the two intervals is: [6, 48]
            >>
            The reciprocal of the first interval is: [0.5, 0.125]
            >>
            this is my prog
            >>
            #include<iostre am>
            #include<string >
            >>
            using namespace std;
            >>
            class interval
            {
            int lower;
            int upper;
            >>
            >public:
            > interval(int l, int u);
            >>
            >Do not forget the constructor.
            >>
            void set(int,int)con st;
            >>
            >Not const, see below for explanation.
            >>
            void get (int,int);
            >>
            >Will not work, see below.
            >>
            void print();
            >>
            > void print() const;
            >>
            void addtion(int,int ,int,int);
            >>
            > void add(const interval&) const;
            >>
            void subtract(int,in t,int,int);
            >>
            > void subtract(const interval&) const;
            >>
            void mutiplty(int,in t,int,int);
            >>
            > void multiply(const interval&) const;
            >>
            void divide(int,int, int,int);
            >>
            > void divide(const interval&) const;
            >>
            };
            >>
            int main()
            {
            interval first,second;
            >>
            >Remove those, you (now) have a constructor, make sure to also use it.
            >>
            int l,u;
            >>
            cout<<"Enter the lower and the upper limits of the first interval";
            >>
            > cin >l >u;
            >>
            > interval first(l, u);
            >>
            cout<<"["<<first.l<<"," <<first.u<<"]"<<endl;
            first.set(l,u);
            >>
            >No! 1) they are called lower and upper, not l and u, 2) they are
            >private, you should never change them unless through the usage of member
            >functions, 3) you should use print() to show their value.
            >Same goes for this the second one.
            >>
            print();
            >>
            >print() is a member, you need an object to call it.
            >>
            >>
            >>
            return 0;
            }
            >>
            >interval::inte rval(int l, int u)
            >{
            > // Insert code here, unless you know about initialisation lists in
            > // which case you should use them.
            >>
            >}
            void interval::set(i nt,int)const
            >>
            >Cannot use const here, it indicates that this function does not make any
            >changes to the object, which is obviously does.
            >>
            {
            lower=l;
            upper=u;
            }
            void interval::get(i nt,int)
            >>
            >No, this does not work, you need to pass them as references, or return a
            >struct containing their values or make get_upper() and get_lower()
            >functions.
            >>
            void interval::addti on(int,int,int, int)
            >>
            >You should pass another interval as parameters
            >>
            >void interval::addit ion(const interval&) const
            >>
            { int add1,add2;
            >>
            add1=first.l+se cond.l;
            add2=first.u+se cond.u;
            }
            >>
            >And you should use the constructor to create the new object.
            >The same goes for the rest of the functions.
            >>
            void print();
            >>
            >void interval::print () const
            >>
            {
            cout<<"The sum of the two intervals is:
            [ "<<add1<<","<<a dd2<<"]"<<endl;
            cout<<"The subtraction of the two intervals is:
            [ "<<sub1<<","<<s ub2<<"]"<<endl;
            cout<<"The mutiplication of the two intervals is:
            [ "<<mul1<<","<<m ul2<<"]"<<endl;
            cout<<"The reciprocal of the first interval is:
            [ "<<d1<<","<<d2< <"]"<<endl;
            }
            >>
            >And what are add1 and add2? All those operations should be performed in
            >main() and it should look something like
            >>
            > cout << "The sum of the two intervals is: ";
            > (first + second).print() ;
            >>
            >I hope you have much time left until you need to turn the assignment in
            >because you have obviously not been paying attention during the lessons
            >(or your instructor is *really* bad).
            >>
            >--
            >Erik Wikström- Hide quoted text -
            >>
            >- Show quoted text -
            >
            Erik thanks for helping me you are soo kind by the way my teacher is
            not *really* bad i like him but maybe there is some thing wrong with
            me loOol
            >
            ok now i understood your explaination but not everthing :"
            can you show me example of how to use the constructor & when should we
            use it ? i believe it is used to assgin values to the members in
            class ..
            >
            void interval::addit ion(const interval&) const
            >>
            { int add1,add2;
            >>
            add1=first.l+se cond.l;
            add2=first.u+se cond.u;
            }
            >>
            >And you should use the constructor to create the new object.
            >The same goes for the rest of the functions.( can you show me how i don`t know how to use constuctor*)
            >
            >void interval::print () const
            >>
            {
            cout<<"The sum of the two intervals is:
            [ "<<add1<<","<<a dd2<<"]"<<endl;
            cout<<"The subtraction of the two intervals is:
            [ "<<sub1<<","<<s ub2<<"]"<<endl;
            cout<<"The mutiplication of the two intervals is:
            [ "<<mul1<<","<<m ul2<<"]"<<endl;
            cout<<"The reciprocal of the first interval is:
            [ "<<d1<<","<<d2< <"]"<<endl;
            }
            >>
            >And what are add1 and add2? All those operations should be performed in
            >main() and it should look something like
            >>
            > cout << "The sum of the two intervals is: ";
            > (first + second).print() ;
            >
            if i wrote all these in the main then what should i write in
            print!!!
            sorry i know that i`m annoying you :""
            >
            thhhhhhhhhaaaaa aaaaank you very much for helping me
            i should submit my assign on thursday i still have 5 days it`s okey :)
            Something that outputs the interval, so if you have code like this

            interval ival(1,2);
            ival.print();

            you should get something like

            [1,2]

            output on the terminal.

            --
            Erik Wikström

            Comment

            • =?ISO-8859-1?Q?Erik_Wikstr=F6m?=

              #7
              Re: i need help:&quot;&quo t;&lt;

              On 2007-09-14 23:48, CuTe_Engineer wrote:
              On Sep 15, 4:40 am, CuTe_Engineer <men_3eyoo...@h otmail.comwrote :
              > On Sep 14, 8:47 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
              >>
              >>
              >>
              >>
              >>
              On 2007-09-14 15:06, CuTe_Engineer wrote:
              >>
              hii,
              i have cs assignment i tried to solve it but i still have many
              errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
              the prog. i just wanna you to show me my mistakes
              >>
              #these are the operations
              [a, b] + [c, d] = [a+c, b+d],
              [a, b] - [c, d] = [a-d, b-c],
              [a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
              1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].
              >>
              & the Question is to Write the class interval that has lower and upper
              as data members, set, get, print, and constructors as member
              functions. The class also has the four member functions add, subtract,
              multiply, and divide.
              >>
              Implement the class members, and write a driver that declares two
              objects of the class interval and prints the results of the four
              operations on the two declared objects.
              >>
              Sample input / output:
              >>
              Enter the lower and upper limits of the first interval: 2 8
              [2, 8]
              >>
              Enter the lower and upper limits of the second interval: 3 6
              [3, 6]
              >>
              The sum of the two intervals is: [5, 14]
              >>
              The subtraction of the two intervals is: [-4, 5]
              >>
              The multiplication of the two intervals is: [6, 48]
              >>
              The reciprocal of the first interval is: [0.5, 0.125]
              >>
              this is my prog
              >>
              #include<iostre am>
              #include<string >
              >>
              using namespace std;
              >>
              class interval
              {
              int lower;
              int upper;
              >>
              public:
              interval(int l, int u);
              >>
              Do not forget the constructor.
              >>
              void set(int,int)con st;
              >>
              Not const, see below for explanation.
              >>
              void get (int,int);
              >>
              Will not work, see below.
              >>
              void print();
              >>
              void print() const;
              >>
              void addtion(int,int ,int,int);
              >>
              void add(const interval&) const;
              >>
              void subtract(int,in t,int,int);
              >>
              void subtract(const interval&) const;
              >>
              void mutiplty(int,in t,int,int);
              >>
              void multiply(const interval&) const;
              >>
              void divide(int,int, int,int);
              >>
              void divide(const interval&) const;
              >>
              };
              >>
              int main()
              {
              interval first,second;
              >>
              Remove those, you (now) have a constructor, make sure to also use it.
              >>
              int l,u;
              >>
              cout<<"Enter the lower and the upper limits of the first interval";
              >>
              cin >l >u;
              >>
              interval first(l, u);
              >>
              cout<<"["<<first.l<<"," <<first.u<<"]"<<endl;
              first.set(l,u);
              >>
              No! 1) they are called lower and upper, not l and u, 2) they are
              private, you should never change them unless through the usage of member
              functions, 3) you should use print() to show their value.
              Same goes for this the second one.
              >>
              print();
              >>
              print() is a member, you need an object to call it.
              >>
              return 0;
              }
              >>
              interval::inter val(int l, int u)
              {
              // Insert code here, unless you know about initialisation lists in
              // which case you should use them.
              >>
              }
              void interval::set(i nt,int)const
              >>
              Cannot use const here, it indicates that this function does not make any
              changes to the object, which is obviously does.
              >>
              {
              lower=l;
              upper=u;
              }
              void interval::get(i nt,int)
              >>
              No, this does not work, you need to pass them as references, or return a
              struct containing their values or make get_upper() and get_lower()
              functions.
              >>
              void interval::addti on(int,int,int, int)
              >>
              You should pass another interval as parameters
              >>
              void interval::addit ion(const interval&) const
              >>
              { int add1,add2;
              >>
              add1=first.l+se cond.l;
              add2=first.u+se cond.u;
              }
              >>
              And you should use the constructor to create the new object.
              The same goes for the rest of the functions.
              >>
              void print();
              >>
              void interval::print () const
              >>
              {
              cout<<"The sum of the two intervals is:
              [ "<<add1<<","<<a dd2<<"]"<<endl;
              cout<<"The subtraction of the two intervals is:
              [ "<<sub1<<","<<s ub2<<"]"<<endl;
              cout<<"The mutiplication of the two intervals is:
              [ "<<mul1<<","<<m ul2<<"]"<<endl;
              cout<<"The reciprocal of the first interval is:
              [ "<<d1<<","<<d2< <"]"<<endl;
              }
              >>
              And what are add1 and add2? All those operations should be performed in
              main() and it should look something like
              >>
              cout << "The sum of the two intervals is: ";
              (first + second).print() ;
              >>
              I hope you have much time left until you need to turn the assignment in
              because you have obviously not been paying attention during the lessons
              (or your instructor is *really* bad).
              >>
              --
              Erik Wikström- Hide quoted text -
              >>
              - Show quoted text -
              >>
              >Erik thanks for helping me you are soo kind by the way my teacher is
              >not *really* bad i like him but maybe there is some thing wrong with
              >me loOol
              >>
              >ok now i understood your explaination but not everthing :"
              >can you show me example of how to use the constructor & when should we
              >use it ? i believe it is used to assgin values to the members in
              >class ..
              >>
              > void interval::addit ion(const interval&) const
              >>
              >>
              >>
              >>
              >>
              >>
              >>
              { int add1,add2;
              >>
              add1=first.l+se cond.l;
              add2=first.u+se cond.u;
              }
              >>
              And you should use the constructor to create the new object.
              The same goes for the rest of the functions.( can you show me how i don`t know how to use constuctor*)
              void interval::print () const
              >>
              {
              cout<<"The sum of the two intervals is:
              [ "<<add1<<","<<a dd2<<"]"<<endl;
              cout<<"The subtraction of the two intervals is:
              [ "<<sub1<<","<<s ub2<<"]"<<endl;
              cout<<"The mutiplication of the two intervals is:
              [ "<<mul1<<","<<m ul2<<"]"<<endl;
              cout<<"The reciprocal of the first interval is:
              [ "<<d1<<","<<d2< <"]"<<endl;
              }
              >>
              And what are add1 and add2? All those operations should be performed in
              main() and it should look something like
              >>
              cout << "The sum of the two intervals is: ";
              (first + second).print() ;
              >>
              > if i wrote all these in the main then what should i write in
              >print!!!
              > sorry i know that i`m annoying you :""
              >>
              >thhhhhhhhhaaaa aaaaaank you very much for helping me
              >i should submit my assign on thursday i still have 5 days it`s okey :)- Hide quoted text -
              >>
              >- Show quoted text -- Hide quoted text -
              >>
              >- Show quoted text -
              Please don't reply to your own post unless to correct your previous post.
              You should pass another interval as parameters
              >
              void interval::addit ion(const interval&) const <<<<why???
              To make the operations sane, given that you had made addition a member
              function one would assume that the intended use was something like this:

              interval a, b;
              interval c = a.add(b);

              --
              Erik Wikström

              Comment

              • =?ISO-8859-1?Q?Erik_Wikstr=F6m?=

                #8
                Re: i need help:&quot;&quo t;&lt;

                On 2007-09-14 23:40, CuTe_Engineer wrote:
                On Sep 14, 8:47 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
                >On 2007-09-14 15:06, CuTe_Engineer wrote:
                >>
                >>
                >>
                >>
                >>
                hii,
                i have cs assignment i tried to solve it but i still have many
                errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
                the prog. i just wanna you to show me my mistakes
                >>
                #these are the operations
                [a, b] + [c, d] = [a+c, b+d],
                [a, b] - [c, d] = [a-d, b-c],
                [a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
                1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].
                >>
                & the Question is to Write the class interval that has lower and upper
                as data members, set, get, print, and constructors as member
                functions. The class also has the four member functions add, subtract,
                multiply, and divide.
                >>
                Implement the class members, and write a driver that declares two
                objects of the class interval and prints the results of the four
                operations on the two declared objects.
                >>
                Sample input / output:
                >>
                Enter the lower and upper limits of the first interval: 2 8
                [2, 8]
                >>
                Enter the lower and upper limits of the second interval: 3 6
                [3, 6]
                >>
                The sum of the two intervals is: [5, 14]
                >>
                The subtraction of the two intervals is: [-4, 5]
                >>
                The multiplication of the two intervals is: [6, 48]
                >>
                The reciprocal of the first interval is: [0.5, 0.125]
                >>
                this is my prog
                >>
                #include<iostre am>
                #include<string >
                >>
                using namespace std;
                >>
                class interval
                {
                int lower;
                int upper;
                >>
                >public:
                > interval(int l, int u);
                >>
                >Do not forget the constructor.
                >>
                void set(int,int)con st;
                >>
                >Not const, see below for explanation.
                >>
                void get (int,int);
                >>
                >Will not work, see below.
                >>
                void print();
                >>
                > void print() const;
                >>
                void addtion(int,int ,int,int);
                >>
                > void add(const interval&) const;
                >>
                void subtract(int,in t,int,int);
                >>
                > void subtract(const interval&) const;
                >>
                void mutiplty(int,in t,int,int);
                >>
                > void multiply(const interval&) const;
                >>
                void divide(int,int, int,int);
                >>
                > void divide(const interval&) const;
                >>
                };
                >>
                int main()
                {
                interval first,second;
                >>
                >Remove those, you (now) have a constructor, make sure to also use it.
                >>
                int l,u;
                >>
                cout<<"Enter the lower and the upper limits of the first interval";
                >>
                > cin >l >u;
                >>
                > interval first(l, u);
                >>
                cout<<"["<<first.l<<"," <<first.u<<"]"<<endl;
                first.set(l,u);
                >>
                >No! 1) they are called lower and upper, not l and u, 2) they are
                >private, you should never change them unless through the usage of member
                >functions, 3) you should use print() to show their value.
                >Same goes for this the second one.
                >>
                print();
                >>
                >print() is a member, you need an object to call it.
                >>
                >>
                >>
                return 0;
                }
                >>
                >interval::inte rval(int l, int u)
                >{
                > // Insert code here, unless you know about initialisation lists in
                > // which case you should use them.
                >>
                >}
                void interval::set(i nt,int)const
                >>
                >Cannot use const here, it indicates that this function does not make any
                >changes to the object, which is obviously does.
                >>
                {
                lower=l;
                upper=u;
                }
                void interval::get(i nt,int)
                >>
                >No, this does not work, you need to pass them as references, or return a
                >struct containing their values or make get_upper() and get_lower()
                >functions.
                >>
                void interval::addti on(int,int,int, int)
                >>
                >You should pass another interval as parameters
                >>
                >void interval::addit ion(const interval&) const
                >>
                { int add1,add2;
                >>
                add1=first.l+se cond.l;
                add2=first.u+se cond.u;
                }
                >>
                >And you should use the constructor to create the new object.
                >The same goes for the rest of the functions.
                >>
                void print();
                >>
                >void interval::print () const
                >>
                {
                cout<<"The sum of the two intervals is:
                [ "<<add1<<","<<a dd2<<"]"<<endl;
                cout<<"The subtraction of the two intervals is:
                [ "<<sub1<<","<<s ub2<<"]"<<endl;
                cout<<"The mutiplication of the two intervals is:
                [ "<<mul1<<","<<m ul2<<"]"<<endl;
                cout<<"The reciprocal of the first interval is:
                [ "<<d1<<","<<d2< <"]"<<endl;
                }
                >>
                >And what are add1 and add2? All those operations should be performed in
                >main() and it should look something like
                >>
                > cout << "The sum of the two intervals is: ";
                > (first + second).print() ;
                >>
                >I hope you have much time left until you need to turn the assignment in
                >because you have obviously not been paying attention during the lessons
                >(or your instructor is *really* bad).
                >>
                >--
                >Erik Wikström- Hide quoted text -
                >>
                >- Show quoted text -
                >
                Erik thanks for helping me you are soo kind by the way my teacher is
                not *really* bad i like him but maybe there is some thing wrong with
                me loOol
                >
                ok now i understood your explaination but not everthing :"
                can you show me example of how to use the constructor & when should we
                use it ? i believe it is used to assgin values to the members in
                class ..
                >
                void interval::addit ion(const interval&) const
                Constructors are used when you create a new object. When an object is
                created a constructor will be run, if you have not declared any
                constructors the compiler will create a default one for you. Often when
                you create an object you know what values you want it to have, so you
                can pass those to the constructor. To create an interval between 3 and 7
                use the constructor like this:

                interval myInterval(3,7) ;

                This is much better (cleaner, more efficient, etc.) than the alternative:

                interval myInterval;
                myInterval.set( 3,7);

                --
                Erik Wikström

                Comment

                • CuTe_Engineer

                  #9
                  Re: i need help:&quot;&quo t;&lt;

                  On Sep 15, 5:49 am, Erik Wikström <Erik-wikst...@telia. comwrote:
                  On 2007-09-14 23:40, CuTe_Engineer wrote:
                  >
                  >
                  >
                  >
                  >
                  On Sep 14, 8:47 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
                  On 2007-09-14 15:06, CuTe_Engineer wrote:
                  >
                  hii,
                  i have cs assignment i tried to solve it but i still have many
                  errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
                  the prog. i just wanna you to show me my mistakes
                  >
                  #these are the operations
                  [a, b] + [c, d] = [a+c, b+d],
                  [a, b] - [c, d] = [a-d, b-c],
                  [a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
                  1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].
                  >
                  & the Question is to Write the class interval that has lower and upper
                  as data members, set, get, print, and constructors as member
                  functions. The class also has the four member functions add, subtract,
                  multiply, and divide.
                  >
                  Implement the class members, and write a driver that declares two
                  objects of the class interval and prints the results of the four
                  operations on the two declared objects.
                  >
                  Sample input / output:
                  >
                  Enter the lower and upper limits of the first interval: 2 8
                  [2, 8]
                  >
                  Enter the lower and upper limits of the second interval: 3 6
                  [3, 6]
                  >
                  The sum of the two intervals is: [5, 14]
                  >
                  The subtraction of the two intervals is: [-4, 5]
                  >
                  The multiplication of the two intervals is: [6, 48]
                  >
                  The reciprocal of the first interval is: [0.5, 0.125]
                  >
                  this is my prog
                  >
                  #include<iostre am>
                  #include<string >
                  >
                  using namespace std;
                  >
                  class interval
                  {
                  int lower;
                  int upper;
                  >
                  public:
                  interval(int l, int u);
                  >
                  Do not forget the constructor.
                  >
                  void set(int,int)con st;
                  >
                  Not const, see below for explanation.
                  >
                  void get (int,int);
                  >
                  Will not work, see below.
                  >
                  void print();
                  >
                  void print() const;
                  >
                  void addtion(int,int ,int,int);
                  >
                  void add(const interval&) const;
                  >
                  void subtract(int,in t,int,int);
                  >
                  void subtract(const interval&) const;
                  >
                  void mutiplty(int,in t,int,int);
                  >
                  void multiply(const interval&) const;
                  >
                  void divide(int,int, int,int);
                  >
                  void divide(const interval&) const;
                  >
                  };
                  >
                  int main()
                  {
                  interval first,second;
                  >
                  Remove those, you (now) have a constructor, make sure to also use it.
                  >
                  int l,u;
                  >
                  cout<<"Enter the lower and the upper limits of the first interval";
                  >
                  cin >l >u;
                  >
                  interval first(l, u);
                  >
                  cout<<"["<<first.l<<"," <<first.u<<"]"<<endl;
                  first.set(l,u);
                  >
                  No! 1) they are called lower and upper, not l and u, 2) they are
                  private, you should never change them unless through the usage of member
                  functions, 3) you should use print() to show their value.
                  Same goes for this the second one.
                  >
                  print();
                  >
                  print() is a member, you need an object to call it.
                  >
                  return 0;
                  }
                  >
                  interval::inter val(int l, int u)
                  {
                  // Insert code here, unless you know about initialisation lists in
                  // which case you should use them.
                  >
                  }
                  void interval::set(i nt,int)const
                  >
                  Cannot use const here, it indicates that this function does not make any
                  changes to the object, which is obviously does.
                  >
                  {
                  lower=l;
                  upper=u;
                  }
                  void interval::get(i nt,int)
                  >
                  No, this does not work, you need to pass them as references, or returna
                  struct containing their values or make get_upper() and get_lower()
                  functions.
                  >
                  void interval::addti on(int,int,int, int)
                  >
                  You should pass another interval as parameters
                  >
                  void interval::addit ion(const interval&) const
                  >
                  { int add1,add2;
                  >
                  add1=first.l+se cond.l;
                  add2=first.u+se cond.u;
                  }
                  >
                  And you should use the constructor to create the new object.
                  The same goes for the rest of the functions.
                  >
                  void print();
                  >
                  void interval::print () const
                  >
                  {
                  cout<<"The sum of the two intervals is:
                  [ "<<add1<<","<<a dd2<<"]"<<endl;
                  cout<<"The subtraction of the two intervals is:
                  [ "<<sub1<<","<<s ub2<<"]"<<endl;
                  cout<<"The mutiplication of the two intervals is:
                  [ "<<mul1<<","<<m ul2<<"]"<<endl;
                  cout<<"The reciprocal of the first interval is:
                  [ "<<d1<<","<<d2< <"]"<<endl;
                  }
                  >
                  And what are add1 and add2? All those operations should be performed in
                  main() and it should look something like
                  >
                  cout << "The sum of the two intervals is: ";
                  (first + second).print() ;
                  >
                  I hope you have much time left until you need to turn the assignment in
                  because you have obviously not been paying attention during the lessons
                  (or your instructor is *really* bad).
                  >
                  --
                  Erik Wikström- Hide quoted text -
                  >
                  - Show quoted text -
                  >
                  Erik thanks for helping me you are soo kind by the way my teacher is
                  not *really* bad i like him but maybe there is some thing wrong with
                  me loOol
                  >
                  ok now i understood your explaination but not everthing :"
                  can you show me example of how to use the constructor & when should we
                  use it ? i believe it is used to assgin values to the members in
                  class ..
                  >
                  void interval::addit ion(const interval&) const
                  >
                  Constructors are used when you create a new object. When an object is
                  created a constructor will be run, if you have not declared any
                  constructors the compiler will create a default one for you. Often when
                  you create an object you know what values you want it to have, so you
                  can pass those to the constructor. To create an interval between 3 and 7
                  use the constructor like this:
                  >
                  interval myInterval(3,7) ;
                  >
                  This is much better (cleaner, more efficient, etc.) than the alternative:
                  >
                  interval myInterval;
                  myInterval.set( 3,7);
                  >
                  --
                  Erik Wikström- Hide quoted text -
                  >
                  - Show quoted text -
                  this is my new prog. i hope it`s better now
                  you told that we shouldn`t put all these things in the function print
                  but i didn`t understand what should we do with it if we didn`t placed
                  it in print " what`s the benefit of print??"
                  is my constructor ok now?

                  sorry i don`t have the software at home to compile it so i can see my
                  mistakes.

                  #include<iostre am>
                  #include<string >

                  using namespace std;

                  class interval
                  {
                  public:
                  interval();
                  interval(int ,int );
                  void set(int,int);
                  void print() const;
                  void addittion(const interval&) const;
                  void subtract(const interval&) const;
                  void multiply(const interval&) const;
                  void divide(const interval&) const;
                  void set(int,int);
                  void get(int&,int&);
                  private:
                  int lower;
                  int upper;
                  };

                  int main()
                  {
                  interval interval1,
                  interval interval2(3,6),

                  cout<<"Enter the lower and the upper limits of the first interval";
                  cin>>lower>>upp er;
                  interval1.set(2 ,8)
                  cout<<endl;
                  cout<<"["<<lower<<","<< upper<<"]"<<endl;

                  cout<<"Enter the lower and the upper limits of the second
                  interval";
                  cin>>lower>>upp er;
                  interval2.set(3 ,6)
                  cout<<endl;
                  cout<<"["<<lower<<","<< upper<<"]"<<endl;


                  interval.print( );

                  return 0;
                  }
                  interval::inter val()
                  {
                  lower=2
                  upper=8
                  }
                  interval::inter val(int lower, int upper)
                  {
                  lower=3;
                  upper=6;

                  void interval::set(i nt,int)
                  {
                  lower=l;
                  upper=u;
                  }
                  void interval::get(i nt&,int&)const
                  {
                  lower=l;
                  upper=u;
                  }
                  void interval::addit ion(int,int,int ,int)
                  {
                  int add1,add2;

                  add1=interval1. lower+interval2 .lower;
                  add2=interval1. upper+interval2 .upper;


                  }
                  void interval::subtr act(int,int,int ,int)
                  {
                  int sub1,sub2;

                  sub1=interval1. lower-interval2.upper ;
                  sub2=interval1. upper-interval2.lower ;

                  }
                  void interval::mutip lty(int,int,int ,int);
                  {
                  int ac,ad,bc,bd,mul 1,mul2;

                  ac=interval1.lo wer*interval2.s econd;
                  ad=interval1.lo wer*interval2.u pper;
                  bc=interval1.up per*interval2.l ower;
                  bd=interval1.up per*interval2.u pper;

                  mul1=min(ac,ad, bc,bd);
                  mul2=max(ac,ad, bc,bd);

                  }
                  void divide(int,int, int,int);
                  {
                  int d1,d2;

                  if(interval1.lo wer==0&&interva l1.upper==0)
                  cout<<"error"<< endl;
                  else
                  d1=1/interval1.lower ;
                  d2=1/interval1.upper ;

                  }
                  void print();
                  {
                  cout<<"The sum of the two intervals is:"<<"["<< add1 <<","<< add2
                  <<"]"<<endl;
                  cout<<"The subtraction of the two intervals is:"<<"["<< sub1
                  <<","<< sub2 <<"]";<<endl;
                  cout<<"The multiplication of the two intervals is:"<<"["<< mul1
                  <<","<< amul2 <<"]"<<endl;
                  cout<<"The reciprocal of the first interval is:"<<"["<< d1 <<","<<
                  d2 <<"]"<<endl;

                  }


                  Comment

                  • =?ISO-8859-1?Q?Erik_Wikstr=F6m?=

                    #10
                    Re: i need help:&quot;&quo t;&lt;

                    On 2007-09-15 10:05, CuTe_Engineer wrote:
                    On Sep 15, 5:49 am, Erik Wikström <Erik-wikst...@telia. comwrote:
                    >On 2007-09-14 23:40, CuTe_Engineer wrote:
                    >>
                    >>
                    >>
                    >>
                    >>
                    On Sep 14, 8:47 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
                    >On 2007-09-14 15:06, CuTe_Engineer wrote:
                    >>
                    hii,
                    i have cs assignment i tried to solve it but i still have many
                    errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
                    the prog. i just wanna you to show me my mistakes
                    >>
                    #these are the operations
                    [a, b] + [c, d] = [a+c, b+d],
                    [a, b] - [c, d] = [a-d, b-c],
                    [a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
                    1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].
                    >>
                    & the Question is to Write the class interval that has lower and upper
                    as data members, set, get, print, and constructors as member
                    functions. The class also has the four member functions add, subtract,
                    multiply, and divide.
                    >>
                    Implement the class members, and write a driver that declares two
                    objects of the class interval and prints the results of the four
                    operations on the two declared objects.
                    >>
                    Sample input / output:
                    >>
                    Enter the lower and upper limits of the first interval: 2 8
                    [2, 8]
                    >>
                    Enter the lower and upper limits of the second interval: 3 6
                    [3, 6]
                    >>
                    The sum of the two intervals is: [5, 14]
                    >>
                    The subtraction of the two intervals is: [-4, 5]
                    >>
                    The multiplication of the two intervals is: [6, 48]
                    >>
                    The reciprocal of the first interval is: [0.5, 0.125]
                    >>
                    this is my prog
                    >>
                    #include<iostre am>
                    #include<string >
                    >>
                    using namespace std;
                    >>
                    class interval
                    {
                    int lower;
                    int upper;
                    >>
                    >public:
                    > interval(int l, int u);
                    >>
                    >Do not forget the constructor.
                    >>
                    void set(int,int)con st;
                    >>
                    >Not const, see below for explanation.
                    >>
                    void get (int,int);
                    >>
                    >Will not work, see below.
                    >>
                    void print();
                    >>
                    > void print() const;
                    >>
                    void addtion(int,int ,int,int);
                    >>
                    > void add(const interval&) const;
                    >>
                    void subtract(int,in t,int,int);
                    >>
                    > void subtract(const interval&) const;
                    >>
                    void mutiplty(int,in t,int,int);
                    >>
                    > void multiply(const interval&) const;
                    >>
                    void divide(int,int, int,int);
                    >>
                    > void divide(const interval&) const;
                    >>
                    };
                    >>
                    int main()
                    {
                    interval first,second;
                    >>
                    >Remove those, you (now) have a constructor, make sure to also use it.
                    >>
                    int l,u;
                    >>
                    cout<<"Enter the lower and the upper limits of the first interval";
                    >>
                    > cin >l >u;
                    >>
                    > interval first(l, u);
                    >>
                    cout<<"["<<first.l<<"," <<first.u<<"]"<<endl;
                    first.set(l,u);
                    >>
                    >No! 1) they are called lower and upper, not l and u, 2) they are
                    >private, you should never change them unless through the usage of member
                    >functions, 3) you should use print() to show their value.
                    >Same goes for this the second one.
                    >>
                    print();
                    >>
                    >print() is a member, you need an object to call it.
                    >>
                    return 0;
                    }
                    >>
                    >interval::inte rval(int l, int u)
                    >{
                    > // Insert code here, unless you know about initialisation lists in
                    > // which case you should use them.
                    >>
                    >}
                    void interval::set(i nt,int)const
                    >>
                    >Cannot use const here, it indicates that this function does not make any
                    >changes to the object, which is obviously does.
                    >>
                    {
                    lower=l;
                    upper=u;
                    }
                    void interval::get(i nt,int)
                    >>
                    >No, this does not work, you need to pass them as references, or return a
                    >struct containing their values or make get_upper() and get_lower()
                    >functions.
                    >>
                    void interval::addti on(int,int,int, int)
                    >>
                    >You should pass another interval as parameters
                    >>
                    >void interval::addit ion(const interval&) const
                    >>
                    { int add1,add2;
                    >>
                    add1=first.l+se cond.l;
                    add2=first.u+se cond.u;
                    }
                    >>
                    >And you should use the constructor to create the new object.
                    >The same goes for the rest of the functions.
                    >>
                    void print();
                    >>
                    >void interval::print () const
                    >>
                    {
                    cout<<"The sum of the two intervals is:
                    [ "<<add1<<","<<a dd2<<"]"<<endl;
                    cout<<"The subtraction of the two intervals is:
                    [ "<<sub1<<","<<s ub2<<"]"<<endl;
                    cout<<"The mutiplication of the two intervals is:
                    [ "<<mul1<<","<<m ul2<<"]"<<endl;
                    cout<<"The reciprocal of the first interval is:
                    [ "<<d1<<","<<d2< <"]"<<endl;
                    }
                    >>
                    >And what are add1 and add2? All those operations should be performed in
                    >main() and it should look something like
                    >>
                    > cout << "The sum of the two intervals is: ";
                    > (first + second).print() ;
                    >>
                    >I hope you have much time left until you need to turn the assignment in
                    >because you have obviously not been paying attention during the lessons
                    >(or your instructor is *really* bad).
                    >>
                    >--
                    >Erik Wikström- Hide quoted text -
                    >>
                    >- Show quoted text -
                    >>
                    Erik thanks for helping me you are soo kind by the way my teacher is
                    not *really* bad i like him but maybe there is some thing wrong with
                    me loOol
                    >>
                    ok now i understood your explaination but not everthing :"
                    can you show me example of how to use the constructor & when should we
                    use it ? i believe it is used to assgin values to the members in
                    class ..
                    >>
                    void interval::addit ion(const interval&) const
                    >>
                    >Constructors are used when you create a new object. When an object is
                    >created a constructor will be run, if you have not declared any
                    >constructors the compiler will create a default one for you. Often when
                    >you create an object you know what values you want it to have, so you
                    >can pass those to the constructor. To create an interval between 3 and 7
                    >use the constructor like this:
                    >>
                    > interval myInterval(3,7) ;
                    >>
                    >This is much better (cleaner, more efficient, etc.) than the alternative:
                    >>
                    > interval myInterval;
                    > myInterval.set( 3,7);
                    >>
                    >--
                    >Erik Wikström- Hide quoted text -
                    >>
                    >- Show quoted text -
                    this is my new prog. i hope it`s better now
                    you told that we shouldn`t put all these things in the function print
                    but i didn`t understand what should we do with it if we didn`t placed
                    it in print " what`s the benefit of print??"
                    is my constructor ok now?
                    >
                    sorry i don`t have the software at home to compile it so i can see my
                    mistakes.
                    >
                    #include<iostre am>
                    #include<string >
                    >
                    using namespace std;
                    >
                    class interval
                    {
                    public:
                    interval();
                    interval(int ,int );
                    void set(int,int);
                    void print() const;
                    void addittion(const interval&) const;
                    void subtract(const interval&) const;
                    void multiply(const interval&) const;
                    void divide(const interval&) const;
                    void set(int,int);
                    void get(int&,int&);
                    private:
                    int lower;
                    int upper;
                    };
                    >
                    int main()
                    {
                    interval interval1,
                    interval interval2(3,6),
                    >
                    cout<<"Enter the lower and the upper limits of the first interval";
                    cin>>lower>>upp er;
                    interval1.set(2 ,8)
                    cout<<endl;
                    cout<<"["<<lower<<","<< upper<<"]"<<endl;
                    The idea is that you should read in the values from the user, then pass
                    those values to the constructor so you do not have to use set(). Then
                    you will call print() which will do the job of the last line above.

                    By the way, are you sure you should use predefined values in the
                    intervals and not those read from the user?
                    interval::inter val()
                    {
                    lower=2
                    upper=8
                    }
                    Usually one would use something like 0,0 as default values, or the min
                    and max values of an integer.
                    interval::inter val(int lower, int upper)
                    {
                    lower=3;
                    upper=6;
                    }

                    Perhaps you should make some use of those parameters?
                    void interval::set(i nt,int)
                    {
                    lower=l;
                    upper=u;
                    }
                    void interval::get(i nt&,int&)const
                    {
                    lower=l;
                    upper=u;
                    }
                    Have you actually tried to compile your code? Where did l and u come from?
                    void interval::addit ion(int,int,int ,int)
                    Re-read my previous posts regarding the operations.
                    void print();
                    {
                    cout<<"The sum of the two intervals is:"<<"["<< add1 <<","<< add2
                    <<"]"<<endl;
                    cout<<"The subtraction of the two intervals is:"<<"["<< sub1
                    <<","<< sub2 <<"]";<<endl;
                    cout<<"The multiplication of the two intervals is:"<<"["<< mul1
                    <<","<< amul2 <<"]"<<endl;
                    cout<<"The reciprocal of the first interval is:"<<"["<< d1 <<","<<
                    d2 <<"]"<<endl;
                    >
                    }
                    Frankly I do not see much of a difference between this new code and the
                    original, besides two constructors which you then totally fail to make
                    use of in any meaningful way.

                    It is becoming more and more obvious that you have failed to understand
                    the most basic concepts of procedural programming like scope and
                    lifetime, until you learn those you can not advance to more advanced
                    topics like objects (which is a basic concept of object oriented
                    programming, what you are trying to do). I suggest that you start over
                    from chapter 1 and read carefully and do the exercises, or talk to your
                    lecturer about some private tutoring.

                    --
                    Erik Wikström

                    Comment

                    • BobR

                      #11
                      Re: i need help:&quot;&quo t;&lt;


                      Erik Wikström <Erik-wikstrom@telia. comwrote in message
                      news:okOGi.8831 $ZA.4403@newsb. telia.net...
                      On 2007-09-15 10:05, CuTe_Engineer wrote:
                      On Sep 15, 5:49 am, Erik Wikström <Erik-wikst...@telia. comwrote:
                      On 2007-09-14 23:40, CuTe_Engineer wrote:
                      >
                      >
                      >
                      >
                      >
                      On Sep 14, 8:47 pm, Erik Wikström <Erik-wikst...@telia. com>
                      wrote:
                      On 2007-09-14 15:06, CuTe_Engineer wrote:
                      >
                      >
                      >
                      hii,
                      i have cs assignment i tried to solve it but i still have many
                      errors , plzz help mee :"< it`s not cheating becuz i`ve tried &
                      wrote
                      the prog. i just wanna you to show me my mistakes
                      >
                      #these are the operations
                      [a, b] + [c, d] = [a+c, b+d],
                      [a, b] - [c, d] = [a-d, b-c],
                      [a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
                      1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].
                      >
                      & the Question is to Write the class interval that has lower and
                      upper
                      as data members, set, get, print, and constructors as member
                      functions. The class also has the four member functions add,
                      subtract,
                      multiply, and divide.
                      >
                      Implement the class members, and write a driver that declares two
                      objects of the class interval and prints the results of the four
                      operations on the two declared objects.
                      >
                      Sample input / output:
                      >
                      Enter the lower and upper limits of the first interval: 2 8
                      [2, 8]
                      >
                      Enter the lower and upper limits of the second interval: 3 6
                      [3, 6]
                      >
                      The sum of the two intervals is: [5, 14]
                      >
                      The subtraction of the two intervals is: [-4, 5]
                      >
                      The multiplication of the two intervals is: [6, 48]
                      >
                      The reciprocal of the first interval is: [0.5, 0.125]
                      >
                      this is my prog
                      >
                      #include<iostre am>
                      #include<string >
                      >
                      using namespace std;
                      >
                      class interval
                      {
                      int lower;
                      int upper;
                      >
                      public:
                      interval(int l, int u);
                      >
                      Do not forget the constructor.
                      >
                      void set(int,int)con st;
                      >
                      Not const, see below for explanation.
                      >
                      void get (int,int);
                      >
                      Will not work, see below.
                      >
                      void print();
                      >
                      void print() const;
                      >
                      void addtion(int,int ,int,int);
                      >
                      void add(const interval&) const;
                      >
                      void subtract(int,in t,int,int);
                      >
                      void subtract(const interval&) const;
                      >
                      void mutiplty(int,in t,int,int);
                      >
                      void multiply(const interval&) const;
                      >
                      void divide(int,int, int,int);
                      >
                      void divide(const interval&) const;
                      >
                      };
                      >
                      int main()
                      {
                      interval first,second;
                      >
                      Remove those, you (now) have a constructor, make sure to also use
                      it.
                      >
                      int l,u;
                      >
                      cout<<"Enter the lower and the upper limits of the first
                      interval";
                      >
                      cin >l >u;
                      >
                      interval first(l, u);
                      >
                      cout<<"["<<first.l<<"," <<first.u<<"]"<<endl;
                      first.set(l,u);
                      >
                      No! 1) they are called lower and upper, not l and u, 2) they are
                      private, you should never change them unless through the usage of
                      member
                      functions, 3) you should use print() to show their value.
                      Same goes for this the second one.
                      >
                      print();
                      >
                      print() is a member, you need an object to call it.
                      >
                      return 0;
                      }
                      >
                      interval::inter val(int l, int u)
                      {
                      // Insert code here, unless you know about initialisation lists
                      in
                      // which case you should use them.
                      >
                      }
                      void interval::set(i nt,int)const
                      >
                      Cannot use const here, it indicates that this function does not make
                      any
                      changes to the object, which is obviously does.
                      >
                      {
                      lower=l;
                      upper=u;
                      }
                      void interval::get(i nt,int)
                      >
                      No, this does not work, you need to pass them as references, or
                      return a
                      struct containing their values or make get_upper() and get_lower()
                      functions.
                      >
                      void interval::addti on(int,int,int, int)
                      >
                      You should pass another interval as parameters
                      >
                      void interval::addit ion(const interval&) const
                      >
                      { int add1,add2;
                      >
                      add1=first.l+se cond.l;
                      add2=first.u+se cond.u;
                      }
                      >
                      And you should use the constructor to create the new object.
                      The same goes for the rest of the functions.
                      >
                      void print();
                      >
                      void interval::print () const
                      >
                      {
                      cout<<"The sum of the two intervals is:
                      [ "<<add1<<","<<a dd2<<"]"<<endl;
                      cout<<"The subtraction of the two intervals is:
                      [ "<<sub1<<","<<s ub2<<"]"<<endl;
                      cout<<"The mutiplication of the two intervals is:
                      [ "<<mul1<<","<<m ul2<<"]"<<endl;
                      cout<<"The reciprocal of the first interval is:
                      [ "<<d1<<","<<d2< <"]"<<endl;
                      }
                      >
                      And what are add1 and add2? All those operations should be performed
                      in
                      main() and it should look something like
                      >
                      cout << "The sum of the two intervals is: ";
                      (first + second).print() ;
                      >
                      I hope you have much time left until you need to turn the assignment
                      in
                      because you have obviously not been paying attention during the
                      lessons
                      (or your instructor is *really* bad).
                      >
                      --
                      Erik Wikström- Hide quoted text -
                      >
                      - Show quoted text -
                      >
                      >
                      >
                      >
                      Erik thanks for helping me you are soo kind by the way my teacher is
                      not *really* bad i like him but maybe there is some thing wrong with
                      me loOol
                      >
                      ok now i understood your explaination but not everthing :"
                      can you show me example of how to use the constructor & when should
                      we
                      use it ? i believe it is used to assgin values to the members in
                      class ..
                      >
                      >
                      void interval::addit ion(const interval&) const
                      >
                      Constructors are used when you create a new object. When an object is
                      created a constructor will be run, if you have not declared any
                      constructors the compiler will create a default one for you. Often when
                      you create an object you know what values you want it to have, so you
                      can pass those to the constructor. To create an interval between 3 and
                      7
                      use the constructor like this:
                      >
                      interval myInterval(3,7) ;
                      >
                      This is much better (cleaner, more efficient, etc.) than the
                      alternative:
                      >
                      interval myInterval;
                      myInterval.set( 3,7);
                      >
                      --
                      Erik Wikström- Hide quoted text -
                      >
                      - Show quoted text -


                      this is my new prog. i hope it`s better now
                      you told that we shouldn`t put all these things in the function print
                      but i didn`t understand what should we do with it if we didn`t placed
                      it in print " what`s the benefit of print??"
                      is my constructor ok now?

                      sorry i don`t have the software at home to compile it so i can see my
                      mistakes.

                      #include<iostre am>
                      #include<string >

                      using namespace std;

                      class interval
                      {
                      public:
                      interval();
                      interval(int ,int );
                      void set(int,int);
                      void print() const;
                      void addittion(const interval&) const;
                      void subtract(const interval&) const;
                      void multiply(const interval&) const;
                      void divide(const interval&) const;
                      void set(int,int);
                      void get(int&,int&);
                      private:
                      int lower;
                      int upper;
                      };

                      int main()
                      {
                      interval interval1,
                      interval interval2(3,6),

                      cout<<"Enter the lower and the upper limits of the first interval";
                      cin>>lower>>upp er;
                      interval1.set(2 ,8)
                      cout<<endl;
                      cout<<"["<<lower<<","<< upper<<"]"<<endl;
                      >
                      The idea is that you should read in the values from the user, then pass
                      those values to the constructor so you do not have to use set(). Then
                      you will call print() which will do the job of the last line above.
                      >
                      By the way, are you sure you should use predefined values in the
                      intervals and not those read from the user?
                      >
                      interval::inter val()
                      {
                      lower=2
                      upper=8
                      }
                      >
                      Usually one would use something like 0,0 as default values, or the min
                      and max values of an integer.
                      And init lists:

                      interval::inter val() : lower(2), upper(8){}
                      >
                      interval::inter val(int lower, int upper)
                      {
                      lower=3;
                      upper=6;
                      }
                      >
                      Perhaps you should make some use of those parameters?
                      And since....
                      interval::inter val(int lower, int upper){
                      lower=lower;
                      upper=upper;
                      }
                      ..... is confusing(among other things), you should re-name the parms:

                      interval::inter val(int low, int upp){
                      lower=low;
                      upper=upp;
                      }

                      And use init list:

                      interval::inter val(int low, int upp) : lower(low), upper(upp){}

                      You (the OP), could combine the two constructors to one:

                      // interval::inter val() : lower(2), upper(8){}
                      interval::inter val( int low = 2, int upp = 8)
                      : lower(low), upper(upp){}

                      Since the constructor can now be invoked without parameters, it can be used
                      as the default constructor ( interval Ival; will work).
                      >
                      void interval::set(i nt,int)
                      {
                      lower=l;
                      upper=u;
                      }
                      You (the OP) forgot to name the parms:
                      void interval::set( int l, int u ){
                      lower=l;
                      upper=u;
                      }
                      void interval::get(i nt&,int&)const
                      {
                      lower=l;
                      upper=u;
                      }
                      >
                      Have you actually tried to compile your code? Where did l and u come from?
                      void interval::get( int &l, int &u ) const {
                      // lower=l;
                      // upper=u;
                      l = lower;
                      u = upper;
                      }

                      >
                      void interval::addit ion(int,int,int ,int)
                      >
                      Re-read my previous posts regarding the operations.
                      >
                      void print();
                      {
                      cout<<"The sum of the two intervals is:"<<"["<< add1 <<","<< add2
                      <<"]"<<endl;
                      cout<<"The subtraction of the two intervals is:"<<"["<< sub1
                      <<","<< sub2 <<"]";<<endl;
                      cout<<"The multiplication of the two intervals is:"<<"["<< mul1
                      <<","<< amul2 <<"]"<<endl;
                      cout<<"The reciprocal of the first interval is:"<<"["<< d1 <<","<<
                      d2 <<"]"<<endl;

                      }
                      >
                      Frankly I do not see much of a difference between this new code and the
                      original, besides two constructors which you then totally fail to make
                      use of in any meaningful way.
                      >
                      It is becoming more and more obvious that you have failed to understand
                      the most basic concepts of procedural programming like scope and
                      lifetime, until you learn those you can not advance to more advanced
                      topics like objects (which is a basic concept of object oriented
                      programming, what you are trying to do). I suggest that you start over
                      from chapter 1 and read carefully and do the exercises, or talk to your
                      lecturer about some private tutoring.
                      - -
                      Erik Wikström
                      >
                      >

                      For OP:

                      #include<iostre am>
                      #include<string >
                      // using namespace std;

                      class interval{ public:
                      interval( int low = 0, int upp = 0)
                      : lower( low ), upper( upp ){}
                      void set(int,int);
                      void print() const;
                      void addittion( interval const & ) const;
                      void subtract( interval const & ) const;
                      void multiply( interval const & ) const;
                      void divide( interval const & ) const;
                      void set( int const low, int const upp){
                      lower = low;
                      upper = upp;
                      return;
                      }
                      void get( int &low, int &upp )const{
                      low = lower;
                      upp = upper;
                      return;
                      }
                      private:
                      int lower;
                      int upper;
                      };


                      void print( std::ostream &out, interval const &in1, interval const &in2){
                      // using namespace std; // if you must
                      int low1(0), upp1(0), low2(0), upp2(0);
                      in1.get( low1, upp1 );
                      in2.get( low2, upp2 );
                      out<<"interval1 is:["<<low1<<","<<u pp1<<"]"<<std::end l;
                      out<<"interval2 is:["<<low2<<","<<u pp2<<"]"<<std::end l;
                      out<<"The sum of the two intervals is:["
                      << low1 + low2 <<","<< upp1 + upp2 <<"]"<<std::end l;
                      out<<"The subtraction of the two intervals is:["
                      << low1 - low2 <<","<< upp1 - upp2 <<"]"<<std::end l;
                      out<<"The multiplication of the two intervals is:["
                      << low1 * low2 <<","<< upp1 * upp2 <<"]"<<std::end l;
                      // etc....
                      return;
                      } // print(ostream&, interval const&,interval const&)


                      int main(){
                      // using namespace std; // if you must
                      interval interval2( 3, 6 );
                      std::cout<<"Ent er the lower and the upper limits of the first
                      interval";
                      int low(0), upp(0);
                      std::cin>>low>> upp;
                      // if( not low || not upp ){ return EXIT_FAILURE; }
                      interval interval1( low, upp );
                      std::cout<<endl ;
                      print( std::cout, interval1, interval2 );
                      return 0;
                      } // main()

                      [ un-tested. may need 'adjusting'. ]

                      Now, add in your other class member function definitions, *one-by-one*.
                      Test each time.
                      Then use those member functions in 'print(....)'. Write a 'print( interval
                      const &Ival2);' for your class, and test it. (hint: Ival1 will be the class
                      itself.)


                      I figure there must be a reason why posts are not being trimmed, so I
                      didn't.

                      --
                      Bob R
                      POVrookie


                      Comment

                      Working...