00:00
00:00
View Profile liam
"I put on my robe and wizard hat.."

29, Male

Student

NaN

Leeds

Joined on 12/11/04

Level:
22
Exp Points:
4,950 / 5,380
Exp Rank:
6,367
Vote Power:
6.34 votes
Rank:
Police Officer
Global Rank:
11,488
Blams:
556
Saves:
251
B/P Bonus:
10%
Whistle:
Bronze
Medals:
222
Gear:
2

Best C++ program EVER

Posted by liam - October 3rd, 2008


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;
}


Comments (1)

What does it do?

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