473,472 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Distance and Area

1 New Member
I want to retrieve my x1, x2, y1, and y2 from a text file using getline, but i don't know how.



Expand|Select|Wrap|Line Numbers
  1. const double PI = 2.0 * asin(1.0);
  2.  
  3. // class declaration
  4. class Point
  5. {
  6.   protected:
  7.     float x;
  8.     float y;
  9.   public:
  10.     Point(float = 0.0, float = 0.0);  //constructor
  11.     float distance(Point&);
  12.     float area();
  13. };
  14.  
  15. // implementation section
  16. Point::Point(float xval, float yval)
  17. {
  18.   x = xval;
  19.   y = yval;
  20. }
  21.  
  22. float Point::distance(Point& b)
  23. {
  24.   return (sqrt(pow((x-b.x),2) + pow((y-b.y),2)));
  25. }
  26.  
  27. float Point::area()
  28. {
  29.   return 0;
  30. }
  31.  
  32. // class declaration for the derived Circle class
  33. class Circle : public Point
  34. {
  35.   protected:
  36.     double radius; // add an additional data member
  37.   public:
  38.     Circle(float = 0.0, float = 0.0, float = 1.0);  // constructor
  39.     float distance(Circle&);
  40.     float area();
  41. };
  42.  
  43. // implementation section for Circle
  44. Circle::Circle(float centerx, float centery, float r)  // constructor
  45. {
  46.   x = centerx;
  47.   y = centery;
  48.   radius = r;
  49. }
  50.  
  51. float Circle::distance(Circle& b)
  52. {
  53.    return (Point::distance(b)); // note the base function call
  54. }
  55.  
  56. float Circle::area()   // this calculates an area
  57. {
  58.   return (PI * pow(radius,2));
  59. };
  60.  
  61. int main()
  62. string line;
  63. ifstream file("a8,txt");
  64. if (file.is_open())
  65. {
  66. while(!file.eof())
  67. {
  68. getline(file,line);
  69.  
  70. cout <<"the points are" << line;
Nov 28 '07 #1
1 1601
Ganon11
3,652 Recognized Expert Specialist
If you have an ifstream, you can say:

Expand|Select|Wrap|Line Numbers
  1. file >> val1 >> val2;
instead of using getline. This is much easier.

If you insist on using getline, you will have to input to a string variable (recommended: std::string), and then break that string up into separate parts to get the different numbers.
Nov 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

20
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...
7
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...
4
by: Pf | last post by:
A piece of html code: <table> <tr> <td> <input type="text" name="myInput" onclick="myFunction(this)"> <td> </tr> </table>
9
by: Sandy | last post by:
Hello - I need either a cheap tool or code & DB that calculates, eg. within 50-mile radius of a zip code. Anyone have any suggestions? -- Sandy
4
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...
10
by: Alan Johnson | last post by:
24.1.1.3 says about InputIterators: Algorithms on input iterators should never attempt to pass through the same iterator twice. They should be single pass algorithms. In 24.3.4.4 summarizes the...
9
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...
1
by: tiffrobe | last post by:
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. ...
11
by: devnew | last post by:
hello while trying to write a function that processes some numpy arrays and calculate euclidean distance ,i ended up with this code (though i used numpy ,i believe my problem has more to do with...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.