Expand|Select|Wrap|Line Numbers
- #include <cmath>
- #include <string>
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- using namespace std;
- class Coord
- { friend Coord ConvPolar(float&, float&);
- public:
- float xval;
- float yval;
- public:
- Coord(float=0.0, float=0.0);
- void fol_Car(float, float);
- };
- Coord::Coord (float x1, float y1)
- {
- xval=x1;
- yval=y1;
- }
- Coord ConvPolar(float& r, float& angle)
- {
- float xx,yy;
- xx= r * cos(angle);
- yy=r * sin(angle);
- Coord zz(xx,yy);
- return zz;
- }
- void getfunction(Coord contact[], ifstream &file)
- {
- int i = 0;
- string line;
- if (file.is_open())
- {
- while (! file.eof() )
- {
- //read line by line
- getline (file,line);
- getline (file,line);
- i = i+1;
- };
- for (int k = 0; k < i; k++)
- {
- cout << contact[k].xval << endl;
- cout << contact[k].yval << endl;
- }
- }
- }
- ;
- class PolarCoord
- { friend PolarCoord ConvPolar3(float&, float&);
- public:
- float dist;
- float theta;
- public:
- PolarCoord(float=0.0, float=0.0);
- void fol_Car(float, float);
- };
- PolarCoord::PolarCoord (float x3, float y3)
- {
- dist=x3;
- theta=y3;
- }
- PolarCoord ConvPolar3(float& newx, float& newy)
- {
- float r, theta;
- r= sqrt( newx*newx + newy*newy);
- theta=atan(newy/newx);
- PolarCoord jj(r,theta);
- return jj;
- };
- class RecCoord
- { friend RecCoord ConvPolar2(float&, float&);
- public:
- float xval2;
- float yval2;
- public:
- RecCoord(float=0.0, float=0.0);
- void fol_Car(float, float);
- };
- RecCoord::RecCoord (float x2, float y2)
- {
- xval2=x2;
- yval2=y2;
- }
- RecCoord ConvPolar2(float& newr, float& newtheta)
- {
- float x,y;
- x= newr * cos(newtheta);
- y=newr * sin(newtheta);
- RecCoord kk(x,y);
- return kk;
- };
- const double PI = 2.0 * asin(1.0);
- // class declaration
- class Point
- {
- public:
- float x;
- float y;
- public:
- Point(float = 0.0, float = 0.0); //constructor
- float distance(Point&);
- };
- // implementation section
- Point::Point(float xval4, float yval4)
- {
- x = xval4;
- y = yval4;
- }
- float Point::distance(Point& b)
- {
- float dd;
- dd= (sqrt(pow((x-b.x),2) + pow((y-b.y),2)));
- return dd;
- };
- // class declaration for the derived Circle class
- class Circle : public Point
- {
- public:
- double radius; // add an additional data member
- public:
- Circle(float = 0.0, float = 0.0, float = 1.0); // constructor
- float distance(Circle&);
- float area();
- };
- // implementation section for Circle
- Circle::Circle(float centerx, float centery, float r) // constructor
- {
- x = centerx;
- y = centery;
- radius = r;
- }
- float Circle::distance(Circle& b)
- {
- return (Point::distance(b)); // note the base function call
- }
- float Circle::area() // this calculates an area
- {
- return (PI * pow(radius,2));
- };
- int main()
- {
- string line;
- float r, angle, newx, newy, yval, dis,theta, newr, newtheta;
- Coord zz;
- RecCoord kk;
- PolarCoord jj;
- float dd;
- cout<< "Function 1\n";
- ifstream file("a8.txt");
- if (file.is_open())
- {
- while (! file.eof() )
- {
- getline (file,line);
- cout<<" Point a is initally at \n"<< line; // displays object a's value in rectangular coordinates.
- getline (file,line);
- cout<<","<<line;
- cout<<" \nEnter a new distance and angle for point a:";
- cin>>r>>angle;
- zz = ConvPolar(r, angle); //coversion from polar to rectangular
- cout<<" Point a is now located at"<< zz.xval<<","<< zz.yval<<endl; //displaying new value in rectangular coordinates.
- system("PAUSE");
- PolarCoord c;
- cout<<"\n function 2";
- ifstream file("a8.txt");
- if (file.is_open())
- {
- while (! file.eof() )
- {
- getline (file,line);
- getline (file,line) ;
- getline (file,line);
- getline (file,line);
- cout<<"\n Rectangular point is initially located at"<<line;
- getline (file,line);
- cout<<","<<line;
- cout<<"\n Polar point b is initially located at "<<c.dist<<","<<c.theta;
- cout<< "\n Enter a new distance and angle for point b:";
- cin>>newr>>newtheta;
- cout<<"\n Polar point b is now located at:" <<newr<<" ," <<newtheta<<"\n";
- kk = ConvPolar2(newr, newtheta);
- cout<<"\n After conversion point a is now located at"<<kk.xval2<<","<<kk.yval2;
- cout<<"\n Enter a new x and y value for point a:";
- cin>>newx>>newy;
- cout<<"\n Rectangular point a is now located at "<<newx<<","<<newy;
- jj = ConvPolar3(newx, newy);
- cout<<"\n After conversion, point b is now located at"<<jj.dist<<","<<jj.theta<<endl;
- system("PAUSE");
- Circle area;
- Circle distance;
- float x, y,r;
- Point b;
- cout<<"\n function 3";
- ifstream file("a8.txt");
- if (file.is_open())
- {
- while (! file.eof() )
- {
- getline (file,line);
- getline (file,line) ;
- getline (file,line);
- getline (file,line);
- getline (file,line) ;
- getline (file,line);
- getline (file,line);
- cout<<"\nThe poinrs are "<<line;
- b.x=atof(line.c_str());
- getline (file,line);
- cout<<", "<<line;
- x=atof(line.c_str());
- getline (file,line);
- cout<<", "<<line;
- b.y=atof(line.c_str());
- getline (file,line);
- cout<<", "<<line;
- y=atof(line.c_str());
- cout<<" The distance between these points is "<<dd<<endl;
- r=b.x;
- cout<< "\n The area of circle 1 is"<<area.radius;
- cout<<"\n The area of circle 2 is "<<area.radius;
- cout<<"\n The distance between circle centers is"<<distance.area();
- system("PAUSE");
- return EXIT_SUCCESS; // exits the program
- }
- }
- }
- }
- }
- }
- }