برنامه زیر از پشته و صف استفاده میکنه من در تابع main شیء s1 ,s2,q1رو تعریف کردم(قرمز رنگ) .اما در نوشتن توابع موقع استفاده از آنها (بنفش) اروری به من میده برای رفع این مشکل کسی از دوستان میتونه کمکم کنه ؟
ارور:
174 C:\Documents and Settings\My Documents\Parking Project For DataStructure.cpp `s1' undeclared (first use this function)
ارور:
174 C:\Documents and Settings\My Documents\Parking Project For DataStructure.cpp `s1' undeclared (first use this function)
کد:
[LEFT]#include<iostream>
using namespace std;
template <class KeyType>
class Stack
{
private:
int top;
KeyType *stack;
int MaxSize;
public:
Stack(int MaxStackSize = 10);
bool IsFull();
void StackFull();
void StackEmpty();
void Add(const KeyType& item);
bool IsEmpty();
KeyType* Delete(KeyType&);
};
template <class KeyType>
Stack<KeyType>::Stack(int MaxStackSize): MaxSize(MaxStackSize)
{
stack = new KeyType[MaxSize];
top = -1;
}
template <class KeyType>
inline bool Stack<KeyType>::IsFull()
{
if(top == MaxSize - 1)
return true;
else
return false;
}
template <class KeyType>
inline bool Stack<KeyType>::IsEmpty()
{
if(top == -1)
return true;
else
return false;
}
template <class KeyType>
void Stack<KeyType>::Add(const KeyType& x)
{
if(IsFull())
{
StackFull();
}
else
stack[++top] = x;
}
template <class KeyType>
KeyType* Stack<KeyType>::Delete(KeyType& x)
{
if(IsEmpty())
{
StackEmpty();
return 0;
}
x = stack[top--];
return &x;
}//end of stack
template <class KeyType>
class Queue
{
private:
int front, rear;
KeyType *queue;
int MaxSize;
public:
Queue(int MaxQueueSize = 10);
bool IsFull();
void Add(const KeyType& item);
bool IsEmpty();
KeyType* Delete(KeyType& );
void QueueEmpty();
void QueueFull();
};
template <class KeyType>
Queue<KeyType>::Queue(int MaxQueueSize) : MaxSize(MaxQueueSize)
{
queue = new KeyType[MaxSize];
front = rear =- 1;
}
template <class KeyType>
inline bool Queue<KeyType>::IsFull()
{
if(rear == MaxSize - 1)
return true;
else
return false;
}
template <class KeyType>
inline bool Queue<KeyType>::IsEmpty()
{
if(front == rear)
return true;
else
return false;
}
template <class KeyType>
void Queue<KeyType>::Add(const KeyType& x)
{
int k = (rear + 1) % MaxSize;
if(front == k) QueueFull();
else queue[rear = k] = x;
}
template <class KeyType>
KeyType* Queue<KeyType>::Delete(KeyType& x)
{
if(front == rear)
{
QueueEmpty();
return 0;
}
x = queue[++front %= MaxSize];
return &x;
}
void addcar();
void deletecar();
void printstatus();
int main()
{
int choice;
[COLOR="Red"] Stack<int> s1;//object s1 ro misazim- parking 1
Stack<int> s2;//Object s2 ro misazim -manzor haman koche bonbast ast
Queue<int> q;//parking shomare 2[/COLOR]
do while(choice != 4)
{
cout << '\n' << "Parking Project" << '\n';
cout << "1-Park a Car" << '\n';
cout << "2-Exit Car From Parking" << '\n';
cout << "3-Show Parkings and Alley Status" << '\n';
cout << "Please Enter Your Choice:";
cin >> choice;
switch(choice)
{
case 1:
addcar();
break;
case 2:
deletecar();
break;
case 3:
printstatus();
break;
}//end of switch
}
while(choice != 4);//end of do while
}//main func
void printstatus()
{
}//end of print func
void addcar()
{
int no;
cout << "Please Enter ID No Of Car That You Want to Add In Parking: ";
cin >> no;
[COLOR="Magenta"] s1.Add(no);[/COLOR]
}//end of add func
void deletecar()
{
int no;
cout << "Please Enter ID No Of Car That You Want to Exit With It From Parking: ";
cin >> no;
}//end of delete func
[/LEFT]