مساء الخير
ويا مرحبا فيكم
بصراحه عندي هالبرنامج
لكن دوخني حيل
لي فتره وانا ماني قادر اعدل واصحح الخطاء
فياليت تساعدوني في اسرع وقت ممكن
==============================================
#include
#include
#include
#include
class Node
{
private:
double data;
Node *next;
public:
Node( double input_data )
{
next = NULL;
data = input_data;
}
~Node()
{
delete [] next;
}
bool setData(double input_data)
{
data = input_data;
return true;
}
double getData()
{
return data;
}
bool setNext(Node *input_node)
{
next = input_node;
return true;
}
Node *getNext()
{
return next;
}
};
class Stack
{
private:
Node *top;
public:
Stack()
{
top = NULL;
}
~Stack()
{
Node *current = top, *previous;
// loop to delete the nodes from stack
while (current !=NULL)
{
previous= current->getNext();
delete current;
current=previous;
}
top= NULL;
}
bool isEmpty()
{
return top == NULL;
}
bool push(Node *n)
{
if (n != NULL)
{
if (top == NULL)
{
top = n;
}
else
{
top->setNext(n);
top = n;
return true;
}
}
return false;
}
Node *pop()
{
Node *current = top;
Node *old;
if (top != NULL)
{
old = top;
top = top->getNext();
return old;
}
return NULL;
}
void print()
{
Node *current=top;
cout << "nStack Contents:" << endl;
if (top == NULL)
cout<<"is empty"<
else
{
if (top != NULL)
{
cout<< " " <getData()<
top->getNext();
}
}
}
};
double calculate(double x, double y, char *operation)
{
if (!strcmp(operation, "+"))
return x + y;
else if (!strcmp(operation, "-"))
return x - y;
else if (!strcmp(operation, "*"))
return x * y;
else if (!strcmp(operation, "/"))
return x / y;
else if (!strcmp(operation, "^"))
return pow(x, y);
else if (!strcmp(operation, "%"))
return (int) x % (int) y;
return -1;
}
void main()
{
Stack stack;
Node n1(10), n2(20);
char line[200], *word;
while ( (cout << "Enter a line: " << flush) && fgets(line, 200, stdin) != NULL )
{
line[ strlen(line) - 1 ] = '