?? find.cpp
字號:
// Find.cpp: implementation of the CFind class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Find.h"
#include "Student.h"
#include "ManageStudent.h"
#include <iostream>
#include<iomanip>
#include<sstream>
#include<fstream>
#include<vector>
#include <string>
#include "Oncredit.h"
using namespace std;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ostream&operator<<(ostream&os,const CStudent&st);
extern CManageStudent*pBase;
void CFind::ShowMenu(){
cout<<endl;
cout<<"*************************查找*************************\n";
cout<<"1 按名字查找\t2 查找高分\t3 查找低分\t4學分查找\t0 退出\n";
cout<<"******************************************************\n";
}
void CFind::DoEvent(int ID)
{
switch(ID)
{
case 1:
OnFindName();
break;
case 2:
OnFindHighScore();
break;
case 3:
OnFindLowScore();
break;
case 4:
OnFindcredit();
break;
case 0:
cout<<"退出查找菜單\n";
pBase=parent;
delete this;
break;
default:
OnInvalidateInput("輸入1,2,3,0");
break;
}
}
void CFind::OnFindName()
{
string name;
cout<<"輸入要查找的學生姓名:";
cin>>name;
vector<CStudent>::iterator it=data.begin();
string tmp;
bool first=true;
while(it!=data.end())
{
if((*it).Name()==name)
{
if(first)
{
for(int i=0;i<8;i++)
cout<<setw(wid[i])<<title[i];
cout<<endl;
first=false;
}
cout<<*it<<endl;
}
it++;
}
}
void CFind::OnFindHighScore()
{
string score_name;
cout<<"輸入課程名:";
cin>>score_name;
int num=0,index=3;
while(index<8)//算出用戶輸入的是第幾門課程
{
if(title[index]==score_name)
break;
index++;
}
vector<CStudent>::iterator it=data.begin();
if(index>=8)
{
cout<<"課程名不對\n";
return;
}
int score;
cout<<"輸入成績:";
cin>>score;
bool first=true;
while(it!=data.end())
{
if((*it)[index-3]>=score)
{
if(first)
{
first=false;
for(int i=0;i<8;i++)
cout<<setw(wid[i])<<title[i];
cout<<endl;
}
cout<<*it<<endl;
num++;
}
it++;
}
cout<<"\n共有"<<num<<"位同學的《"<<score_name<<"》的成績不低于"<<score<<endl;
}
void CFind::OnFindLowScore()
{
string score_name;
cout<<"輸入課程名:";
cin>>score_name;
int num=0,index=3;
while(index<8)//算出用戶輸入的是第幾門課程
{
if(title[index]==score_name)
break;
index++;
}
vector<CStudent>::iterator it=data.begin();
if(index>=8)
{
cout<<"課程名不對\n";
return;
}
int score;
cout<<"輸入成績:";
cin>>score;
bool first=true;
while(it!=data.end())
{
if((*it)[index-3]<=score)
{
if(first)
{
first=false;
for(int i=0;i<8;i++)
cout<<setw(wid[i])<<title[i];
cout<<endl;
}
cout<<*it<<endl;
num++;
}
it++;
}
cout<<"\n共有"<<num<<"位同學的《"<<score_name<<"》的成績不高于"<<score<<endl;
}
void CFind::OnFindcredit(){
CFind*pBase=0;
pBase=new COncredit(pBase);
pBase->ShowMenu();
int ID;
cin>>ID;
pBase->DoEvent(ID);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -