![]() |
| | #1 | |
| Registered User Join Date: Apr 2008
Posts: 1
| Help realy needed Quote:
Code: Enter filename: Midpoint Coordinates: 3.500, 4.500, 5.500 The distance is 12.450 Point Coordinates: 1.000, 1.000, 1.000 Point Coordinates: 6.000, 8.000, 10.000 Code: Enter Filename: Midpoint coordinates: 1.000, 1.000, 1.000 The distance is: 0.000 Point A: 1.000, 1.000, 1.000 Point B: 1.000, 1.000, 1.000 my code is as follows: point.h Code: #ifndef POINT_H_
#define POINT_H_
class Point
{
public:
void setx(double);
void sety(double);
void setz(double);
double getx();
double gety();
double getz();
double getDistance(Point&);
Point midpoint(Point&);
bool displayPoint();
Point();
Point(double, double, double);
~Point();
private:
double x;
double y;
double z;
};
#endif
Code: #include "Point.h"
#include <cmath>
#include <iostream>
using namespace std;
Point::Point() {
x = 0;
y = 0;
z = 0;
}
Point::Point(double pX, double pY, double pZ) {
x = pX;
y = pY;
z = pZ;
}
Point::~Point() {
}
void Point::setx(double pX) {
x = pX;
}
void Point::sety(double pY) {
y = pY;
}
void Point::setz(double pZ) {
z = pZ;
}
double Point::getx() {
return x;
}
double Point::gety() {
return y;
}
double Point::getz() {
return z;
}
double Point::getDistance(Point& otherPoint) {
double oX = otherPoint.getx();
double oY = otherPoint.gety();
double oZ = otherPoint.getz();
double dX,dY,dZ;
dX = pow((x - oX),2);
dY = pow((y - oY),2);
dZ = pow((z - oZ),2);
return sqrt((dX + dY + dZ));
}
Point Point::midpoint(Point& otherPoint) {
double oX = otherPoint.getx();
double oY = otherPoint.gety();
double oZ = otherPoint.getz();
double mX,mY,mZ;
mX = ((getx() + oX) / 2.0);
mY = ((gety() + oY) / 2.0);
mZ = ((getz() + oZ) / 2.0);
Point returnPoint;
returnPoint.setx(mX);
returnPoint.sety(mY);
returnPoint.setz(mZ);
return returnPoint;
}
bool Point::displayPoint() {
std::cout << x << ", " << y << ", " << z << endl;
return 1;
}
Code: #include <cstdlib>
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include "Point.h"
using namespace std;
int main ()
{
char filename[100];
double x,y,z;
ifstream inFile;
cout << "Enter Filename: ";
cin >> filename;
inFile.open(filename);
inFile >> x >> y >> z;
Point a(x,y,x);
Point b(x,y,z);
Point m;
cout << fixed << showpoint << setprecision(3);
m = a.midpoint(b);
cout << "Midpoint coordinates: " << m.getx() << ", " << m.gety() << ", " << m.getz() << endl;
cout << "The distance is: " << a.getDistance(b) << endl;
cout << "Point A: "; a.displayPoint();
cout << "Point B: " << b.getx() << ", " << b.gety() << ", " << b.getz() << endl;
inFile.close();
return 0;
}
Last edited by CornedBee; 04-08-2008 at 02:29 AM. Reason: Preserve forum layout. | |
| ZohebN is offline | |
| | #2 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,676
| Perhaps Code: inFile >> x >> y >> z;
Point a(x,y,x);
inFile >> x >> y >> z;
Point b(x,y,z);
|
| Salem is offline | |
| | #3 |
| Registered User Join Date: Jan 2005
Posts: 7,251
| And: Code: Point a(x,y,z); |
| Daved is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| free needed or not? | quantt | Linux Programming | 3 | 06-25-2009 09:32 AM |
| C Programmers needed for Direct Hire positions | canefan | Projects and Job Recruitment | 0 | 09-24-2008 11:55 AM |
| Battleship Game (Win32 EXP Needed) | ElWhapo | Projects and Job Recruitment | 2 | 01-15-2005 10:10 PM |
| C++ help needed | Enkindu | Projects and Job Recruitment | 3 | 08-31-2004 11:24 PM |
| Using pointers - asterisks needed ? | Nutshell | C Programming | 5 | 01-28-2002 06:56 PM |