![]() |
#2
rjsp2021-01-24 20:22
|
比如这行有以下错误:
Item a[MAX];
[Error] field 'a' has incomplete type 'Item [10]'
代码如下:

#include<iostream>
using namespace std;
typedef struct Item;
class Stack{
private:
double ui=0;
int top;
struct customer{
char fullname[35];
double payment;
};
enum{MAX=10};
Item a[MAX];
public:
Stack(){
top=0;
};
bool isemptey()const;
bool isfull()const;
bool push(const Item &st)const;
bool pop(const Item &st)const;
};
bool Stack::isempty()const{
return top==0;
}
bool Stack::isfull()const{
return top==MAX;
}
bool Stack::push(const Item &st)const{
if(top<MAX){
a[top++]=st;
return true;
}
else{
return false;
}
}
bool Stack::pop(const Item &st)const{
if(top>0){
st=a[--top];
ui+=st.payment;
return true;
}
else
return false;
}
int Stack::show(){
cout<<"ui的值为:"<<ui<<endl;
}
int main(){
Stack asd;
char ch;
Item b={"qwer",44.3};
while(cin>>ch&&ch!='Q'){
while(cin.get()!="\n"){
continue;
}
switch(ch){
case 'A':
case 'a':
cin>>b.payment;
if(asd.isfull())
cout<<"Stack is full.";
else
asd.push(b);
break;
case 'p':
case 'P':
cin>>b.payment;
if(asd.isempty())
cout<<"Stack is empty.";
else{
asd.pop(b);
cout<<"payment结构成员的值为:"<<b.payment<<endl;
asd.show();
}
break;
}
}
return 0;
}
using namespace std;
typedef struct Item;
class Stack{
private:
double ui=0;
int top;
struct customer{
char fullname[35];
double payment;
};
enum{MAX=10};
Item a[MAX];
public:
Stack(){
top=0;
};
bool isemptey()const;
bool isfull()const;
bool push(const Item &st)const;
bool pop(const Item &st)const;
};
bool Stack::isempty()const{
return top==0;
}
bool Stack::isfull()const{
return top==MAX;
}
bool Stack::push(const Item &st)const{
if(top<MAX){
a[top++]=st;
return true;
}
else{
return false;
}
}
bool Stack::pop(const Item &st)const{
if(top>0){
st=a[--top];
ui+=st.payment;
return true;
}
else
return false;
}
int Stack::show(){
cout<<"ui的值为:"<<ui<<endl;
}
int main(){
Stack asd;
char ch;
Item b={"qwer",44.3};
while(cin>>ch&&ch!='Q'){
while(cin.get()!="\n"){
continue;
}
switch(ch){
case 'A':
case 'a':
cin>>b.payment;
if(asd.isfull())
cout<<"Stack is full.";
else
asd.push(b);
break;
case 'p':
case 'P':
cin>>b.payment;
if(asd.isempty())
cout<<"Stack is empty.";
else{
asd.pop(b);
cout<<"payment结构成员的值为:"<<b.payment<<endl;
asd.show();
}
break;
}
}
return 0;
}