请大佬帮忙改一下错误,可苦了孩子呢
#include <iostream>#include <cstring>
#include <stdlib.h>
#include <fstream>
#include <sstream>
#include <stdlib.h>
const int MAXSTUDENT=1000;
#define N 40
#define M 840
using namespace std;
struct Sequence{
int id;
string name;
float PrePSNRY;
float SufPSNRY;
float Prebit;
float Sufbit;
float Prebuf;
float Sufbuf;
}Sequences[MAXSTUDENT];
void PrintMenuPTU23();
void AddSequencePTU23();
void ShowSequencePTU23();
void DeleteBySequenceNamePTU23();
void FindBySequenceNamePTU23();
//bool IsRunning();
void EditBySequenceNamePTU23();
void ShowSequence00();
int importPTU23();
//void bd;
void savePTU23();
void sortPTU23();
void MergesequencePTU23();
int SequenceNum;//声明变量
int main()
{
system("color f2");
SequenceNum=0;
char selected=0;//初始化用户输入的菜单选项
bool running=true; //系统运行标志
PrintMenuPTU23();
while(running)
{
cout<<"请输入菜单选项:";
cin>>selected;
switch(selected){
case '1':
fflush(stdin);
AddSequencePTU23();
//running=IsRunning();
break;
case '2':
fflush(stdin);
ShowSequencePTU23();
//running=IsRunning();
break;
case '3':
fflush(stdin);
DeleteBySequenceNamePTU23();
//running=IsRunning();
break;
case '4':
fflush(stdin);
FindBySequenceNamePTU23();
//running=IsRunning();
break;
case '5':
fflush(stdin);
EditBySequenceNamePTU23();
//running=IsRunning();
break;
case '6':
fflush(stdin);
importPTU23();
MergesequencePTU23();
//running=IsRunning();
break;
case '7':
fflush(stdin);
savePTU23();
//running=IsRunning();
break;
case '8':
fflush(stdin);
system("cls");
//running=IsRunning();
break;
case '9':
fflush(stdin);
sortPTU23();
//running=IsRunning();
break;
case '/':
fflush(stdin);
PrintMenuPTU23();
running=true;
break;
case '0':
fflush(stdin);
running=false;
break;
default:
fflush(stdin);
cout<<"输入无效,请重新输入。。。"<<endl;
system("pause");
running=true;
}
}
return 0;
}
inline void PrintMenuPTU23()
{
cout<<"________________________________________"<<endl;
cout<<"| | "<<endl;
cout<<"| 信息管理程序 |"<<endl;
cout<<"| |"<<endl;
cout<<"| 1.新增信息 2.浏览信息 3.删除信息 |"<<endl;
cout<<"| 4.查找信息 5.修改信息 6.交替导入 |"<<endl;
cout<<"| 7.导出信息 8.清屏 9.排序 |"<<endl;
cout<<"| /.显示菜单 0.退出 |"<<endl;
cout<<"|______________________________________|"<<endl;
}
void AddSequencePTU23()
{
string sname;
float sPrePSNRY;
float sSufPSNRY;
cout<<"请输入name、PrePSNRY和SufPSNRY:";
if(!((cin>>sname)&&(cin>>sPrePSNRY)&&(cin>>sSufPSNRY)))
{
cin.clear();
cin.sync();
cout <<"Warning!!!\n输入数据类型错误,请重试!"<<endl;
}
else
{
Sequences[SequenceNum].id=SequenceNum;
Sequences[SequenceNum].name=sname;
Sequences[SequenceNum].PrePSNRY=sPrePSNRY;
Sequences[SequenceNum].SufPSNRY=sSufPSNRY;
SequenceNum++;
}
}
void ShowSequencePTU23()
{
cout<<"共有"<<SequenceNum<<"条信息:"<<endl;
cout<<"id\t\tname\t\tPrePSNRY\t\tSufPSNRY"<<endl;
for(int i=0;i<SequenceNum;i++)
{
cout<<Sequences[i].id<<"\t\t"<<Sequences[i].name<<"\t\t"<<Sequences[i].PrePSNRY;
cout<<"\t\t\t"<<Sequences[i].SufPSNRY<<endl;
}
}
/*bool IsRunning()
{
char yn='y';
cout<<"Y或y继续,其它任意字符键退出......:";
cin>>yn;
if(yn=='Y'|| yn=='y')
{
return true;
}
return false;
}*/
void DeleteBySequenceNamePTU23()
{
string sname;
cout<<"请输入要删除name:";
cin>>sname;
int i;
bool flag=true;
for( i=0;i<SequenceNum;i++)
if(!(Sequences[i].name))
{
Sequences[i]=Sequences[SequenceNum-1];
SequenceNum--;
cout<<"删除成功!"<<endl;
flag=false;
break;
}
if(flag)
{
cout<<"删除失败!"<<endl;
}
}
void FindBySequenceNamePTU23()
{
string sname;
cout<<"请输入要查找name:";
cin>>sname;
int i;
for( i=0;i<SequenceNum;i++)
if(!(Sequences[i].name))
{
cout<<"id\t\tname\t\tPrePSNRY\t\tSufPSNRY"<<endl;
cout<<Sequences[i].id<<"\t\t"<<Sequences[i].name<<"\t\t"<<Sequences[i].PrePSNRY;
cout<<"\t\t\t"<<Sequences[i].SufPSNRY<<endl;
break;
}
if(i==SequenceNum)
{
cout<<"查找失败!"<<endl;
}
}
void EditBySequenceNamePTU23()
{
string sname;
float sPrePSNRY;
float sSufPSNRY;
cout<<"请输入要修改name、PrePSNRY和SufPSNRY:";
if(!((cin>>sname)&&(cin>>sPrePSNRY)&&(cin>>sSufPSNRY)))
{
cin.clear();
cin.sync();
cout <<"Warning!!!\n输入数据类型错误,请重试!"<<endl;
}
else
{
int i;
for( i=0;i<SequenceNum;i++)
if(!(Sequences[i].name))
{
Sequences[i].PrePSNRY=sPrePSNRY;
Sequences[i].SufPSNRY=sSufPSNRY;
cout<<"修改成功!"<<endl;
break;
}
if(i==SequenceNum)
cout<<"修改失败!"<<endl;
}
}
string name0[M/7],name1[M/7],name2[M/7],name3[M/7],name4[M/7],name5[M/7],name6[M/7];bool daoru=false;
float PrePSNRY1[M/7],PrePSNRY0[M/7],PrePSNRY2[M/7],PrePSNRY3[M/7],PrePSNRY4[M/7],PrePSNRY5[M/7],PrePSNRY6[M/7],SufPSNRY1[M/7],SufPSNRY0[M/7],SufPSNRY2[M/7],SufPSNRY3[M/7],SufPSNRY4[M/7],SufPSNRY5[M/7],SufPSNRY6[M/7];
float Prebit1[M/7],Prebit0[M/7],Prebit2[M/7],Prebit3[M/7],Prebit4[M/7],Prebit5[M/7],Prebit6[M/7],Sufbit1[M/7],Sufbit0[M/7],Sufbit2[M/7],Sufbit3[M/7],Sufbit4[M/7],Prebuf1[M/7],Prebuf0[M/7],Prebuf2[M/7],Prebuf3[M/7],Prebuf4[M/7],Prebuf5[M/7],Prebuf6[M/7],Sufbuf1[M/7],Sufbuf0[M/7],Sufbuf2[M/7],Sufbuf3[M/7],Sufbuf4[M/7],Sufbuf5[M/7],Sufbuf6[M/7],
int importPTU23()
{
//1234567
// 23号 [7465123] [4357261] [1637524] [5674132] [6217345] [2764315] [3547162]
/*
1 BalloonsV21
2 DancerV21
3 GtflyV21
4 KendoV21
5 NewspaperV21
6 Poznanhall2V21
7 PoznanstreetV21
*/
ifstream inFile0("PoznanstreetV21.csv", ios::in);
ifstream inFile1("KendoV21.csv", ios::in);
ifstream inFile2("Poznanhall2V21.csv", ios::in);
ifstream inFile3("NewspaperV21.csv", ios::in);
ifstream inFile4("BalloonsV21.csv", ios::in);
ifstream inFile5("DancerV21.csv", ios::in);
ifstream inFile6("GtflyV21.csv", ios::in);
if ((!inFile0)||(!inFile1)||(!inFile2)||(!inFile3)||(!inFile4)||(!inFile5)||(!inFile6))
{
cout << "文件打开失败!" << endl;
return 0;
}
else
{
cout << "文件打开成功!" << endl;
daoru=true;
}
string line;
string field;
int i=0;
while (getline(inFile0, line))
{
string field;
istringstream sin(line);
getline(sin, field, ',');
name1[i]=field;
getline(sin, field, ',');
PrePSNRY0[i]=atof(field.c_str()) ;
getline(sin, field, ',');
SufPSNRY0[i]=atof(field.c_str());
getline(sin, field, ',');
Prebit0[i]=atof(field.c_str());
getline(sin, field, ',');
Sufbit0[i]=atof(field.c_str());
getline(sin, field, ',');
Prebuf0[i]=atof(field.c_str());
getline(sin, field, ',');
Sufbuf0[i++]=atof(field.c_str());
if(i==M/7)break;
}
i=0;
while (getline(inFile1, line))
{
string field;
istringstream sin(line);
getline(sin, field, ',');
name0[i]=field;
getline(sin, field, ',');
PrePSNRY1[i]=atof(field.c_str()) ;
getline(sin, field, ',');
SufPSNRY1[i]=atof(field.c_str());
getline(sin, field, ',');
Prebit1[i]=atof(field.c_str());
getline(sin, field, ',');
Sufbit1[i]=atof(field.c_str());
getline(sin, field, ',');
Prebuf1[i]=atof(field.c_str());
getline(sin, field, ',');
Sufbuf1[i++]=atof(field.c_str());
if(i==M/7)break;
}
i=0;
while (getline(inFile2, line))
{
string field;
istringstream sin(line);
getline(sin, field, ',');
name2[i]=field;
getline(sin, field, ',');
PrePSNRY2[i]=atof(field.c_str()) ;
getline(sin, field, ',');
SufPSNRY2[i]=atof(field.c_str());
getline(sin, field, ',');
Prebit2[i]=atof(field.c_str());
getline(sin, field, ',');
Sufbit2[i]=atof(field.c_str());
getline(sin, field, ',');
Prebuf2[i]=atof(field.c_str());
getline(sin, field, ',');
Sufbuf2[i++]=atof(field.c_str());
if(i==M/7)break;
}
i=0;
while (getline(inFile3, line))
{
string field;
istringstream sin(line);
getline(sin, field, ',');
name3[i]=field;
getline(sin, field, ',');
PrePSNRY3[i]=atof(field.c_str()) ;
getline(sin, field, ',');
SufPSNRY3[i]=atof(field.c_str());
getline(sin, field, ',');
Prebit3[i]=atof(field.c_str());
getline(sin, field, ',');
Sufbit3[i]=atof(field.c_str());
getline(sin, field, ',');
Prebuf3[i]=atof(field.c_str());
getline(sin, field, ',');
Sufbuf3[i++]=atof(field.c_str());
if(i==M/7)break;
}
i=0;
while (getline(inFile4, line))
{
string field;
istringstream sin(line);
getline(sin, field, ',');
name4[i]=field;
getline(sin, field, ',');
PrePSNRY4[i]=atof(field.c_str()) ;
getline(sin, field, ',');
SufPSNRY4[i]=atof(field.c_str());
getline(sin, field, ',');
Prebit4[i]=atof(field.c_str());
getline(sin, field, ',');
Sufbit4[i]=atof(field.c_str());
getline(sin, field, ',');
Prebuf4[i]=atof(field.c_str());
getline(sin, field, ',');
Sufbuf4[i++]=atof(field.c_str());
if(i==M/7)break;
}
i=0;
while (getline(inFile5, line))
{
string field;
istringstream sin(line);
getline(sin, field, ',');
name4[i]=field;
getline(sin, field, ',');
PrePSNRY4[i]=atof(field.c_str()) ;
getline(sin, field, ',');
SufPSNRY4[i]=atof(field.c_str());
getline(sin, field, ',');
Prebit4[i]=atof(field.c_str());
getline(sin, field, ',');
Sufbit4[i]=atof(field.c_str());
getline(sin, field, ',');
Prebuf4[i]=atof(field.c_str());
getline(sin, field, ',');
Sufbuf4[i++]=atof(field.c_str());
if(i==M/7)break;
}
i=0;
while (getline(inFile6, line))
{
string field;
istringstream sin(line);
getline(sin, field, ',');
name4[i]=field;
getline(sin, field, ',');
PrePSNRY4[i]=atof(field.c_str()) ;
getline(sin, field, ',');
SufPSNRY4[i]=atof(field.c_str());
getline(sin, field, ',');
Prebit4[i]=atof(field.c_str());
getline(sin, field, ',');
Sufbit4[i]=atof(field.c_str());
getline(sin, field, ',');
Prebuf4[i]=atof(field.c_str());
getline(sin, field, ',');
Sufbuf4[i++]=atof(field.c_str());
if(i==M/7)break;
}
inFile0.close();
inFile1.close();
inFile2.close();
inFile3.close();
inFile4.close();
inFile5.close();
inFile6.close();
return true;
}
void savePTU23()
{
/*
BalloonsV21
DancerV21
GtflyV21
KendoV21
NewspaperV21
Poznanhall2V21
PoznanstreetV21
*/
ofstream outFile;
// 23号 [7465123] [4357261] [1637524] [5674132] [6217345] [2764315] [3547162]
//[7465123] PoznanstreetV21-KendoV21-Poznanhall2V21-NewspaperV21-BalloonsV21-DancerV21-GtflyV21
outFile.open("PoznanstreetV21-KendoV21-Poznanhall2V21-NewspaperV21-BalloonsV21-DancerV21-GtflyV21.csv");
outFile<<"id"<<","<<"PrePSNRY"<<","<<"SufPSNRY"<<","<<"Prebit"<<","<<"Sufbit"<<","<<"Prebuf"<<","<<"Sufbuf"<<endl;
for(int i=0;i<SequenceNum;i++)
{
outFile<<Sequences[i].id<<","<<Sequences[i].PrePSNRY;
outFile<<","<<Sequences[i].SufPSNRY<<","<<Sequences[i].Prebit<<","
<<Sequences[i].Sufbit<<","<<Sequences[i].Prebuf<<","<<Sequences[i].Sufbuf<<endl;
}
cout<<"导出成功!"<<endl;
outFile.close();
}
/*void bd(int n)
{
if(n==0)
return ;
else
{
bd(n/2);
cout<<n%2;
}
}*/
void ShowSequence00()
{
cout<<"共有"<<SequenceNum<<"条信息:"<<endl;
cout<<"id\t\tname\t\tPrePSNRY\t\tSufPSNRY"<<endl;
for(int i=SequenceNum-1;i>=0;i--)
{
cout<<Sequences[i].id<<"\t\t"<<Sequences[i].name<<"\t\t"<<Sequences[i].PrePSNRY<<"\t\t\t";
cout<<Sequences[i].SufPSNRY<<endl;
}
}
void sortPTU23()
{
int i,j;
Sequence x;
for(i=1;i<SequenceNum;i++)
{
for(j=0;j<SequenceNum-i;j++)
if((Sequences[j].PrePSNRY+Sequences[j].SufPSNRY)>(Sequences[j+1].PrePSNRY+Sequences[j+1].SufPSNRY))
{
x=Sequences[j];
Sequences[j]=Sequences[j+1];
Sequences[j+1]=x;
}
}
cout<<"成绩总分升序请输入:A或a 降序请输入:Z或z"<<endl;
char k;
cin>>k;
switch(k)
{
case 'A':
case 'a':
ShowSequencePTU23();
break;
case 'Z':
case 'z':
ShowSequence00();
break;
default:
cout<<"输入错误!"<<endl;
}
}
void MergesequencePTU23()
{
while(daoru)
{
int i;
for(int j=0;j<=(M/7-N);j+=N)
{
for(i=0;i<N;i++)
{
Sequences[SequenceNum].id=SequenceNum;
//Sequences[SequenceNum].name=name0[i+j];
Sequences[SequenceNum].PrePSNRY=PrePSNRY0[i+j];
Sequences[SequenceNum].SufPSNRY=SufPSNRY0[i+j];
Sequences[SequenceNum].Prebit=Prebit0[i+j];
Sequences[SequenceNum].Sufbit=Sufbit0[i+j];
Sequences[SequenceNum].Prebuf=Prebuf0[i+j];
Sequences[SequenceNum].Sufbuf=Sufbuf0[i+j];
SequenceNum++;
}
for(i=0;i<N;i++)
{
Sequences[SequenceNum].id=SequenceNum;
//Sequences[SequenceNum].name=name1[i+j];
Sequences[SequenceNum].PrePSNRY=PrePSNRY1[i+j];
Sequences[SequenceNum].SufPSNRY=SufPSNRY1[i+j];
Sequences[SequenceNum].Prebit=Prebit1[i+j];
Sequences[SequenceNum].Sufbit=Sufbit1[i+j];
Sequences[SequenceNum].Prebuf=Prebuf1[i+j];
Sequences[SequenceNum].Sufbuf=Sufbuf1[i+j];
SequenceNum++;
}
for(i=0;i<N;i++)
{
Sequences[SequenceNum].id=SequenceNum;
//Sequences[SequenceNum].name=name1[i+j];
Sequences[SequenceNum].PrePSNRY=PrePSNRY2[i+j];
Sequences[SequenceNum].SufPSNRY=SufPSNRY2[i+j];
Sequences[SequenceNum].Prebit=Prebit2[i+j];
Sequences[SequenceNum].Sufbit=Sufbit2[i+j];
Sequences[SequenceNum].Prebuf=Prebuf2[i+j];
Sequences[SequenceNum].Sufbuf=Sufbuf2[i+j];
SequenceNum++;
}
for(i=0;i<N;i++)
{
Sequences[SequenceNum].id=SequenceNum;
//Sequences[SequenceNum].name=name1[i+j];
Sequences[SequenceNum].PrePSNRY=PrePSNRY3[i+j];
Sequences[SequenceNum].SufPSNRY=SufPSNRY3[i+j];
Sequences[SequenceNum].Prebit=Prebit3[i+j];
Sequences[SequenceNum].Sufbit=Sufbit3[i+j];
Sequences[SequenceNum].Prebuf=Prebuf3[i+j];
Sequences[SequenceNum].Sufbuf=Sufbuf3[i+j];
SequenceNum++;
}
for(i=0;i<N;i++)
{
Sequences[SequenceNum].id=SequenceNum;
//Sequences[SequenceNum].name=name1[i+j];
Sequences[SequenceNum].PrePSNRY=PrePSNRY4[i+j];
Sequences[SequenceNum].SufPSNRY=SufPSNRY4[i+j];
Sequences[SequenceNum].Prebit=Prebit4[i+j];
Sequences[SequenceNum].Sufbit=Sufbit4[i+j];
Sequences[SequenceNum].Prebuf=Prebuf4[i+j];
Sequences[SequenceNum].Sufbuf=Sufbuf4[i+j];
SequenceNum++;
}
for(i=0;i<N;i++)
{
Sequences[SequenceNum].id=SequenceNum;
//Sequences[SequenceNum].name=name0[i+j];
Sequences[SequenceNum].PrePSNRY=PrePSNRY0[i+j];
Sequences[SequenceNum].SufPSNRY=SufPSNRY0[i+j];
Sequences[SequenceNum].Prebit=Prebit0[i+j];
Sequences[SequenceNum].Sufbit=Sufbit0[i+j];
Sequences[SequenceNum].Prebuf=Prebuf0[i+j];
Sequences[SequenceNum].Sufbuf=Sufbuf0[i+j];
SequenceNum++;
}
for(i=0;i<N;i++)
{
Sequences[SequenceNum].id=SequenceNum;
//Sequences[SequenceNum].name=name0[i+j];
Sequences[SequenceNum].PrePSNRY=PrePSNRY0[i+j];
Sequences[SequenceNum].SufPSNRY=SufPSNRY0[i+j];
Sequences[SequenceNum].Prebit=Prebit0[i+j];
Sequences[SequenceNum].Sufbit=Sufbit0[i+j];
Sequences[SequenceNum].Prebuf=Prebuf0[i+j];
Sequences[SequenceNum].Sufbuf=Sufbuf0[i+j];
SequenceNum++;
}
}
break;
}
}