Wednesday, January 7, 2009

A Rough Outline, A General Idea, and a Witty Title

So I set out to work on a program that would do my Algebra 2 homework for me.
Convenient, no?
My goal was to design a program that would take the terms of a difference of squares. (Such as "w3-27")

The program would take the root of the terms. In this case "w" and "3" (So you're still doing a little bit of calculation) and re-arrange them into the formula of
(a-b) - (a2+ab+b2)

It would save me time.

So I hashed out a quick skeleton during my Algebra class (instead of actually paying attention, in hopes that I could do the work myself). I got home, fixed it up, and came out with a rough piece of work that takes two variables and spits them back out in slightly different order:

Here's the source:

# include < iostream >
using namespace std;


char a; //sets the variable in the expression
int b; // sets the variable for the second term
int a2; // stands for a squared in formula
int b2; // stands for b squared in formula



int main()
{

cout << "What is A? \n";
cin >> a;
cout << "What is B? \n";
cin >> b;
cout << "("<< a <<"-"<< b <<")-("<< a <<"squared + "<< b <<"" << a << " + " << b <<
<< "squared)\n";
cin.get();
}


So it's not very pretty, but it gets the job done.


Problems and Solutions and Improvements
1) You still have to do the initial calculation of the roots. Easy fix. I'll just have it divide variable B by 3 two times.
2) If the first term has both a coefficient and a variable, I have to be able to enter the coefficient. That's simple enough. I can treat the coefficient separately, divide that by 3 twice.
3) The program won't take or give out superscript. I can't quite get it to print out superscript. I'll have to look into that. Plus, you still have to do a little thinking, and remove the exponent from the original "a" term. I'm not sure how to fix my superscript problem, honestly.
4) The program doesn't simplify it totally. So if you end up with an answer that isn't fully simplified. that fix might be slightly more complicated. However, I suppose I could set it to test whether or not b2 is divisible by anything that adds up to ab. I'll have to work on this, without a doubt. That might be a little tricky. But essentially it'll come down to an if/else function.

I feel slightly bad about posting unfinished/rough code here, but I suppose it's a good way to organize my thoughts, and show how I progress throughout a project. The code works, does what it's supposed to do. It's just not comprehensive enough. Expect to see more as I work on it.

I am excited though, because this is the first semi-major, semi-useful project I have really attempted with any sort of code or computer knowledge.

Over and Out.

No comments:

Post a Comment