خرید بک لینک

Vote count: -1

 //main()
  #include <iostream>
 #include "Circle.h"
 #define PI 3.1415965 //defining the pi number

 using namespace std;         //I want to create a class that has the characteristics of a circle

  int main()
 {
    Circle c1(1);   //making a class object
     cout<<c1;      //using the operator<< after overloading it 

       retu 0;
 }

   //circle.h
  #include <iostream>          //I'm just practicing with these things so my code will probably have some mistakes but I really caot understand where is the right place for the operator<< because I receive errors all the time
  using namespace std;


      class Circle    //creating the class circle
{
        public:
          Circle();                //constructor with zero members
          Circle(float r);         //constructor with one member
          float getPerimetre();      //getting the perimeter of the circle
          float getArea();          //getting the area of the circle
          friend ostream &operator<<(ostream &mystream, Circle &p);   //making the operator<<

        private:
          float radius;  //private members
};


     #endif // CIRCLE_H


     //circle.cpp
      #include "Circle.h"
     #include <iostream>
     #define PI 3.14159265   //defining the pi number

     using namespace std;

      Circle::Circle()    //creating the constructor with zero members
     {
         radius=0;   

     Circle::Circle(float r)    //creating the constructor with one member
     {
         radius=r;
      }
     float Circle::getPerimetre()    //explaining the functions  get perimetre
     {
         retu (2*PI*radius);
      }
     float Circle::getArea()  //and get area
      {
          retu (PI*radius*radius);
      }
      ostream &operator<<(ostream &mystream, Circle &p)  //i'm not sure if this is the right place to write this
      {
            mystream<<radius<<", "<<getPerimetre()<<", "<<getArea()<<endl;
            retu mystream;
      }

out from all the things that I've read I really caot understand where is the correct spot to write this operator and why I keep receiving errors when I run the project. I am new to this and also to this site so any help would be very apreciated

asked 55 secs ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 2 خرداد 1395 ساعت: 20:33

صفحه بندی