All pastes #902142 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-02-13 05:28 UTC
rendered paste body
#include "stdafx.h"  //studio refuses to compile without this header file

#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;
class line
{
private:
	float A,B,C;
public:
	void GetValues(float a, float b, float c, float d)
	{
		A=d-b;
		B=a-c;
		C=(b*c)-(a*d);
	}
	float slope()
	{
		float slope = (-A/B);
		return slope;
	}
	float midpointx(float a, float c)
	{
		float midpoint = (a+c)/2;
		return midpoint;
	}
	float midpointy(float b, float d)
	{
		float midpoint = (b+d)/2;
		return midpoint;
	}
	float inputpoint()
	{
		float point;
		cout<<"Please input the x coordinate of the first point: ";
		cin>>point;
		return point;
	}
	float getA(){return A;}
	float getB(){return B;}
	float getC(){return C;}
};

void main()
{
	line geometry;
	float a=NULL;
	float b=NULL;
	float c=NULL;
	float d=NULL;
	while(a == NULL)
	{
		a=geometry.inputpoint();
		if (!cin.good())
		{
			cout<<"Please make a numerical input."<<endl;
			a=NULL;
		}
	}
	while(b == NULL)
	{
		cout<<"Please input the y coordinate of the first point: ";
		cin>>b;
		if (!cin.good())
		{
			cout<<"Please make a numerical input."<<endl;
			b=NULL;
		}
	}
	while(c == NULL)
	{
		cout<<"Please input the x coordinate of the second point: ";
		cin>>c;
		if (!cin.good())
		{
			cout<<"Please make a numerical input."<<endl;
			c=NULL;
		}
	}
	while(d == NULL)
	{
		cout<<"Please input the y coordinate of the second point: ";
		cin>>d;
		if (!cin.good())
		{
			cout<<"Please make a numerical input."<<endl;
			d=NULL;
		}
	}
	geometry.GetValues(a,b,c,d);
	cout<<"The general formula for the line is: "<<geometry.getA()<<"x + "<<geometry.getB()<<"y + "<<geometry.getC()<<" = 0"<<endl;
	cout<<"The slope of the line is: "<<geometry.slope()<<endl;
	cout<<"The midpoint for the line is: ("<<geometry.midpointx(a,c)<<", "<<geometry.midpointy(b,d)<<")"<<endl;
	system("PAUSE");
}