1 Replies - 675 Views - Last Post: 23 October 2013 - 09:03 PM Rate Topic: -----

#1 Rbroke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 23-October 13

reference to Point.h file in .cpp file

Posted 23 October 2013 - 05:30 PM

In the program we have to create 5 header files and one cpp file. The header files are FigureGeometry, Point, Circle, Square and Rectangle. In the cpp file we have to reference the point file to calculate the square and circle. Also have to set the side length of the square to 5 and the width of 5 and a height of 7 on the rectangle. Having problems referencing the header files, has been a long time since doing anything with C++. Circle works fine but need help with the .cpp file to reference the Point.h file and set the requested parameters. Here is the Point.h, Square.h and cpp file code. Header files are per instructor directions. The TestAll class purpose is to implement a main method which creates three objects -- a Circle object, a Square object, and a Rectangle object. Any help is appreciated. thanks!


Point.h
  
#ifndef POINT_H  
#define POINT_H  
  
#include<iostream>  
 

using namespace std;  


  

 class Point  

 {  

 private:  

     int width; //stores the width of a Point object
     int height; //stores the height of a Point object

 public:  

     Point(){  

         width = 0;  
         height = 0;  
     }  

     Point(int theWidth, int theHeight){  

         width = theWidth;  
         height = theHeight;  
     }  

     int getWidth() const{  
         return width;  
     }  

     int getHeight()const{  
         return height;  
     }  

     void setWidth(int theWidth){  
         width = theWidth;  
     }  

     void setHeight(int theHeight)  {  
         height = theHeight;  
     }  

 };  

    
 #endif 





Square.h

#ifndef SQUARE_H
#define SQUARE_H

#include<iostream>
#include<iomanip>
#include<string>
#include "Point.h"
#include "FigureGeometry.h"



using namespace std;


 class Square

 {

 private:

     Point point;

 public:

     Square(){;}

     Square(Point p1)

     {

         point = p1;

     }

     ~Square(){;}

     int getSideLength(){
         return point.getWidth();
	 }

     float getArea(){
         return getSideLength() * getSideLength();
	 }

     float getPerimeter(){
         return getSideLength() * 4;
     }

     void setPoint(Point p1){
         point = p1;

     }


 };
#endif





Testall.cpp

#include <iostream>
#include <iomanip>
#include <string>
#include "Circle.h"
#include "Rectangle.h"
#include "Square.h"
#include "Point.h"
#include "FigureGeometry.h"



using namespace std;
 


 
void main()
{  

	
	
	Circle* c1 = new Circle(5.0f);  //Creates instance of circle c1 with radius of 5
	cout << "Details of c1:" << endl;
	cout << "radius: "<< c1->getRadius()<<endl;
	cout << "area: " << c1->getArea() << endl;
	cout << "perimeter: " << c1->getPerimeter() << endl;
	cout << "     "<< endl;

	Square s1;
	s1.setPoint();
	Square Point;
	//Point.setWidth(5); 	
        cout << "Details of s1:" << endl;
	cout << "side length: "<< s1->getSideLength() <<endl;
	cout << "area: " << s1->getArea() << endl;
	cout << "perimeter:" << s1->getPerimeter() << endl;
	cout << "     "<< endl;
 
  }
};




Is This A Good Question/Topic? 0
  • +

Replies To: reference to Point.h file in .cpp file

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3553
  • View blog
  • Posts: 11,014
  • Joined: 05-May 12

Re: reference to Point.h file in .cpp file

Posted 23 October 2013 - 09:03 PM

View PostRbroke, on 23 October 2013 - 08:30 PM, said:

Having problems referencing the header files, has been a long time since doing anything with C++.


What exactly is your problem? Are you getting a compiler error? Did you forget where you placed the file?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1