Start by making sure you understand what exactly you are supposed to do. Start by making sure you understand what all of these functions are supposed to do and why he has main the way he has it. Start by spending a considerable amount of time doing all of these problems with pencil and paper till you know what everything represents. Then write some functions and test them with a simpler main to make sure it all works appropriately. When it does, go back to his main and try it.
Code tags are like this:
[code=C++]
// paste code here
[/code]
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
I've never seen sequential dot operators used like this:
myClass a;
a.enter().push();
but I like learning new things, so if someone can confirm line two above as valid syntax assuming enter() and push() are valid methods for a myClass object, I'll be wiser than I am now.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
Look at all the pretty colours in your post.
Blue means it's a string - is it really meant to be a string?
Consider looking for the mis-placed "
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
I've never seen sequential dot operators used like this:
myClass a;
a.enter().push();
but I like learning new things, so if someone can confirm line two above as valid syntax assuming enter() and push() are valid methods for a myClass object, I'll be wiser than I am now.
The syntax is fine, depending on what everything returns. If the methods return myClass objects, you're good to go. Here's a valid, though completely meaningless implementation.
#include <iostream>
using namespace std;
class myClass
{
public:
myClass ()
{
}
myClass enter ()
{
return *this;
}
myClass push ()
{
return *this;
}
private:
int someAttribute;
};
int main()
{
myClass a;
a.enter ().push ();
cin.get ();
return 0;
}
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
VernonDozier, thanks. I knew that explained why the << and the + operator can be used sequentially, but I've never seen the dot operator used that way. I have used the dot operator sequentially to get infromation or do things for encapsulated class/struct members, but have never seen this use of it before.
serdengil, post the code you have written for the StCalc class, not the driver program. It looks to me like you will need several variable members in the class in addition to the methods necessary to be able to run the code. It looks like you will need at least one variable to store input, one variable to store an answer and one stack variable. Only you know if you can use code for a prewritten stack or whether you will need to write your own.
Start out by commenting all of the program in main() except the declaration of the StCalc variable and a line to display either or both of the member variables. Once you can do that then write code to do each method you need to create for the program one at a time. If you have to write code to be sure the method is working correctly before it's actually used in the program as written, good for you, just be sure you remove it after the function has been thouroughly tested.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
Paste your CODE, not some fuzzy bitmap image.
How the hell are we supposed to quote text from that?
Oh, and the for loop in your ctor is broke.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
You can either embed a stack within the StCalc or you can write code to create a stack directly. Given you use of an array within the code, then I assume you will be writing code directly.
Here's how I would start writing code. I used public member variables to make the functionality easier. I would use private member variables to make the code more stable.
struct myStack
{
myStack() {};//write code to initialize member variables
int sizeOfStack;
double input;
double array[20];
double answer;
void enter(double i) {}; //write code to put i into input;
};
int main()
{
StCalc a;
a.enter(3);
/*the following 3 lines are debugging code to assure the constructor and enter() worked as expected. I will be removed when functionality assured.*/
cout << a.input << endl;
cout << a.answer << endl;
cout << a.sizeOfStack << endl;
cin.get();
return 0;
}
Only after I got that functionality working would I try to do anything directly with the arrray, like limiting availability of elements to make it functional stack.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396