PDA

View Full Version : Maths Tools



A G E N T
02-28-2008, 02:41 AM
Well, my rtard of a maths teacher (I won't get into that now) likes to assign a lot of the same-ish questions, over and over. The flavour of this week is apparently finding the y-intercept of a linear relation given the slope and a point that lies on the line.

Maybe in future versions I'll have different permutations, such as slope and y-intercept given two points, or points given slope and a y-intercept.

Enjoy, rate/hate.


program New;

var
Slopem, InputSlope : string;
TheSlope, xBym, XVal, YVal, InvX, LeftSide, YInt, Num, Denom : extended;

Equation : string;
Rational, Negative : boolean;

procedure CalculateInput;
begin
XVal := StrToFloat(Readln('X coordinate?')); //StrToFloat(LabeledEdit1.text);
YVal := StrToFloat(Readln('Y coordinate?')); //StrToFloat(LabeledEdit2.text);
InputSlope := Readln('Slope? (write rational numbers as a/b'); //Slope.text;
end;

procedure DoIt;
var
XVal2,YVal2 : extended;
begin
CalculateInput;
Equation := 'y = '+InputSlope+' x + b';
//writeln(replace(Equation,' ',''));
Equation := replace(Equation,' ','');
slopem := copy(Equation,pos('=',Equation)+1,(Pos('x',Equatio n) - Pos('=',Equation))-1);
//Writeln(Slopem);
if(Pos('/',Slopem) > 0) then Rational := True;
if(not Rational) then
begin
//Writeln(Slopem);
TheSlope := StrToFloat(Slopem);
xBym := XVal * TheSlope;
//Writeln(FloatToStr(xBym));
InvX := xBym * -1;
//Writeln(FloatToStr(InvX));
LeftSide := YVal + InvX;
//Memo1.lines.add('The line with slope '+slopem+' and with the point ('+FloatToStr(XVal)+','+FloatToStr(YVal)+') has a y-intercept of '+FloatToStr(LeftSide)+'.');
GetApplication.MessageBox('The line with slope '+slopem+' and with the point ('+FloatToStr(XVal)+','+FloatToStr(YVal)+') has a y-intercept of '+FloatToStr(LeftSide)+'.','Result',1);
end else
begin
Num := StrToFloat(Copy(Slopem,0,Pos('/',Slopem)-1));
Denom := StrToFloat(Copy(Slopem,Pos('/',Slopem)+1,1));
YVal2 := YVal * Denom;
XVal2 := XVal * Denom;
xBym := XVal * Num;
InvX := xBym * -1;
LeftSide := YVal + InvX;
YInt := LeftSide * Num;
//Writeln(FloatToStr(YInt));
GetApplication.MessageBox('The line with slope '+slopem+' and with the point ('+FloatToStr(XVal)+','+FloatToStr(YVal)+') has a y-intercept of '+FloatToStr(LeftSide)+'.','Result',1);
end;
end;

begin
DoIt;
end.

Harry
02-28-2008, 02:49 AM
Are you in my Math class? I am learning about like the same thing right now...
Weird o_O...

Nice job anyways, maybe you should print the script out and show to her, get some extra credit :p