eita_zuliana 0 Report post Posted February 29, 2008 Sapa2 boleh tolong nak selesaikan masalah nie....saya dah buat tapi ade error jugak....mintak tolong.... Create a program using C++ to implement stack using array. You must require the user to input their date of birth in format ddmmyyyy. Push the input from the user into the stack. Display the top element of the stack. Then pop 4 elements. Again display the top element of the stack. Now, push integer 10. Display the top element of the stack and the whole content of the stack.**As we know, only one element can be pushed into the stack at once. #include <iostream.h>const int size=100;class Stack{ private: int Top; char data; char bday; public: create(); Push(); Pop(); StackTop(); bool Full(); bool Empty();};Stack::create(){ Top = -1;}bool Stack::Empty(){ return bool(Top== -1);}bool Stack::Full(){ return bool(Top== size-1);}Stack::Push(){ char newitem; int i; for(i=0;i<8;i++) cout<<"Enter item into stack:"<<endl; cin>>newitem; if(Full()) cout<<"Stack is full!!"<<endl; else { Top=Top+1; data[Top]= newitem; }}Stack::Pop();{ if(Empty()) cout<<"Stack is empty!!"<<endl; else { cout<<"Item has been popped is:"<<data[Top]<<endl; Top=Top-1; }}Stack::StackTop(){ if(Empty()) cout<<"Stack is empty"<<endl; else { cout<<"Top item in the stack is:"<<data[Top]<<endl; }}void main(){ Stack d; int Top; char bday; cout<<"What is your birthday?:"<<endl; cin>>bday; d.Push(); d.create(); d.StackTop(); d.Full(); d.Empty(); return 0;} Quote Share this post Link to post Share on other sites
Admin2 12 Report post Posted March 1, 2008 Kita kena wat baik sesama manusia.. tolong menolong, bekerjasama sentiasa mengeratkan silatulrahim.. eh? hehe.. x de siapa nak tolong cik ni ke? cik Eita Zuliana, nanti saya cuba check coding cik... Quote Share this post Link to post Share on other sites
eita_zuliana 0 Report post Posted March 2, 2008 tq... Quote Share this post Link to post Share on other sites
PinguSpy 3 Report post Posted March 4, 2008 apasal aku rase mcm k0 punye malsh?first tgk koding aku dh tau first error cube buang void dkt main bwh sekali... lain2 error cari sendiri ar... p/s aku pun ader coding yg perlu disiapkn Quote Share this post Link to post Share on other sites
zeph 1 Report post Posted March 23, 2008 aku cuba fix error yg terang2 jer ni, banyak lagi bug perlu dibuang.#include <iostream> using namespace std; const int size=100; class Stack { private: int Top; char data[size]; char bday; char newitem; public: void create(); void Push(); void Pop(); void StackTop(); bool Full(); bool Empty(); }; void Stack::create() { Top = -1; } bool Stack::Empty() { return bool(Top== -1); } bool Stack::Full() { return bool(Top == (size-1)); } void Stack::Push() { int i; for (i=0;i<8;i++) cout << "Enter item into stack:" << endl; cin >> newitem; cout << "ruun" << endl; if (Full()) cout << "Stack is full!!" << endl; else { Top=Top+1; data[Top]= newitem; } } void Stack::Pop() { if (Empty()) cout<<"Stack is empty!!"<<endl; else { cout<<"Item has been popped is:"<<data[Top]<<endl; Top=Top-1; } } void Stack::StackTop() { if (Empty()) cout<<"Stack is empty"<<endl; else { cout<<"Top item in the stack is:"<<data[Top]<<endl; } } int main() { Stack d; char bday; cout<<"What is your birthday?:"<<endl; cin>>bday; d.create(); d.Push(); d.StackTop(); d.Full(); d.Empty(); return 0; } Quote Share this post Link to post Share on other sites