?? c++學生系統代碼3.txt
字號:
#include<iostream>
#include<fstream>
#include<string>
#include <iomanip>
#include<windows.h>
#include<ctime>
using namespace std;
const int NAME_NUM=30;
struct student
{
char name[NAME_NUM];
float num;
float chinaNum;
float englishNum;
float mathNum;
float average;
float result;
int pos;
student *next;
};
void Print(student *head);
void InsertFront(student* &head, student *pNew);
void InsertRear(student* &head, student *pNew);
student* Find(student *head, char *findStr, char type);
student* Read();
void Write(student* head);
void ShowList(student* head);
int GetLength(student* head);
void Delete(student* &head, char *delStr,int delNum);
void FindMaxOrMin(student *head,char type,char maxOrMin);
void Reword(student *pStd);
void Sort(student *&head, char type,char maxOrMin);
void Count(student *&head);
void DeleteAll(student *&head);
bool Enter(char type);
void SetTitle(bool isLoad);
void AboutMe();
void ChaXun(string str,student *head);
void PaiMing(string str, student* head);
void ShanChu(string str, student *&head);
void XianShi(string str, student *head);
void XuiGai(string str, student *&head);
void ZengJia(string str, student* &head);
int Run();
bool Enter(char type)
{
ofstream out("Password.pwd",ios::app);
ifstream in("Password.pwd");
string s[2];
int num=0;
string zhangHao;
string miMa;
while(!in.eof())
{
in>>s[num];
num++;
if(num==2)
{
break;
}
}
if(s[0].compare("")==0 || type=='2' )
{
if(s[0].compare("")==0 && type!='2')
{
cout<<"你是第一次使用本程序,請設置帳號和密碼."<<endl;
}
else
{
bool isLoad=false;
isLoad=Enter('1');
if(isLoad==true)
{
cout<<"修改用戶."<<endl;
out.close();
out.open("Password.pwd",ios::trunc);
}
else
{
cout<<"你輸入的密碼錯誤."<<endl;
cout<<"你不是管理員不能修改密碼."<<endl;
return false;
}
}
cout<<"請輸入您的新帳號: ";
cin>>s[0];
cout<<"請輸入您的新密碼: ";
cin>>s[1];
string s1,s2;
for(int i=0; i<s[0].size(); i++)
{
s1+=char(int(s[0][i])+11);
}
for( i=0; i<s[1].size(); i++)
{
s2+=char(int(s[1][i])+11);
}
s[0]=s1;
s[1]=s2;
for( i=0; i<=1; i++)
{
out<<s[i]<<" ";
}
out.close();
}
string s1,s2;
for(int i=0; i<s[0].size(); i++)
{
s1+=char(int(s[0][i])-11);
}
for( i=0; i<s[1].size(); i++)
{
s2+=char(int(s[1][i])-11);
}
cout<<"請輸入您的帳號: ";
cin>>zhangHao;
cout<<"請輸入您的密碼: ";
cin>>miMa;
if(zhangHao.compare(s1)==0 && miMa.compare(s2)==0)
{
return true;
}
else
{
return false;
}
return false;
}
void Print(student *head)
{
student *pHead=head;
int num=strlen(head->name);
while(head)
{
if(num<strlen(head->name))
{
num=strlen(head->name);
}
head=head->next;
}
head=pHead;
cout<<setw(num)<<head->name<<setw(8)
<<head->num<<setw(10)<<head->chinaNum
<<setw(10)<<head->mathNum<<setw(10)
<<head->englishNum<<setw(8)<<head->result
<<setw(8)<<head->average<<setw(5)<<head->pos<<endl;
}
void ShowList(student* head)
{
cout<<"姓名:"<<setw(8)<<"座號:"<<setw(10)
<<"語文分數:"<<setw(10) <<"數學分數:"
<<setw(10)<<"英語分數:"<<setw(8)<<"總分數:"
<<setw(8)<<"平均分:"<<setw(6)<<"名次:"<<endl<<endl;
while(head)
{
Count(head);
Print(head);
head=head->next;
}
cout<<endl;
}
void Write(student* head)
{
ofstream out("Student.dat",ios::trunc);
while(head)
{
Count(head);
out.write((char*)head,sizeof(student));
head=head->next;
}
out.close();
}
student* Read()
{
ifstream in("Student.dat");
student *head;
student *pP;
student *pEnd;
pP=new student;
pEnd=head=pP;
student *pS=new student;
memset(pS->name,0,NAME_NUM);
in.read((char*)pS,sizeof(student));
if(strcmp(pS->name,"\0")==0)
{
return NULL;
}
strcpy(pP->name,pS->name);
pP->num=pS->num;
pP->chinaNum=pS->chinaNum;
pP->englishNum=pS->englishNum;
pP->mathNum=pS->mathNum;
while(!in.eof())
{
in.read((char*)pS,sizeof(student));
pEnd->next=pP;
pEnd=pP;
pP=new student;
strcpy(pP->name,pS->name);
pP->num=pS->num;
pP->chinaNum=pS->chinaNum;
pP->englishNum=pS->englishNum;
pP->mathNum=pS->mathNum;
}
pEnd->next=NULL;
delete pP;
return head;
}
student* Find(student *head,char *findStr, char type)
{
/*參數說明:
type=='1' 按 名字 查找
type=='2' 按 座號 查找
type=='3' 按 語文 查找
type=='4' 按 數學 查找
type=='5' 按 英語 查找
type=='6' 按 總分 查找
type=='7' 按 平均分 查找
type=='8' 按 排名 查找 //沒有實現
*/
bool isFind=false;
student *firstStd=NULL;
cout<<"姓名:"<<setw(8)<<"座號:"<<setw(10)
<<"語文分數:"<<setw(10) <<"數學分數:"
<<setw(10)<<"英語分數:"<<setw(8)<<"總分數:"
<<setw(8)<<"平均分:"<<setw(5)<<"名次:"<<endl<<endl;
while(head)
{
if(type=='1')
{
if(strcmp(head->name,findStr)==0)
{
if(firstStd==NULL)
{
firstStd=head;
}
Print(head);
isFind=true;
if(head->next==NULL)
{
return firstStd;
}
}
}
else if(type=='2')
{
if(int(head->num)==int(atof(findStr)))
{
if(firstStd==NULL)
{
firstStd=head;
}
Print(head);
isFind=true;
if(head->next==NULL)
{
return firstStd;
}
}
}
else if(type=='3')
{
if(int(head->chinaNum)==int(atof(findStr)))
{
if(firstStd==NULL)
{
firstStd=head;
}
Print(head);
isFind=true;
if(head->next==NULL)
{
return firstStd;
}
}
}
else if(type=='4')
{
if(int(head->mathNum)==int(atof(findStr)))
{
if(firstStd==NULL)
{
firstStd=head;
}
Print(head);
isFind=true;
if(head->next==NULL)
{
return firstStd;
}
}
}
else if(type=='5')
{
if(int(head->englishNum)==int(atof(findStr)))
{
if(firstStd==NULL)
{
firstStd=head;
}
Print(head);
isFind=true;
if(head->next==NULL)
{
return firstStd;
}
}
}
else if(type=='6')
{
if(int(head->result)==int(atof(findStr)))
{
if(firstStd==NULL)
{
firstStd=head;
}
Print(head);
isFind=true;
if(head->next==NULL)
{
return firstStd;
}
}
}
else if(type=='7')
{
if(int(head->average)==int(atof(findStr)))
{
if(firstStd==NULL)
{
firstStd=head;
}
Print(head);
isFind=true;
if(head->next==NULL)
{
return firstStd;
}
}
}
else if(type=='8')
{
if(int(head->pos)==int(atof(findStr)))
{
if(firstStd==NULL)
{
firstStd=head;
}
Print(head);
isFind=true;
if(head->next==NULL)
{
return firstStd;
}
}
}
head=head->next;
}
if(isFind==false)
{
cout<<"找不到你要找的記錄."<<endl;
return NULL;
}
return firstStd;
}
void InsertRear(student* &head,student *pNew)
{
student *pEnd,*pHead,*pS=new student;
if(head==NULL)
{
InsertFront(head,pNew);
return ;
}
pHead=head;
while(head)
{
pEnd=head;
if(head->next==NULL)
{
break;
}
head=head->next;
}
strcpy(pS->name,pNew->name);
pS->num=pNew->num;
pS->chinaNum=pNew->chinaNum;
pS->englishNum=pNew->englishNum;
pS->mathNum=pNew->mathNum;
pS->next=NULL;
pEnd->next=pS;
head=pHead;
}
void InsertFront(student* &head, student *pNew)
{
student *pHead=new student;
strcpy(pHead->name,pNew->name);
pHead->num=pNew->num;
pHead->chinaNum=pNew->chinaNum;
pHead->englishNum=pNew->englishNum;
pHead->mathNum=pNew->mathNum;
pHead->next=head;
head=pHead;
}
int GetLength(student *head)
{
int len=0;
while(head)
{
len++;
head=head->next;
}
return len;
}
void Delete(student* &head, char *delStr,int delNum)
{
student* pDel,*pNew,*pHead;
bool isFind=false;
pHead=head;
if(strcmp(head->name,delStr)==0)
{
pNew=head->next;
delete head;
head=pNew;
if(delNum==2)
{
cout<<endl<<"因為要刪除的記錄在前面,所有只刪除第一記錄."<<endl;
}
return ;
}
while(head->next)
{
if(delNum==2)
{
if(strcmp(head->next->name,delStr)==0)
{
pNew=head->next->next;
pDel=head->next;
delete pDel;
head->next=pNew;
head=pHead;
isFind=true;
}
}
else
{
if(strcmp(head->next->name,delStr)==0)
{
pNew=head->next->next;
pDel=head->next;
delete pDel;
head->next=pNew;
head=pHead;
return ;
}
}
head=head->next;
}
head=pHead;
if(isFind==false)
{
cout<<"找不到你要刪除的記錄."<<endl;
}
else
{
cout<<"刪除記錄成功."<<endl;
}
}
void FindMaxOrMin(student *head,char type,char maxOrMin)
{
/*參數說明:
type=='1' 按 語文 查找
type=='2' 按 數學 查找
type=='3' 按 英語 查找
type=='4' 按 總分 查找
type=='5' 按 平均分 查找
type=='6' 按 排名 查找
*/
int maxNum;
student *pHead=head;
if(type=='1')
{
maxNum=int(head->chinaNum);
}
else if (type=='2')
{
maxNum=int(head->mathNum);
}
else if (type=='3')
{
maxNum=int(head->englishNum);
}
else if (type=='4')
{
maxNum=int(head->result);
}
else if (type=='5')
{
maxNum=int(head->average);
}
else if (type=='6')
{
maxNum=head->pos;
}
else
{
cout<<"你輸入錯誤,請重新輸入."<<endl;
return ;
}
while(head)
{
if(maxOrMin=='1')
{
if(type=='1')
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -