I'm a little lost on my program. Everything works fine except function 3. It gives out garbage numbers. Its suppose to give the distance between two points and then the area of 2 circles. -
-
#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
-
}
-
}
-
}
-
}
-
}
-
}
-
}
-
1 4064
Hi,
1.You haven't assigned any value to float variable 'dd' in int main().
2.The function, area.radius() accepts void and returns float. Parantheses missing. Also, assign another float variable, say, area to area.radius(). Print area.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Xenophobe |
last post by:
I have successfully converted the ASP code included in the following article
to PHP:
http://www.4guysfromrolla.com/webtech/040100-1.shtml
As described the high and low latitudes and longitudes are pre-calculated
and passed to the query.
SELECT *
FROM Locations
|
by: csumner |
last post by:
I am trying to use the haversine function to find the distance between
two points on a sphere, specifically two zip codes in my database. I'm
neither horribly familiar with SQL syntax nor math equations :), so I
was hoping I could get some help. Below is what I'm using and it is,
as best as I can figure, the correct formula. It is not however,
giving me correct results. Some are close, others don't seem right at
all. Any ideas?
SET...
|
by: DellaCroce |
last post by:
Does anyone here have the formula for calculating distance give two pairs of
Longitude/Latitude coordinates? Please share this with me if you would.
--
Greg
|
by: Nick |
last post by:
hi, guys
I don't know where should I put this post, because this is a general
question, not really a c# question.
The question is how to caculate the real distance between two
geographical point? For example, i know two positions from my gps,
longitude and latitude. how to know to caculate how many miles between
these two points.
There are many websites doing this in search, enter the miles as
radius, and only show the results fall in...
|
by: byteschreck |
last post by:
Is it possible to change the distance from the form's border the form
designer suggests when you use snaplines?
I think it should be smaller.
| |
by: giloosh |
last post by:
how would i get the distance and angle between 2 points on the screen.
For example:
what is the distance between (100,50) and (250,70)
what i really wanna do is see how far the current mouse position is
from a given object and what the angle is between them.
Any help please?
Thanks,
Gil
|
by: nottheartistinquestion |
last post by:
As an intellectual exercise, I've implemented an STL-esque List<and
List<>::Iterator. Now, I would like a signed distance between two
iterators which corresponds to their relative position in the list.
For instance, if I did something like distance(list.end(),
list.begin()), I would get -list.size(). The STL's iterator distance
function amounts to something like this:
distance_type distance(Iterator first, Iterator last)
{...
|
by: ccaddiso |
last post by:
I want to retrieve my x1, x2, y1, and y2 from a text file using getline, but i don't know how.
const double PI = 2.0 * asin(1.0);
// class declaration
class Point
{
protected:
|
by: Tom P. |
last post by:
I am writing a drawing program but I want to keep the scale down
(there could end up being several hundred objects on the screen).
I want to limit the points collected to a certain distance from other
points already collected, in other words, if you're drawing a line it
will only record points on the line every 6 pixels. How do I determine
how far away one point is from another? if they are restricted to
straight lines that's fine but as...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |