qpMONKEYMIKEqp's Profile User Rating: -----

Reputation: -1 Dishonored
Group:
Members
Active Posts:
25 (0.03 per day)
Joined:
16-October 12
Profile Views:
269
Last Active:
User is offline Oct 09 2013 11:01 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   qpMONKEYMIKEqp has not set their status

Posts I've Made

  1. In Topic: C++ Operator<< Override inheritance

    Posted 9 Oct 2013

    I have figured it out now! With your help!

    I moved the operator<< into public and then my compiler was giving me some error about constants. So I took const out of the operator<< and changed it all from info.Variable to info.getVariable. This let me compile with no errors and get the product i was looking for.

    Once again thank you all for the help. I love that the people here give me hits to the correct answers instead of just taking my code fixing it and pasting it into the chat!

    My changed code is:

    Circle.h

    
    #ifndef Ch2HW_MichaelRauch_Circle_h
    #define Ch2HW_MichaelRauch_Circle_h
    
    #include <iostream>
    #include "Point.h"
    
    using namespace std;
    
    class Circle: public Point
    {
    public:
        
        friend ostream& operator<< (ostream&, const Circle&);
        friend ostream& operator<< (ostream&, const Point&);
        //Construtor
        Circle(double x, double y, double rad)
        {
            radius = rad; //Store the radius of the circle
            setX(x); //Stores the xCoordinate
            setY(y); //Stores the yCoordinate
        }
        
        double getRadius()
        {
            return radius;
        }
        
    private:
        double radius; //Variable to define radius
    };
    
    ostream& operator<<(ostream& osObject, Circle& info)
    {
        osObject << "(";                        
        osObject << info.getX();
        osObject << ",";                        
        osObject << info.getY();
        osObject << ",";                        
        osObject << info.getRadius();
        osObject << ")";                        
        
        return osObject;    //return osObject which contains "(x,y)"
    }
    
    
    #endif
    
    
    


    Point.h

    
    #ifndef Ch2HW_MichaelRauch_Point_h
    #define Ch2HW_MichaelRauch_Point_h
    
    #include <iostream>
    
    using namespace std;
    
    class Point
    {
    public:
        //Overload << operator
        friend ostream& operator<< (ostream&, const Point&);
        
            //Construtor
        Point(double x = 0, double y = 0)
        {
            xCoordinate = x; //Store the X value of the coordinate
            yCoordinate = y; //Store the Y value of the coordinate
        }
            
            //Function to set the y coordinate
        void setY(double y = 0)
        {
            yCoordinate = y; //Store new y value of the coordinate
        }
        
            //Function to set the x coordinate
        void setX(double x = 0)
        {
            xCoordinate = x; //Store new x value of the coordinate
        }
        
            //Function to get the y coordinate
        double getY()
        {
            return yCoordinate; //return the y value of the coordinate
        }
        
            //Function to get the x coordinate
        double getX()
        {
            return xCoordinate; //return the x value of the coordinate
        }
        
    private:
        double xCoordinate; //Variable to define x coordinate
        double yCoordinate; //Variable to define y coordinate
    };
    
        //Make << output "(x,y)"
    ostream& operator<<(ostream& osObject, const Point& coordinate)
    {
        osObject << "(";                        //Current output "("
        osObject << coordinate.xCoordinate;     //Current output "(x"
        osObject << ",";                        //Current output "(x,"
        osObject << coordinate.yCoordinate;     //Current output "(x,y"
        osObject << ")";                        //Current output "(x,y)"
        
        return osObject;    //return osObject which contains "(x,y)"
    }
    
    #endif
    
    
    
  2. In Topic: C++ Operator<< Override inheritance

    Posted 9 Oct 2013

    Where should i look or what can i try to get the output i want? I tried just creating another operator<< override in circle.h but if i do that i can not the the x and yCoordinate from the Point.h?

    I can get the radius from the class Circle. but i can not get the x and yCoordinates form the Point class. But the Circle class can get x and y from Point class....

    i tried using << Point:xCoordinate and << getX(). Nothing seems to be going my way.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

qpMONKEYMIKEqp hasn't added any friends yet.

Comments

qpMONKEYMIKEqp has no profile comments yet. Why not say hello?