Thread: help on this very small practice program

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    help on this very small practice program

    /*Ok first of all I just want to tell you that by this you're not doing my homework, because I am learning on my own right now.....This is just from a book that I am reading....and I decided to do something extra */
    //Listing 10.1 Overloading class member functions

    #include <iostream>

    // Rectangle class declaration
    class Rectangle
    {
    public:
    // constructors
    Rectangle(int width, int height);
    ~Rectangle(){}

    // overloaded class function DrawShape
    void DrawShape() const;
    void DrawShape(int aWidth, int aHeight) const;

    private:
    int itsWidth;
    int itsHeight;
    };

    //Constructor implementation
    Rectangle::Rectangle(int width, int height)
    {
    itsWidth = width;
    itsHeight = height;
    }


    // Overloaded DrawShape - takes no values
    // Draws based on current class member values
    void Rectangle:rawShape() const
    {
    DrawShape( itsWidth, itsHeight);
    }


    // overloaded DrawShape - takes two values
    // draws shape based on the parameters
    void Rectangle:rawShape(int width, int height) const
    {
    for (int i = 0; i<height; i++)
    {
    for (int j = 0; j< width; j++)
    {
    std::cout << "*";
    }
    std::cout << "\n";
    }
    }

    // Driver program to demonstrate overloaded functions
    int main()
    {
    // initialize a rectangle to 30,5
    Rectangle theRect(30,5);
    std::cout << "DrawShape(): \n";
    theRect.DrawShape();
    std::cout << "\nDrawShape(40,2): \n";
    theRect.DrawShape(40,2);
    return 0;
    }

    /* I want to creat a member method that takes in one pararemeter either width or height.... so then I can overload drawshape, and then getting the other missing argument by means of using enum, please help...........*/


    PS THIS IS NOT MY HOMEWORK....using Sams Teach Yourself C++ in 21 days.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    bump
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    My recommendation is to leave that book completely. I was doing the same thing that you are doing only to find out that I had missed a lot of key information that it missed. Therefore, I had to start all over using a different book. Goto this site:

    http://www.syndik.at/harald/regal/buecher/login_e.asp

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    By the way, DO NOT BUMP

  5. #5
    Unregistered
    Guest
    int width;
    int height;
    int choice:
    int continue = 1;

    srand(time(NULL));

    while(continue != 0)
    {
    cout << "do you wish to enter" << endl;
    cout << "1)width or " << endl;
    cout << "2) height " << endl;
    cin >> choice;
    //data validate here
    switch (choice)
    {
    case 1:
    cout << "after you enter the value for width the computer will generate a random value for height" << endl;
    cin >> width;
    height = (rand() % 3) + 1;//use enum here instead if you wish
    DrawShape(width, height);
    case 2:
    //similar for width
    default:
    //etc.
    }
    cout << "to stop enter zero' << endl;}
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. Please Help with small program
    By cjohnman in forum C Programming
    Replies: 11
    Last Post: 04-14-2008, 09:59 AM
  3. A little Help with a small program
    By whtpirate in forum C Programming
    Replies: 7
    Last Post: 06-05-2003, 06:15 PM
  4. Very small program...Whats wrong???
    By SmokingMonkey in forum C++ Programming
    Replies: 4
    Last Post: 05-30-2003, 09:09 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM