使用命名空間std//﹌﹌﹌﹌" />
ǰλã̌WȫW - Z - 編程互動作業

編程互動作業

// 2.cpp:定義控制臺應用程序的入口點。

//

#包含" stdafx.h "

# include & ltiostream & gt

# include & ltfstream & gt

# include & ltstring.h & gt

# include & ltconio.h & gt//使用getch();

使用命名空間std

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌򞻸򞻸򞻸򞻸6

班級學生

{

公共:

char name[20];

char Id[20];

int Cnum//C課程成績

int Mnum//數學課程成績

int枚舉;//英語課程成績

int sum//總分

學生*下壹個;

無效輸入()

{

cout & lt& lt" \ t \ t \請輸入學生的姓名:";CIN & gt;& gt姓名;

cout & lt& lt" \ t \ t \請輸入學生ID:";CIN & gt;& gtid;

cout & lt& lt" \ t \ t \請輸入課程C的等級:";CIN & gt;& gtCnum

cout & lt& lt" \ t \ t \請輸入數學課程分數:";CIN & gt;& gtMnum

cout & lt& lt" \ t \ t \請輸入英語課程的分數:";CIN & gt;& gt枚舉;

sum = Cnum+Mnum+Enum;

}

void ReadFile(istream & amp;在)

{

在& gt& gt名稱& gt& gtId & gt& gtCnum & gt& gtMnum & gt& gt枚舉& gt& gt總和;

}

無效顯示()

{

cout & lt& lt"名稱:"

& lt& lt"數學:"

}

};

//﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ 򞻸 6510

班級學生按摩

{

公共:

student message();

~ student message();

void ShowMenu();

void Find();

void Save();

void modify item();

void remove item();

void Swap(Student *,Student *);

void Sort();

//void un pass();

int list count();

//void平均值();

空顯示()

{

for(Student * p = Head->;接下來;p!=結束;p = p-& gt;下壹個)

p->;show();

cout & lt& lt“輸入任意字符!繼續……”;

getch();

}

void AddItem()

{

end->;input();

end->;下壹個=新生;

End = End-& gt;接下來;

cout & lt& lt“添加成功!”& lt& ltendl

cout & lt& lt“輸入任意字符!繼續……”;

getch();

}

私人:

學生*頭,*尾;

ifstream in

ofstream out

學生*FindItem(char * name)

{

for(學生* p =頭;p->;下壹個!=結束;p = p-& gt;Next)//如果匹配成功,返回上壹個指針,否則為空。

如果(!strcmp(p-& gt;下壹個-& gt;name,name))返回p;

返回NULL

}

學生*FindID(char * Id)

{

for(學生* p =頭;p->;下壹個!=結束;p = p-& gt;Next)//如果匹配成功,返回上壹個指針,否則為空。

如果(!strcmp(p-& gt;下壹個-& gt;Id,Id))返回p;

返回NULL

}

};

//﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ 򞻸 ﹌ 6510

學生按摩::學生按摩()

{

頭=新生;

head->;下壹個=新生;

end = Head-& gt;接下來;

in . open(" sort . txt ");

如果(!在)

cout & lt& lt“這是壹個沒有學生信息的新系統。請先輸入。”& lt& ltendl

其他

{

而(!in.eof())

{

end->;ReadFile(in);

if(End-& gt;name[0]= = ' \ 0 ')break;

end->;下壹個=新生;

End = End-& gt;接下來;

}

in . close();

cout & lt& lt" \t\t \踩踏學生信息成功!"& lt& ltendl

}

}

//﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ 򞻸 򞻸 651

學生消息::~學生消息()

{

save();

for(學生*臨時;head->;下壹個!=結束;)

{

temp = Head-& gt;接下來;

head->;next = Head-& gt;下壹個-& gt;接下來;

刪除temp

}

刪除頭,尾;

}

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌򞻸򞻸򞻸65

void student message::show menu()

{

cout & lt& lt“〓〓〓〓〓〓〓〓〓〓☆〓〓〓〓〓〓〓〓〓〓〓〓〓〓1 & lt;endl

cout & lt& lt“〓〓〓〓〓〓〓★★★★★★★★★★★★★★★★〓〓〓〓〓〓〓"<;& ltendl

cout & lt& lt"〓〓〓〓〓〓〓〓☆973438+0.提高學生的成績☆〓〓〓〓〓〓〓〓〓〓〓〓" & lt;endl

cout & lt& lt〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓12 <endl

cout & lt& lt"〓〓〓〓〓〓〓〓〓〓☆ 3.分類統計☆〓〓〓〓〓〓〓〓〓〓〓〓& lt;endl

cout & lt& lt〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓12 <endl

cout & lt& lt“〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓& lt;endl

cout & lt& lt"〓〓〓〓〓〓〓〓〓〓☆ 6.修改學生信息☆〓〓〓〓〓〓〓〓〓〓〓〓& lt;endl

cout & lt& lt"〓〓〓〓〓〓〓〓〓〓☆ 0.安全離開system☆〓〓〓〓〓〓〓〓〓〓〓〓& lt;endl

cout & lt& lt" \ n \ t \ t \ n \ t \請選擇:";

}

//﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ 򞻸 򞻸 651

void student message::Find()

{

字符名稱[20],Id[10];

int x;

學生* p = NULL

cout & lt& lt”\ n \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n”;

cout & lt& lt" \ t \ t等於1。按學生姓名搜索\ n \ t \ t執行2。按學生的學號搜索”;

cout & lt& lt" \ n \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * *請選擇:";

CIN & gt;& gtx;

開關(x)

{

案例1:{ cout & lt;& lt" \ t \ t \請輸入您要找的學生的姓名:";CIN & gt;& gt姓名;

if(p=FindItem(name))

{

p->;下壹個-& gt;show();

cout & lt& lt“輸入任意字符!繼續……”;

getch();

}

其他

{

cout & lt& lt" \ t \ t \ t找不到叫這個名字的學生!"& lt& lt\ n ' & lt& ltendl

cout & lt& lt“輸入任意字符!繼續……”;

getch();

}

}破;

案例二:

{

cout & lt& lt" \ t \ t \請輸入您要查找的學生的學號:";CIN & gt;& gtid;

if(p=FindID(Id))

{

p->;下壹個-& gt;show();

cout & lt& lt“輸入任意字符!繼續……”;

getch();

}

其他

{

cout & lt& lt" \ t \ t \ t沒有發現學生學得好!"& lt& lt\ n ' & lt& ltendl

cout & lt& lt“輸入任意字符!繼續……”;

getch();

}

}破;

}

}

//﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ 򞻸 ﹌ 6510

Void學生消息::modify item()//修改信息

{

char name[20];

學生* p = NULL

cout & lt& lt" \ t \ t \請輸入要修改的人的姓名:";CIN & gt;& gt姓名;

if(p=FindItem(name))

{

cout & lt& lt\ t \ t \已找到學生信息,請輸入新信息& lt& ltendl

p->;下壹個-& gt;input();

cout & lt& lt“修改成功!”& lt& ltendl

cout & lt& lt“輸入任意字符!繼續……”;

getch();

}

其他

{

cout & lt& lt" \ t \ t \找不到!"& lt& ltendl

cout & lt& lt“輸入任意字符!繼續……”;

getch();

}

}

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌򞻸﹌򞻸651

Void學生按摩::remove item()//刪除信息。

{

char name[20];

學生* p =空,*臨時=空;

cout & lt& lt" \ t \ t \請輸入要刪除的學生姓名:"

if(p=FindItem(name))

{

temp = p-& gt;接下來;

p->;next = p-& gt;下壹個-& gt;接下來;

刪除temp

cout & lt& lt"成功刪除!"& lt& ltendl

cout & lt& lt“輸入任意字符!繼續……”;

getch();

}

其他

{

cout & lt& lt" \ t \ t \找不到!"& lt& ltendl

cout & lt& lt“輸入任意字符!繼續……”;

getch();

}

}

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌

