?? test.cpp
字號:
#include <iostream>
#include "linkstudent.h"
#include "student.h"
#include "liststudent.h"
#include "mainmenu.h"
#include "findmenu.h"
const static NAME = 40;
const static SNO = 20;
using namespace std;
void main()
{
//創建學生信息
// Student stu[6] = {
// Student("cd","1000",23,'m'),
// Student("ab","1002",25,'m'),
// Student("jk","1004",24,'m'),
// Student("baby","1005",22,'f'),
// Student("gf","1007",23,'f'),
// Student("sakura","1006",22,'f')
// };
//添加學生成績
// stu[0].set_pfm(80,90,56);
// stu[1].set_pfm(75,68,63);
// stu[2].set_pfm(90,98,86);
// stu[3].set_pfm(76,80,84);
// stu[4].set_pfm(60,56,38);
// stu[5].set_pfm(78,88,98);
Liststudent list;//學生鏈表
// Linkstudent link_stu; //
//添加學生信息到鏈表
// for(int i = 0; i < 5; i++)
// list.insert(stu[i]);
// list.append(stu[5]);
list.read_stuInfo(); //從studentInfo.txt文件中讀取數據,并將其加入到list鏈表
//進入主菜單循環
while(true )
{
m_menu();//顯示主菜單
char option; //主菜單選項
cout << "Enter your choice(q to quit):";
cin >> option;
if (option == 'q')
break; //退出主程序
switch(option)
{
////////////////////當選查看學生信息的操作////////////////
case '1':
{
while(true)
{
mfindstu();
char op;
cout << "Enter your choice(q to 上一層):";
cin >> op;
if('q' == op)
break;
cin.get();
if(op == '1')
list.show_all();
else if('2' == op)
{
char na[NAME];
cout << "\n請輸入待查學生姓名(quit to quit):";
cin.getline(na,NAME);
while(strcmp(na,"quit"))
{
Linkstudent * t = list.find_n(na);
if(t != NULL)
t->stu.showall();
else cout<<" \nthere isn't the student!"<<endl;
cin.clear();
cin.sync();
cout << "請輸入待查學生姓名(quit to quit):" << endl;
cin>>na;
cin.get();
}//end while
}//end if
else if('3' == op)
{
char snu[20];
cout << "請輸入待查學生學號:";
cin>>snu;
cin.get();
while(strcmp(snu,"quit"))
{
Linkstudent * t = list.find_sn(snu);
if(t != NULL)
t->stu.showall();
else cout<<" there isn't the student!"<<endl;
cin.clear();
cin.sync();
cout << "Enter quit to quit:";
cin>>snu;
cin.get();
}
}//endif
} //end while
} //end case 1
break;
/////////////////////修改學生信息的操作////////////////////////////
case '2':
{
cin.get();
char modify_sn[SNO];
list.show_all();
cout << endl << endl;
cout << "請輸入所修改學生學號:";
cin.getline(modify_sn,SNO);
Linkstudent *modify_st = list.find_sn( modify_sn );
if(modify_st)
{
cout << "所修改學生信息為:" << endl;
modify_st->stu.showall();
cout << endl << endl;
cout << "請選擇所修改信息:" << endl << endl;
cout << "1 學號\t2 姓名\t3 性別\t4 年齡\t5 語文\t6 數學\t7 英語"<<endl<<endl;
cout << "(q to quit)!:";
while(true)
{
char modify_op;
cin >> modify_op;
if('q' == modify_op)
break;
//while(cin && cin.get() != '\n')
//continue;
switch(modify_op)
{
case '1':
{
char modi_sn[SNO];
cin.get();
cout << "請輸入新學號:";
cin.getline(modi_sn,SNO);
modify_st->stu.set_sn(modi_sn);
cout << "修改后學生信息為:\n";
modify_st->stu.showall();
cout << endl << endl;
}break;
case '2':
{
char modi_n[NAME];
cin.get();
cout << "請輸入新姓名:";
cin.getline(modi_n,NAME);
modify_st->stu.set_name(modi_n);
cout <<endl;
cout << "修改后學生信息為:\n";
modify_st->stu.showall();
cout << endl;
}break;
case '3':
{
while(true)
{
cin.get();
cout << "請輸入新性別(f or m):";
char modi_s;
cin >> modi_s;
if(modi_s == 'f' || modi_s == 'm')
{
cout << endl;
modify_st->stu.set_sex(modi_s);
cout << "修改后學生信息為:\n";
modify_st->stu.showall();
cout << endl << endl;
break;
}
}//end while
}break; //end case '3'
case '4':
{
while(true)
{
cin.get();
cout << "請輸入新年齡(2 to 98):";
int modi_a;
cin >> modi_a;
if(modi_a >= 2 && modi_a <=98)
{
modify_st->stu.set_age(modi_a);
modify_st->stu.showall();
break;
}
}// end while
}break;//end case '4'
case '5':
{
while(true)
{
cin.get();
cout << "請輸入新語文成績(0 to 150):";
int modi_y;
cin >> modi_y;
if(modi_y >= 0 && modi_y <=150)
{
modify_st->stu.set_chinese(modi_y);
modify_st->stu.showall();
break;
}
}// end while
}break;//end case '5'
case '6':
{
while(true)
{
cin.get();
cout << "請輸入新數學成績(0 to 150):";
int modi_m;
cin >> modi_m;
if(modi_m >= 0 && modi_m <=150)
{
modify_st->stu.set_math(modi_m);
modify_st->stu.showall();
break;
}
}// end while
}break;//end case '6'
case '7':
{
while(true)
{
cin.get();
cout << "請輸入新英語成績(0 to 150):";
int modi_e;
cin >> modi_e;
if(modi_e >= 0 && modi_e <=150)
{
modify_st->stu.set_english(modi_e);
modify_st->stu.showall();
break;
}
}// end while
}break;//end case '7'
}//end switch
cout << "請選擇所修改信息:" << endl;
cout << "1 學號\t2 姓名\t3 性別\t4 年齡\t5 語文\t6 數學\t7 英語"<<endl;
cout << "(q to quit)!:";
}// end while
}//end if
}//end case 2
break;
/////////////////////////添加學生信息的操作////////////////////////////
case '3':
{
char insert_sn[SNO];
char insert_n[NAME];
int insert_a;
char insert_s;
int insert_y = 0;
int insert_m = 0;
int insert_e = 0;
while(cin && cin.get() != '\n')
cin.get();
cout << "請輸入學號:" ;
cin.getline(insert_sn,SNO);
while( list.find_sn(insert_sn) )
{
cout << "該學號已存在,請重新輸入:";
cin.getline(insert_sn,SNO);
}
cout << "請輸入姓名:";
cin.clear();
cin.sync();
cin.getline(insert_n,NAME);
cout << "請輸入年齡:";
cin >> insert_a;
while(insert_a < 2 || insert_a > 98)
{
cout << "該年齡無效,請重新輸入:";
cin.clear();
cin.sync();
cin >> insert_a;
}
cout << "請輸入性別(M or F):";
cin >> insert_s;
while(insert_s != 'F' && insert_s != 'M')
{
cout << "再仔細想一下你的性別吧(M or F):";
cin.clear();
cin.sync();
cin >> insert_s;
}
char answer;
cout << "要輸入分數么?(Y or N)";
cin >> answer;
while(true)
{
if( answer == 'y')
{
cin.clear();
cin.sync();
cout << "請輸入語文分數(0~150):";
cin >> insert_y;
while(insert_y < 0 || insert_y > 150)
{
cout << "分數不對,請重新輸入!(0~150):";
cin.clear();
cin.sync();
cin >> insert_y;
}
cout << "請輸入數學分數(0~150):";
cin >> insert_m;
while(insert_m < 0 || insert_m > 150)
{
cout << "分數不對,請重新輸入!(0~150):";
cin.clear();
cin.sync();
cin >> insert_m;
}
cout << "請輸入英語分數(0~150):";
cin >> insert_e;
while(insert_e < 0 || insert_e > 150)
{
cout << "分數不對,請重新輸入!(0~150):";
cin.clear();
cin.sync();
cin >> insert_e;
}
break;
}//endif
else if( answer == 'n')
{
cin.clear();
cin.sync();
break;
}
cout << "y or n:";
cin.clear();
cin.sync();
cin >> answer;
}//end while
Student insert_stu(insert_n,insert_sn,insert_a,insert_s,insert_y,insert_m,insert_e);
list.insert(insert_stu);
cout << "所添加學生信息是:" << endl;
insert_stu.showall();
} //end case 3
break;
////////////////////////刪除學生信息的操作////////////////////////////
case '4':
{
cin.get();
int dele_op;
cout << "1 按學號刪除:" << endl;
cout << "2 按姓名刪除:" << endl;
cin >> dele_op;
if(dele_op == 1)//按照學號刪除學生信息
{
char dele_sn[SNO];
cout << "請輸入待刪學號:";
cin.get();
cin.getline(dele_sn,SNO);
Linkstudent * t = list.find_sn(dele_sn);
if( t )
{
cout << "該學生信息為:"<<endl;
t->stu.showall();
char dele_an;
cout << "確定要刪除么?(y or n)";
cin >> dele_an;
while(true)
{
if(dele_an == 'y')
{
list.remvoe_sn(dele_sn);
break;
}
else if(dele_an == 'n')
break;
else
{
cout << "確定要刪除么?(y or n)";
cin >> dele_an;
}
}//endwhile
}//endif
else
cout << "沒有該學生!"<<endl;
}//endif
if(2 == dele_op)// 按照姓名刪除學生信息
{
char dele_n[NAME];
cout << "請輸入待刪姓名:";
cin.get();
cin.getline(dele_n,NAME);
Linkstudent * t = list.find_n(dele_n);
if( t )
{
cout << "該學生信息為:"<<endl;
t->stu.showall();
char dele_an;
cout << "確定要刪除么?(y or n)";
cin >> dele_an;
while(true)
{
if(dele_an == 'y')
{
list.remove_n(dele_n);
break;
}
else if(dele_an == 'n')
break;
else
{
cout << "確定要刪除么?(y or n)";
cin >> dele_an;
}
}//endwhile
}//endif
else
cout << "沒有該學生!" << endl;
}//endif
}//end case 4
break;
////////////////////////////成績統計////////////////////////////
case '5':
{
cin.get();
int inall_op;
int inall_begin;
int inall_end;
cout << "請選擇要統計的課程:" << endl;
cout << "1 語文\t2 數學\t3 英語"<<endl<<endl;
cin>>inall_op;
cout << "請輸入要統計的分數段:" << endl;
cin>>inall_begin>>inall_end;
switch(inall_op)
{
case 1:
{
Linkstudent *x=list.get_first ();
Linkstudent *temp = x->next;
int i;
while(temp)
{
i=temp->stu.get_chinese();
//cout<<endl<<i<<endl;
if(inall_begin<=i && i<=inall_end)
list.find_chinese(i);
temp=temp->next ;
}
}
break;
case 2:
{
Linkstudent *x=list.get_first ();
Linkstudent *temp = x->next;
int i;
while(temp)
{
i=temp->stu.get_math();
//cout<<endl<<i<<endl;
if(inall_begin<=i && i<=inall_end)
list.find_math(i);
temp=temp->next ;
}
}
break;
case 3:
{
Linkstudent *x=list.get_first ();
Linkstudent *temp = x->next;
int i;
while(temp)
{
i=temp->stu.get_math();
//cout<<endl<<i<<endl;
if(inall_begin<=i && i<=inall_end)
list.find_math(i);
temp=temp->next ;
}
}
break;
}
break;
////////////////////////////排序////////////////////////////////
case '6':
{
cin.get();
int order_op;
int order_sort;
cout << "請選擇要排序的課程:" << endl;
cout << "1 語文\t2 數學\t3 英語\t4 總分"<<endl<<endl;
cin>>order_op;
cout << "請選擇排序的方式:" << endl;
cout << "1 升序\t2 降序"<<endl<<endl;
cin>>order_sort;
if(order_sort==1)
{
list.sort_ascending(order_op);//冒泡法升序排序
}
else
list.sort_descending(order_op);//冒泡法降序排序
list.show_all();//顯示排序后的結果
}
break;
case '7':
{
list.save_stuInfo();//保存數據到文件
}
break;
default:
break;
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -