#include<iostream>
using namespace std;
#define size 10
struct node
{
char Code[size];
char Value[size];
node *next;
};
class book
{
private:
node *top;
int count;
public:
book();
~book();
bool empty();
void push(char Code[], char Value[]);
void pop(char cod[10], char val[10]);
}
;
book::book()
{
top=NULL;
count=0;
}
book::~book() {}
bool book::empty()
{
return count==0;
}
void book::push(char cod[10], char val[10])
{
node *newNode;
newNode = new node;
strcpy( newNode->Code, cod );
strcpy( newNode->Value, val );
if(empty())
{
top=newNode;
newNode->next=NULL;
}
else
{
newNode->next=top;
top=newNode;
count++;
}
}
void book::pop(char cod[10], char val[10])
{
if(empty())
cout<<"The stack is empty!!"<<endl;
else
{
cout<<"Code: "<<top->Code<<endl;
cout<<"Value: "<<top->Value<<".00"<<endl;
cout<<top->Code<<endl;
cout<<top->Value<<endl;
node *temp=top;
top=top->next;
delete temp;
--count;
}
}
void main()
{
book bookstore;
int input1=1;
char code[10];
char value[10];
cout<<"Please enter data, and 0 to stop;"<<endl;
while(input1!=0)
{
cout<<"Code: ";
cin>>code;
cout<<"Value: ";
cin>>value;
bookstore.push(code,value);
cout<<endl;
}
cout<<"\nThe list of items received:"<<endl;
while(!bookstore.empty())
{
bookstore.pop(code,value);
}
}
input will never be zero because it never changes.
P.S: Please use code-tags.
Wazzak
Last edited on
You can make it in two steps:
1. Use Code Tags
2. Check code and value, and break when required.
int Number = 4;
int Number = 4;
See the difference?
There is a button on the right that looks like [<>], press it and put all your code like this:
[ code] Put your code here [ /code]
Did you really think Code Tags was a Your-code-related thing?