void student mass::swap(student * p 1,student * p2)//交換兩個combox變量的數據字段。

{

Student * temp =新生;

strcpy(temp-& gt;名稱,p 1->;姓名);

strcpy(temp-& gt;Id,p 1->;id);

temp->;cnum = p 1->;Cnum

temp->;mnum = p 1->;Mnum

temp->;Enum=p1->枚舉;

temp->;sum = p 1->;總和;

strcpy(p 1->;名稱,p2-& gt;姓名);

strcpy(p 1->;Id,p2-& gt;id);

p 1->;cnum = p2-& gt;Cnum

p 1->;mnum = p2-& gt;Mnum

p 1->;enum = p2-& gt;枚舉;

p 1->;sum = p2-& gt;總和;

strcpy(p2-& gt;名稱,臨時-& gt;姓名);

strcpy(p2-& gt;Id,temp-& gt;id);

p2->;cnum = temp-& gt;Cnum

p2->;mnum = temp-& gt;Mnum

p2->;enum = temp-& gt;枚舉;

p2->;sum = temp-& gt;總和;

}

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌

intstudentmessage::list Count()//計算當前鏈表中的記錄總數,並返回壹個整數。

{

如果(!頭)

返回0;

int n = 0;

for(Student * p = Head->;接下來;p!=結束;p = p-& gt;下壹個)

{

n++;

}

返回n;

}

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌

void student message::Sort()//對當前鏈表進行排序。

{

cout & lt& lt"排序..."& lt& ltendl

學生*p=NULL,*p1=NULL,* k = NULL

int n = student message::list count();

如果(n & lt2)

返回;

for(p = Head-& gt;接下來;p!=結束;p = p-& gt;下壹個)

for(k = p-& gt;接下來;k!=結束;k = k-& gt;下壹個)

{

如果(p->;sum & gtk-& gt;總和)

{

student message::Swap(p,k);

}

}

cout & lt& lt“排序完成!”& lt& ltendl

getch();

返回;

}

//﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ 򞻸 򞻸 651

void student message::Save()

{

out . open(" sort . txt ");

for(Student * p = Head->;接下來;p!=結束;p = p-& gt;下壹個)

out & lt& ltp->;名稱& lt& lt" \ t " & lt& ltp->;Id & lt& lt" \ t " & lt& ltp->;Cnum & lt& lt" \t "

& lt& ltp->;Mnum & lt& lt" \ t " & lt& ltp->;枚舉& lt& lt" \ t " & lt& ltp->;sum & lt& lt\ n ';

out . close();

}

//﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ ﹌ 򞻸 򞻸 651

int main()

{

int x,I = 0;

bool quit = false

cout & lt& lt" \ t \ t " & lt& ltendl

for(I = 0;我& lt3;i++)

cout & lt& lt" \ t \ t◎\ t \ t \ t \ t \ t◎;" & lt;& ltendl

cout & lt& lt" \t\t◎★★★歡迎使用學生成績管理系統★★★★◎;" & lt;& ltendl

for(I = 0;我& lt3;i++)

cout & lt& lt" \ t \ t◎\ t \ t \ t \ t \ t◎;" & lt;& ltendl

cout & lt& lt" \ t \ t \ n " & lt& ltendl;

學生按摩成績;

cout & lt& lt"按任意鍵開始...";

getch();

而(!退出)

{

系統(“cls”);

等級。ShowMenu();

CIN & gt;& gtx;

開關(x)

{

案例0:退出=真;打破;

案例1:年級。AddItem();打破;

案例二:年級。顯示();打破;

案例三:年級。sort();打破;

案例四:年級。find();打破;

案例五:年級。remove item();打破;

案例六:年級。modify item();打破;

}

}

返回0;

}

//改壹下就可以用了。這不是原創的

  • һƪ:Ҽgs՚܇ܴ늄Ӻȼ܇᣿
  • һƪ:ʲWvԿо ҪЩ
  • copyright 2024̌WȫW