Deriving one class from another

This is a discussion on Deriving one class from another within the C++ Programming forums, part of the General Programming Boards category; Ok, yeah, it's homework. Here's the deal, I need to make a class "point", perform operations on the point, like ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Location
    Oklahoma City
    Posts
    55

    Deriving one class from another

    Ok, yeah, it's homework. Here's the deal, I need to make a class "point", perform operations on the point, like showing the point, setting and printing coordinates, and showing x and y coordinates, then... design a class "circle" that can sotre radius and center and derive "circle" from "point" to perform operations on a circle, like setting radius, printing the radius, calculating and printing the area and circumference and such.

    Here is what I've done so far:

    circle.cpp
    Code:
    #include <iostream.h>
    #include <math.h>
    #include "Circle.h"
    
    void Circle :: read() {
        cout << "\nEnter radius of circle: ";
        cin >> radius;
        cout << "Enter center point of circle:";
        Point::read();
    }
    float Circle :: area() const {
        const float pii = 3.14159;
        return  pii * radius * radius;
    }
    void Circle :: I_am() const {
        cout << "\nI am Circle ";
    }
    Circle.h
    Code:
    #ifndef _circle
    #define _cicle
    #include "point.h"
    class Circle : public Point{
        private:
            float radius;
       public:
            void read();
            float area() const;
            virtual void I_am(void) const;
    };
    #endif
    point.cpp
    Code:
    #include <iostream.h>
    #include <math.h>
    #include "point.h"
    
    void Point::read() {
        cout << "\n Enter x-coordinate of point: ";
        cin >> x;
        cout << " Enter y-coordinate of point: ";
        cin >> y;
    }
    
    float Point :: area() const{
        return 0.0;
    }
    void Point :: I_am() const {
        cout << "\nI am Point ";
    }
    float Point::distance(const Point &p2)const{
        return sqrt( (p2.x-x)*(p2.x-x) + (p2.y - y)*(p2.y - y));
    
    }
    point.h
    Code:
    #ifndef _point
    #define _point
    #include "shape.h"
    class Point : public Shape {
        public:
          virtual void read();
          virtual float area() const;
          virtual float distance(const Point &p2)const;
          virtual void I_am() const;
        private:
          float x;
          float y;
    
    };
    #endif
    Then I wrote an abstract

    shape.h
    Code:
    #ifndef _shape
    #define _shape
    class Shape {
        public:
            virtual void read() = 0;
            virtual float area()const = 0 ;
          virtual void I_am() const = 0;
    };
    #endif
    Now, i'm getting an error:

    point.pp
    Cannot open include file: 'iostream.h': No such file or directory
    circle.cpp
    Cannot open include file: 'iostream.h': No such file or directory


    Any help is appreciated.
    Thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Get rid of the ".h". Chances are your compiler is newer than that old style of doing things.
    Code:
    #include <iostream>
    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    and on the math header too
    Code:
    #include<cmath>
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    former member Brain Cell's Avatar
    Join Date
    Feb 2004
    Posts
    472
    I've read a few times that the convention is to define your header files' constants as POINT_H instead _point for example.

    Correct me if i'm wrong because i'm not 100% sure of this.
    My Tutorials :
    - Bad programming practices in : C
    - C\C++ Tips
    (constrcutive criticism is very welcome)


    - Brain Cell

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    From 17.4.3.1.2
    - Each name that contains a double underscore (__) or begins with an underscore followed by an uppercase letter is reserved to the implementation for any use.

    Technically, _point is ok.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  2. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 02:09 PM
  3. Mmk, I give up, lets try your way. (Resource Management)
    By Shamino in forum Game Programming
    Replies: 31
    Last Post: 01-18-2006, 09:54 AM
  4. class errors
    By romeoz in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2003, 08:57 PM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21