-
大小: 13KB文件類型: .cpp金幣: 1下載: 0 次發(fā)布日期: 2021-06-04
- 語言: C/C++
- 標簽:
資源簡介
數(shù)據(jù)結(jié)構(gòu)課設運動會分數(shù)統(tǒng)計
C++源碼
需要的拿去
代碼片段和文件信息
#include???//對cin,cout的值做操縱
#include??//用于文件的操作
#include??//用于數(shù)值交還
#define?MAXSIZE?40??//定義表的最大長度用以存儲記錄???
#define?n?20????//學校數(shù)
#define?m?20???//男子項目數(shù)?
#define?w?20???//女子項目數(shù)?
//定義結(jié)構(gòu)體變量,存儲關鍵字
typedef?struct??ElemType
{?//成績記錄類型
int?item_no;???????????????????//項目編號
char?item_name[20];????????????//項目名稱
int?school_no;?????????????????//學校編號
char?school_name[20];??????????//學校名稱
int?place;?????????????????????//前五前三名
int?score;?????????????????????//得分
int?order;?????????????????????//名次
};
//順序表結(jié)構(gòu)類型List
typedef?struct?List?
{
ElemType*?element;
int?length;
};
void?ClearList(List?&L)//清空線性表
{
if?(L.element!=NULL)?{
delete?[]L.element;
L.element=NULL;
}
L.length=0;
}
void??InitList(List?&L)?//初始化線性表
{
L.element=new?ElemType[MAXSIZE];
if?(L.element==NULL)
{cout<<“內(nèi)存為空“< exit(1);
}
L.length=0;
??????????????????????????
}
bool?InsertList(List?&LElemType?itemint?x)???//插入數(shù)據(jù)元素x
{????if?(L.length?>MAXSIZE)
{cout<<“上溢!“< if?(x<1||x>L.length+1)?
{cout<<“位置異?!? if?(L.length==MAXSIZE)?{
int?k=sizeof(ElemType);
L.element=(ElemType*)realloc(L.element2*MAXSIZE*k);
if?(L.length==NULL)
{cout<“動態(tài)可分配的存儲空間用完,退出運行!“< exit(1);
}
}
for(?int?j=L.length-1;j>=x-1;j--)??????????????
??L.element[j+1]=L.element[j];
L.element[x-1]=item;
L.length++;
ofstream?f1(“運動會數(shù)據(jù).txt“ios::app);//打開記錄文本
f1.write((char*)&L.element[x-1]sizeof(ElemType));?//把插入線性表的元素寫入文件
return?true;
}
bool?DeleteList(List?&Lint?x)???//刪除某個元素
{
if?(L.length==0)?{
cout<<“線性表為空,刪除無效!“< return?false;
}
if?(x<0||x>L.length)?{
cout<<“輸入值無效!“< return?false;
}
for(int?i=x;i L.element[i-1]=L.element[i];//記錄刪除后后面的記錄依次向前進位
????L.length--;
????cout<<“刪除成功!“< return?true;
}
int?LenthList(List?&L)????//得到線性表的長度
{
return?L.length;
}
void?PrintElement(List?&Lint?x)???//得到線性表中指定序號為x的元素
{
if?(x<1||x>L.length)
{
???? cout<<“所給的值越界!“< ???return;
}??
//給定一定寬度存放數(shù)據(jù)
???? cout< “學校名稱“<
????cout< L.element[x-1].school_no< setw(10)< ????????cout< }
bool?ReadFileTxt(List?&L)???????//生成數(shù)據(jù)文本
{
ifstream?f1(“運動會數(shù)據(jù).txt“ios::in|ios::out);???????????//對文件可進行輸入輸出操作
ElemType?x;
if(f1.read((char*)&xsizeof(ElemType))) ????????????//判斷文件中是否有資料
{
cout< “學校名稱“< f1.seekg(0);????????????????????//把文件指針移到文件的開始位置
}
else?
cout<<“文件中無資料,請先輸入成績!“<
- 上一篇:C++課程設計飛機訂票系統(tǒng)
- 下一篇:vs mfc opengl配置教程
評論
共有 條評論