I have a homework assignment that requires the user to input two equations from the keyboard. The user can enter any letter of the alphabet but each equation can only have a total of 26 letters. I created a class for the equations and I was able to validate the input data. However, I am lost when it comes to calculating the equations. The program should do the following:
2A + 3B = 4
3A - 2c = 6
calculates to: 5A + 3B - 2C = 10
My program so far:
#include <iostream>
#include <string>
using namespace std;
class Equation
{
private:
enum {MAX_VARIABLES = 26};
string equation;
int num_variables;
public:
void read_equation();
void validate_user_input();
};
void Equation::read_equation()
{
//simply reads the input string
}
void Equation::validate_user_input()
{
//used a loop to count the number of letter in the string to make
//sure it was less than 26 per equation. If it is greater the
//user is prompted to re-enter the equation.
}
int main()
{
Equation eq1, eq2;
eq1.read_equation();
eqi.validate_user_input();
eq2.read_equation();
eq2.validate_user_input();
system("pause");
return 0;
}
// my two functions work fine and produce the correct results. My problem
// is determining how to calculate the two equations (adding one equations to the other)
//
// my idea was to separate the initial strings into 2D char arrays so that for example
// 2A would be one element of the array. I have no idea where else to go from here.
// Any ideas?