I just need to add the actual line. wintard.
#include <iostream>
#include <math.h>
using namespace std;
double distance(double pa[2], double pb[2]){
double result = sqrt((pow(pb[0]-pa[0], 2)+pow(pb[1]-pa[1], 2)));
return result;
}
double gradient(double pa[2], double pb[2]){
double result = (pa[1]-pb[1])/(pa[0]-pb[1]);
return result;
}
double midpoint(double pa, double pb){
double result = (pa+pb)/2;
return result;
}
int main(){
double pointa[2], pointb[2];
cout << "Graphical Math calculator"<< endl<<"Enter 2 co-ordinates: "<<endl<<" 1st:\nX:";
cin>>pointa[0]; cin.ignore(0); cout<<"Y:"; cin>>pointa[1]; cout<<"\n 2nd:\nX:";
cin>>pointb[0]; cout<<"Y:"; cin>>pointb[1]; cout<<"\n";
for(int a=1; a<21; a++){
for(int b=1; b<21; b++){
if((pointa[0]==21-a && pointa[1]==b)){
cout<<"AA";
} else if((pointb[0]==21-a && pointb[1]==b)){
cout<<"BB";
} else {
cout<<"--";
}
}
if(a==2){
cout<<" AA: ("<<pointa[0]<<","<<pointa[1]<<")"<<en dl;
} else if(a==3){
cout<<" BB: ("<<pointb[0]<<","<<pointb[1]<<")"<<en dl;
} else if(a==9){
cout<<" Distance: "<<distance(pointa, pointb)<<endl;
} else if(a==10){
cout<<" Gradient: "<<gradient(pointa, pointb)<<endl;
} else if(a==11){
cout<<" Midpoint: ("<<midpoint(pointa[0], pointb[0])<<", "<<midpoint(pointa[1], pointb[1])<<")"<<endl;
} else {
cout<<endl;
}
}
return 0;
}
FatKidWitAJetPak
What does it do?
liam
My trig homework >_> Calculates gradient, midpoint and distance. Plus it draws a small graph which shows where the 2 points lie in physical space :P That code I posted is kinda wrong though, it prints the points out in the wrong places, but, I fixed it, Idc =D