Hey guys,
I do have a main function and need to write the class. I just need to where should I start. I am a new in C++ but the prof. asked us to write the class code of this calculator. He already gave the main function and the purpose of the class is an
HP calculator has a screen and a push down stack that can hold up to 20 entries. The calculations of multiplication addition subtraction and division are all performed. if more then 20 entries are pushed, it will crash.
[code.c++]
int main(){
StCalc a;
a.enter(2); //screen has 2
a.push() .enter(3); //2 on stack screen has 3
a.push() .add() .pop(); // 2 3 on stack, add, pop to screen which has 5
cout<<"Expect StCalc (5): "<<a<<endl; // test "<<"
cout<<"Expect 5: "<<a.getScreen()<<endl; //test getScreen()
a.push() .enter(4); //5 on stack 4 on screen
cout<<"Expect StCalc (20): "<<a.push() .mul() .pop<<endl;
a.push() .enter(8); //stack has 20 screen has 8
cout<<"Expect StCalc(2.5): '<<a.push() .sub() .pop() <<endl;
a.push() .enter(3); //2.5 on stack, 3 on screen
cout<<"Expect StCalc(-0.5): <<a.push() .sub() .pop()<<endl;
a<<42; //test overload "<<", which stores 42 on screen
cout<< "expect 10: ""<<(a==42)<<(==3)<<endl; //test boolen ==
cout<<"Expect StCalc (42): "<<a<<endl;
a.enter(3);
a+=2; //test overloaded +=
cout<<"Expect StCalc(5): "<<a<<endl;
a.push() .enter(0);
//a.push() div(); //should crash
a.push() .push() .push() .push() .push() .push() .push();
a.push() .push() .push() .push() .push() .push() .push();
a.push() .push() .push() .push() .push() .push() .push();
}
void check(bool b, char *mess, int line, char *filename) {
if(!b){
cerr<<"ERROR(line "<<line<<" in file '""<<filename<<"'): "<<mess<<endl;
exit(1);
}
}
/* the OUTPUT
Expect StCalc (5): StCalc (5)
Expect 5: 5
Expect StCalc (20):StCalc(20)
Expect StCalc (2.5): StCalc(2.5)
Expect StCalc (-0.5): StCalc (-0.5)
Expect 10: 10
Expect StCalc (42): StCalc(42)
Expect StCalc (5): StCalc (5)
ERROR (line 86 in file 'fullp0.cc') : (Stcalc ::push()) stack overflow*/