主题:高手帮忙修改下程序。
这是个“高校实验任务安排”系统,主要有⑴ 插入: ⑵ 删除:⑶ 查询:⑷ 修改:⑸ 输出到文本:的功能用VC++6.0运行有一下错误:
C:\Documents and Settings\Owner\桌面\复件 实训程序\010101.cpp(41) : error C2228: left of '.key' must have class/struct/union type
C:\Documents and Settings\Owner\桌面\复件 实训程序\010101.cpp(41) : error C2228: left of '.key' must have class/struct/union type
C:\Documents and Settings\Owner\桌面\复件 实训程序\010101.cpp(41) : fatal error C1903: unable to recover from previous error(s); stopping compilation
执行 cl.exe 时出错.
就是不知道'.key' 怎么定义还有第三个错误什么意思?
//---------------------------------------------------------------------------
#include <iostream.h>
#include <conio.h>
#include <cstring>
#include <conio.h>
#include <iomanip.h>
#define MAXSIZE 100
typedef int KeyType;
typedef int ElemType;
struct ElemType2 //学生的记录信息
{ KeyType key ; //学号
char name[8]; //姓名
} ;
class SeQueue
{ private:
ElemType elem[MAXSIZE];
ElemType *ht;
int length;
int front,rear;
public:
SeQueue();
~SeQueue();
void find(int k);
void AddQ(ElemType x);
ElemType DelQ();
ElemType gettop();
};
SeQueue::SeQueue()
{ front=0;
rear=0;
cout<<"建立!!"<<endl;
}
SeQueue::~SeQueue()
{}; //{ delete [MAXSIZE]Q.elem;}
void SeQueue::find(KeyType K )
{ int i,j,p;
j=K % p;
i=j-1;
while((ht[j].key!=0)&&(ht[j].key!=K)&&(j!=i)) j=(j+1)%MAXSIZE; // 解决冲突
if(ht[j].key==K)
{cout<<"\n 成功查找到学号为"<<K<<"的学生,位置在:"<<j<<"上";
cout<<"\n\n 该学生的基本信息为:\n\n" ;
cout<<"姓名:"<<ht[j].name;
j= - 32767;
}
else if(j= =i) { cout<<"\n 表满,出现异常! Overflow!"; // 溢出
j=32767;
}
return j;
}
void SeQueue::AddQ(ElemType x)
{ int i,j,K;char na[8];
cout<<"\n 请输入所要添加学生的学号以-1结束:"; cin>>K;
while(K!=-1)
{ i=find(K);
if(i==-32767) cout<<"\n 该学生已存在,无法插入。";
else if(i!=32767){
cout<<"\n 请输入学生的姓名:";
cin>>na>>;
ht[i].key=K;
strcpy(ht[i].name,na); //用串拷贝赋值
cout<<"\n 插入成功!" ;
cout<<"\n 请继续输入学号以-1结束:"; cin>>K;
}
}
}
ElemType SeQueue::DelQ()
{
if(front==rear)
{cout<<"QUEUE IS EMPTY\n"; return -1;}
else{
front=(front+1) % MAXSIZE;
return(elem[front]);
}
}
ElemType SeQueue::gettop()
{
if(front==rear)
{cout<<" 队列为空,无法显示 \n"; return -1;}
else
{ ElemType x;
x=elem[(front+1)%MAXSIZE];
return x;
}
}
int main( )
{ ElemType e; int j;
SeQueue h;
int k;
cout<<"\n 实验安排";
do{
cout<<"\n\n";
cout<<"\n\n 1.初步建立一个队列";
cout<<"\n\n 2.输出等待学生";
cout<<"\n\n 3.加入等待学生";
cout<<"\n\n 4.输出等待学生";
cout<<"\n\n 5.取队头";
cout<<"\n\n 6.输出打印到文本";
cout<<"\n\n 7.结束程序";
cout<<"\n******************************** ";
cout<<"\n 请输入你的选择(1,2,3,4,5,6)";
cin>>k;
switch(k){
case 1:{SeQueue::SeQueue();
}break;
case 2:{h.find();
}break;
case 3:{
cout<< "请输入等待学生"; cin>>e;
h.AddQ(e);
h.find();
}break;
case 4:{ e=h.DelQ();
if(e!=-1)
cout<< "出队的结点值是:"<<e<<endl;
h.find();
}break;
case 5:{ e=h.gettop();
if(e!=-1)
cout<<"本次做实验的学生为:"<<e<<endl;
}break;
case 6:{
ofstream of( "C:\0605.txt ");
of < <num;
cout<<"已输入到C:\0605.txt文件"<<endl;
}break;
default:break;
}
cout<<"\n--------------------------------- ";
}while(k>=1&&k<7);
cout<<"\n 再见!";
cout<<"\n 按任意键,返回。";
_getch(); return 0;
}
谢谢了
C:\Documents and Settings\Owner\桌面\复件 实训程序\010101.cpp(41) : error C2228: left of '.key' must have class/struct/union type
C:\Documents and Settings\Owner\桌面\复件 实训程序\010101.cpp(41) : error C2228: left of '.key' must have class/struct/union type
C:\Documents and Settings\Owner\桌面\复件 实训程序\010101.cpp(41) : fatal error C1903: unable to recover from previous error(s); stopping compilation
执行 cl.exe 时出错.
就是不知道'.key' 怎么定义还有第三个错误什么意思?
//---------------------------------------------------------------------------
#include <iostream.h>
#include <conio.h>
#include <cstring>
#include <conio.h>
#include <iomanip.h>
#define MAXSIZE 100
typedef int KeyType;
typedef int ElemType;
struct ElemType2 //学生的记录信息
{ KeyType key ; //学号
char name[8]; //姓名
} ;
class SeQueue
{ private:
ElemType elem[MAXSIZE];
ElemType *ht;
int length;
int front,rear;
public:
SeQueue();
~SeQueue();
void find(int k);
void AddQ(ElemType x);
ElemType DelQ();
ElemType gettop();
};
SeQueue::SeQueue()
{ front=0;
rear=0;
cout<<"建立!!"<<endl;
}
SeQueue::~SeQueue()
{}; //{ delete [MAXSIZE]Q.elem;}
void SeQueue::find(KeyType K )
{ int i,j,p;
j=K % p;
i=j-1;
while((ht[j].key!=0)&&(ht[j].key!=K)&&(j!=i)) j=(j+1)%MAXSIZE; // 解决冲突
if(ht[j].key==K)
{cout<<"\n 成功查找到学号为"<<K<<"的学生,位置在:"<<j<<"上";
cout<<"\n\n 该学生的基本信息为:\n\n" ;
cout<<"姓名:"<<ht[j].name;
j= - 32767;
}
else if(j= =i) { cout<<"\n 表满,出现异常! Overflow!"; // 溢出
j=32767;
}
return j;
}
void SeQueue::AddQ(ElemType x)
{ int i,j,K;char na[8];
cout<<"\n 请输入所要添加学生的学号以-1结束:"; cin>>K;
while(K!=-1)
{ i=find(K);
if(i==-32767) cout<<"\n 该学生已存在,无法插入。";
else if(i!=32767){
cout<<"\n 请输入学生的姓名:";
cin>>na>>;
ht[i].key=K;
strcpy(ht[i].name,na); //用串拷贝赋值
cout<<"\n 插入成功!" ;
cout<<"\n 请继续输入学号以-1结束:"; cin>>K;
}
}
}
ElemType SeQueue::DelQ()
{
if(front==rear)
{cout<<"QUEUE IS EMPTY\n"; return -1;}
else{
front=(front+1) % MAXSIZE;
return(elem[front]);
}
}
ElemType SeQueue::gettop()
{
if(front==rear)
{cout<<" 队列为空,无法显示 \n"; return -1;}
else
{ ElemType x;
x=elem[(front+1)%MAXSIZE];
return x;
}
}
int main( )
{ ElemType e; int j;
SeQueue h;
int k;
cout<<"\n 实验安排";
do{
cout<<"\n\n";
cout<<"\n\n 1.初步建立一个队列";
cout<<"\n\n 2.输出等待学生";
cout<<"\n\n 3.加入等待学生";
cout<<"\n\n 4.输出等待学生";
cout<<"\n\n 5.取队头";
cout<<"\n\n 6.输出打印到文本";
cout<<"\n\n 7.结束程序";
cout<<"\n******************************** ";
cout<<"\n 请输入你的选择(1,2,3,4,5,6)";
cin>>k;
switch(k){
case 1:{SeQueue::SeQueue();
}break;
case 2:{h.find();
}break;
case 3:{
cout<< "请输入等待学生"; cin>>e;
h.AddQ(e);
h.find();
}break;
case 4:{ e=h.DelQ();
if(e!=-1)
cout<< "出队的结点值是:"<<e<<endl;
h.find();
}break;
case 5:{ e=h.gettop();
if(e!=-1)
cout<<"本次做实验的学生为:"<<e<<endl;
}break;
case 6:{
ofstream of( "C:\0605.txt ");
of < <num;
cout<<"已输入到C:\0605.txt文件"<<endl;
}break;
default:break;
}
cout<<"\n--------------------------------- ";
}while(k>=1&&k<7);
cout<<"\n 再见!";
cout<<"\n 按任意键,返回。";
_getch(); return 0;
}
谢谢了