Jump to content

object ,,,I need a help?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
Q-Girl

Q-Girl

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
I Know I am asking too much but i promise that I would help more in future I have this project and I have been ask to make this class ,, I don't Know how? can you help me with it ??

Quote

Create a class called “Rectangle” with attributes length and width, each of which
defaults to 1. Provide member functions that calculate the perimeter and area of the
rectangle. Also, provide set and get functions for the length and width attributes.
The set function should verify that both length and width values are larger than 0
and less than 20. Eventually, include a function square that determines whether the
rectangle is a square

can you Explain to me what I can Do ??:confused:

#2
speculatius

speculatius

    Newbie

  • Members
  • PipPip
  • 25 posts
Hello again :)

try to read some tutorial about C++. You need only basics:

1. creating class
2. define constructor
3. create some methods

This link will help you (I am not able to post regular links, so please remove dollars from link and paste it into browser):
w$w$w.cplusplus.com/doc/tutorial/classes/

#3
Q-Girl

Q-Girl

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
thank you very much I will go there ,,

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Note: your class will have 2 member variables, 7 methods, and a constructor.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
I'd have two constructors. One with set values and one with default values, and a private init method so you DRY.

class Rectangle
{
public:
    Rectangle(int w, int h)
    {
        init(w, h);
    }
    Rectangle()
    {
        init(1, 1);
    }

// Other methods here...

private:
    int width, height;

    void init(int w, int h)
    {
        width = w;
        height = h;
    }
};

Wow I changed my sig!

#6
dragon_kcn

dragon_kcn

    Newbie

  • Members
  • PipPip
  • 21 posts
Hi Q-Girl.
I can give you some frames.

class Rectangle{

private:

  int nWidth, nHeight; //member variables

public:

  Rectangle(){ //default constructor

    Rectangle(1, 1);

  }

  Rectangle(int w, int h){ //constructor with parameters

    nWidth  = w;

    nHeight = h;

  }

  int getPeriMeter(){

    // here should be inserted the calculating source code.   

  }

  int getArea(){

    // TODO ...

  }

  bool isSquare(){

    // TODO ...

  }

}

Finally you should write 2 functions, I mean the getter and setter on your own way.
Good luck.

Regards.
Cholnam Kim.

Edited by dragon_kcn, 08 December 2009 - 07:41 AM.
Resetting the styles.


#7
Q-Girl

Q-Girl

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
:rolleyes:

ZekeDragon said:

I'd have two constructors. One with set values and one with default values, and a private init method so you DRY.

class Rectangle

{

public:

    Rectangle(int w, int h)

    {

        init(w, h);

    }

    Rectangle()

    {

        init(1, 1);

    }


// Other methods here...


private:

    int width, height;


    void init(int w, int h)

    {

        width = w;

        height = h;

    }

};

^^
thank you I will try ang get back to you ,

#8
Q-Girl

Q-Girl

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts

dragon_kcn said:

Hi Q-Girl.
I can give you some frames.

class Rectangle{

private:

  int nWidth, nHeight; //member variables

public:

  Rectangle(){ //default constructor

    Rectangle(1, 1);

  }

  Rectangle(int w, int h){ //constructor with parameters

    nWidth  = w;

    nHeight = h;

  }

  int getPeriMeter(){

    // here should be inserted the calculating source code.   

  }

  int getArea(){

    // TODO ...

  }

  bool isSquare(){

    // TODO ...

  }

}

Finally you should write 2 functions, I mean the getter and setter on your own way.
Good luck.

Regards.
Cholnam Kim.

thank you very much I will study it and back to you with my thoughts and question ^^