求一个学生信息管理系统C++编写的,简单的信息,查询,删除就可以,谢谢了!

QQ348916135,有的发我邮箱上,谢谢!
2024-12-19 18:39:14
推荐回答(3个)
回答1:

#include
#include
#include

using namespace std;
int num;
const int MAX_NUM_OF_STUDENTS=1000;
struct Student
{ int no;
char name [20];
int computer;
int math;
int english;
int physics;
};
Student students[MAX_NUM_OF_STUDENTS];
Student name_students[MAX_NUM_OF_STUDENTS];
char choose;
extern int Input_project();
extern int Search_project();
extern int Delete_project();
extern int Modify_project();

int Face()//主界面
{
cout<<"\t\t\t~*~*~欢迎使用学生信息管理系统~*~*~"< cout<<"◇ 录入(I),"< <<"◇ 修改(M),"< cout<<"☆ 请输入您的选择(I,S,D,E):";
cin>>choose;
switch(choose)
{ case 'I':
case 'i': system("cls");Input_project();break;
case 'S':
case 's': system("cls");Search_project();break;
case 'D':
case 'd': system("cls");Delete_project();break;
case 'M':
case 'm': system("cls");Modify_project();break;
case 'E':
case 'e': system("cls");return -1;break;
default: cout<<" 输入错误!"< }
return 0;
}

int Input_project()//输入功能
{ choose='C';
for( ;choose=='C'||choose=='c';num++)
{ cout<<"Ο 学号:";
cin>>students[num].no;
cout<<"Ο 姓名:";
cin>>students[num].name;
cout<<"Ο 数学:";
cin>>students[num].math;
cout<<"Ο 英语:";
cin>>students[num].english;
cout<<"Ο 物理:";
cin>>students[num].physics;
cout<<"Ο 计算机:";
cin>>students[num].computer;
cout<<"☆ 继续或返回主菜单(C/E):";
cin>>choose;
if(choose=='E'||choose=='e') break;
}
num+=1;//num为总人数
int i=num;//以下是按no冒泡排序
bool exchange;
while(i>1)
{ exchange=false;
for( int k=0;k { if(students[k].no>students[k+1].no)
{ Student temp=students[k];
students[k]=students[k+1];
students[k+1]=temp;
exchange=true;
}
}
if (!exchange) break;
i--;
}
for (int t=0;t { name_students[t].no=students[t].no;
*strcpy(name_students[t].name,students[t].name);
name_students[t].math=students[t].math;
name_students[t].english=students[t].english;
name_students[t].computer=students[t].computer;
name_students[t].physics=students[t].physics;
}
while(i>1)//以下是按name冒泡排序
{ exchange=false;
for( int k=0;k { if(strcmp(name_students[k].name,name_students[k+1].name)>0)
{ Student temp=name_students[k];
name_students[k]=name_students[k+1];
name_students[k+1]=temp;
exchange=true;
}
}
if (!exchange) break;
i--;
}

FILE *fp=fopen("c:\\name.txt","a+");//存储两结构体数组
FILE *fp1=fopen("c:\\number.txt","a+");
if (fp == NULL||fp1 == NULL)//判断文件打开是否成功
{ cout<<"打开文件失败!"< return -1;
}
for(i=0;i { fwrite(&students[i],sizeof(Student),1,fp);
fwrite(&name_students[i],sizeof(Student),1,fp1);
}
fclose(fp);
fclose(fp1);
system("cls");return 0;
}

int Search_project()//查询功能
{ FILE *fp=fopen("c:\\name.txt","r");
FILE *fp1=fopen("c:\\number.txt","r");
if (fp == NULL||fp1 == NULL)//判断文件打开是否成功
{ cout<<"打开文件失败!"< return -1;
}
num=0;
fread(&students[num],sizeof(Student),1,fp);
fread(&name_students[num],sizeof(Student),1,fp1);
while((!feof(fp))&&(!feof(fp1)))
{ num++;//计算已存储的资料的人数num
fread(&students[num],sizeof(Student),1,fp);
fread(&name_students[num],sizeof(Student),1,fp1);
}
fclose(fp);
fclose(fp1);

cout<<'\t'<<"按学号查询(A)"<<'\t'<<"按姓名查询(B)"<<'\t'<<"返回主菜单(E)"< cout<<"Ο 请选择:";
char input;
cin>>input;
switch(input)
{ case 'A':
case 'a':
{ cout<<"Ο 输入学号:";
int number;
cin>>number;//以下是折半查询:
int low=0;
int high=num-1;
while (low<=high)
{ int mid=(low+high)/2;
if (students[mid].no==number)
{ cout<<"Ο 学号:"< cout<<"Ο 姓名:"< cout<<"Ο 数学: "< cout<<"Ο 英语: "< cout<<"Ο 物理: "< cout<<"Ο 计算机: "< break;
}
else if (number>students[mid].no)
low=mid+1;
else high=mid-1;
}
if(low>high) cout<<" 无相关资料!"< }break;
case 'B':
case 'b':
{ cout<<"Ο 输入姓名:";
char name[20];
cin>>name;
int low=0;int high=num-1;//以下是折半查询:
while (low<=high)
{ int mid=(low+high)/2;
if (strcmp(name_students[mid].name,name)==0)
{ cout<<"Ο 学号:"< cout<<"Ο 姓名:"< cout<<"Ο 数学: "< cout<<"Ο 英语: "< cout<<"Ο 物理: "< cout<<"Ο 计算机: "< break;
}
else if (strcmp(name_students[mid].name,name)<0)
low=mid+1;
else high=mid-1;
}
if(low>high) cout<<" 无相关资料!"< }break;
case 'E':
case 'e':system("cls");return -1;break;
}
cout<<"☆ 继续或返回主菜单(C/E):";
cin>>choose;
if(choose=='C'||choose=='c') {system("cls");Search_project();}
else {system("cls");return -1;}
return 0;
}

int Delete_project()
{ cout<<"Ο 需删除的学生的学号是:";
int number;
cin>>number;
for(int i=0;i { if( students[i].no==number)
break;
}
for(;i { Student temp =students[i];
students[i]=students[i+1];
students[i+1]=temp;
}
for(int t=0;t { if( name_students[t].no==number)
break;
}
for(;t { Student temp =name_students[t];
name_students[t]=name_students[t+1];
name_students[t+1]=temp;
}
num-=1;//总人数减一,即删除最后一位
FILE *fp=fopen("c:\\name.txt","w");
FILE *fp1=fopen("c:\\number.txt","w");
if (fp == NULL||fp1 == NULL)//判断文件打开是否成功
{ cout<<"打开文件失败!"< return -1;
}
for(i=0;i { fwrite(&students[i],sizeof(Student),1,fp);
fwrite(&name_students[i],sizeof(Student),1,fp1);
}
fclose(fp);
fclose(fp1);
bool p=true;//以下查找并判断删除是否成功
int low=0;
int high=num-1;
while (low<=high)
{ int mid=(low+high)/2;
if (students[mid].no==number||name_students[mid].no==number)
{ cout<<" 删除失败!"< p=false;
break;
}
else if (number>students[mid].no)
low=mid+1;
else high=mid-1;
}
if(p) cout<<" 删除成功!"< cout<<"☆ 继续或返回主菜单(C/E):";
cin>>choose;
if(choose=='C'||choose=='c') {system("cls");Delete_project();}
else {system("cls");return -1;}
return 0;
}

int Modify_project()
{ FILE *fp=fopen("c:\\name.txt","r");
FILE *fp1=fopen("c:\\number.txt","r");
if (fp == NULL||fp1 == NULL)//判断文件打开是否成功
{ cout<<"打开文件失败!"< return -1;
}
num=0;
fread(&students[num],sizeof(Student),1,fp);
fread(&name_students[num],sizeof(Student),1,fp1);
while((!feof(fp))&&(!feof(fp1)))
{ num++;//计算已存储的资料的人数num
fread(&students[num],sizeof(Student),1,fp);
fread(&name_students[num],sizeof(Student),1,fp1);
}
fclose(fp);
fclose(fp1);

cout<<"Ο 需修改的学生的学号是:";
int number;
cin>>number;
int t,math,english,physics,computer;
cout<<"Ο 输入修改结果:"< cout<<"Ο 数学:";
cin>>math;
cout<<"Ο 英语:";
cin>>english;
cout<<"Ο 物理:";
cin>>physics;
cout<<"Ο 计算机:";
cin>>computer;
for(int i=0;i { if( students[i].no==number)
break;
}
students[i].math=math;
students[i].english=english;
students[i].physics=physics;
students[i].computer=computer;

i=num;//以下是按no冒泡排序
bool exchange;
while(i>1)
{ exchange=false;
for( int k=0;k { if(students[k].no>students[k+1].no)
{ Student temp=students[k];
students[k]=students[k+1];
students[k+1]=temp;
exchange=true;
}
}
if (!exchange) break;
i--;
}
for (t=0;t { name_students[t].no=students[t].no;
*strcpy(name_students[t].name,students[t].name);
name_students[t].math=students[t].math;
name_students[t].english=students[t].english;
name_students[t].computer=students[t].computer;
name_students[t].physics=students[t].physics;
}
while(i>1)//以下是按name冒泡排序
{ exchange=false;
for( int k=0;k { if(strcmp(name_students[k].name,name_students[k+1].name)>0)
{ Student temp=name_students[k];
name_students[k]=name_students[k+1];
name_students[k+1]=temp;
exchange=true;
}
}
if (!exchange) break;
i--;
}

fp=fopen("c:\\name.txt","w+");//存储两结构体数组,w+表示清空已有文件的内容
fp1=fopen("c:\\number.txt","w+");
if (fp == NULL||fp1 == NULL)//判断文件打开是否成功
{ cout<<"打开文件失败!"< return -1;
}
for(i=0;i { fwrite(&students[i],sizeof(Student),1,fp);
fwrite(&name_students[i],sizeof(Student),1,fp1);
}
fclose(fp);
fclose(fp1);
cout<<"☆ 继续或返回主菜单(C/E):";
cin>>choose;
if(choose=='C'||choose=='c') {system("cls");Delete_project();}
else {system("cls");return -1;}
return 0;
}

int main()
{ system("cls");
do
{Face();}
while (choose=='e'||choose=='E');
return 0;
}

回答2:

已发送。。。

回答3:

#include "stdafx.h"
#include "Resource.h"
#include "Label.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLabel

CLabel::CLabel()
{
m_crText = GetSysColor(COLOR_WINDOWTEXT);
m_hBrush = ::CreateSolidBrush(GetSysColor(COLOR_3DFACE));

::GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT),sizeof(m_lf),&m_lf);

m_font.CreateFontIndirect(&m_lf);
m_bTimer = FALSE;
m_bState = FALSE;
m_bLink = TRUE;
m_hCursor = NULL;
m_Type = None;

m_hwndBrush = ::CreateSolidBrush(GetSysColor(COLOR_3DFACE));
}

CLabel::~CLabel()
{
m_font.DeleteObject();
::DeleteObject(m_hBrush);
}

CLabel& CLabel::SetText(const CString& strText)
{
SetWindowText(strText);
return *this;
}

CLabel& CLabel::SetTextColor(COLORREF crText)
{
m_crText = crText;
RedrawWindow();
return *this;
}

CLabel& CLabel::SetFontBold(BOOL bBold)
{
m_lf.lfWeight = bBold ? FW_BOLD : FW_NORMAL;
ReconstructFont();
RedrawWindow();
return *this;
}

CLabel& CLabel::SetFontUnderline(BOOL bSet)
{
m_lf.lfUnderline = bSet;
ReconstructFont();
RedrawWindow();
return *this;
}

CLabel& CLabel::SetFontItalic(BOOL bSet)
{
m_lf.lfItalic = bSet;
ReconstructFont();
RedrawWindow();
return *this;
}

CLabel& CLabel::SetSunken(BOOL bSet)
{
if (!bSet)
ModifyStyleEx(WS_EX_STATICEDGE,0,SWP_DRAWFRAME);
else
ModifyStyleEx(0,WS_EX_STATICEDGE,SWP_DRAWFRAME);

return *this;
}

CLabel& CLabel::SetBorder(BOOL bSet)
{
if (!bSet)
ModifyStyle(WS_BORDER,0,SWP_DRAWFRAME);
else
ModifyStyle(0,WS_BORDER,SWP_DRAWFRAME);

return *this;
}

CLabel& CLabel::SetFontSize(int nSize)
{
nSize*=-1;
m_lf.lfHeight = nSize;
ReconstructFont();
RedrawWindow();
return *this;
}

CLabel& CLabel::SetBkColor(COLORREF crBkgnd)
{
if (m_hBrush)
::DeleteObject(m_hBrush);

m_hBrush = ::CreateSolidBrush(crBkgnd);
return *this;
}

CLabel& CLabel::SetFontName(const CString& strFont)
{
strcpy(m_lf.lfFaceName,strFont);
ReconstructFont();
RedrawWindow();
return *this;
}

BEGIN_MESSAGE_MAP(CLabel, CStatic)
//{{AFX_MSG_MAP(CLabel)
ON_WM_CTLCOLOR_REFLECT()
ON_WM_TIMER()
ON_WM_LBUTTONDOWN()
ON_WM_SETCURSOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLabel message handlers

HBRUSH CLabel::CtlColor(CDC* pDC, UINT nCtlColor)
{
// TODO: Change any attributes of the DC here

// TODO: Return a non-NULL brush if the parent's handler should not be called

if (CTLCOLOR_STATIC == nCtlColor)
{
pDC->SelectObject(&m_font);
pDC->SetTextColor(m_crText);
pDC->SetBkMode(TRANSPARENT);
}

if (m_Type == Background)
{
if (!m_bState)
return m_hwndBrush;
}

return m_hBrush;
}

void CLabel::ReconstructFont()
{
m_font.DeleteObject();
BOOL bCreated = m_font.CreateFontIndirect(&m_lf);

ASSERT(bCreated);
}

CLabel& CLabel::FlashText(BOOL bActivate)
{
if (m_bTimer)
{
SetWindowText(m_strText);
KillTimer(1);
}

if (bActivate)
{
GetWindowText(m_strText);
m_bState = FALSE;

m_bTimer = TRUE;
SetTimer(1,500,NULL);
m_Type = Text;
}

return *this;
}

CLabel& CLabel::FlashBackground(BOOL bActivate)
{

if (m_bTimer)
KillTimer(1);

if (bActivate)
{
m_bState = FALSE;

m_bTimer = TRUE;
SetTimer(1,500,NULL);

m_Type = Background;
}

return *this;
}

void CLabel::OnTimer(UINT nIDEvent)
{
m_bState = !m_bState;

switch (m_Type)
{
case Text:
if (m_bState)
SetWindowText("");
else
SetWindowText(m_strText);
break;

case Background:
InvalidateRect(NULL,FALSE);
UpdateWindow();
break;
}

CStatic::OnTimer(nIDEvent);
}

CLabel& CLabel::SetLink(BOOL bLink)
{
m_bLink = bLink;

if (bLink)
ModifyStyle(0,SS_NOTIFY);
else
ModifyStyle(SS_NOTIFY,0);

return *this;
}

void CLabel::OnLButtonDown(UINT nFlags, CPoint point)
{
CString strLink;

GetWindowText(strLink);
ShellExecute(NULL,"open",strLink,NULL,NULL,SW_SHOWNORMAL);

CStatic::OnLButtonDown(nFlags, point);
}

BOOL CLabel::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (m_hCursor)
{
::SetCursor(m_hCursor);
return TRUE;
}

return CStatic::OnSetCursor(pWnd, nHitTest, message);
}

CLabel& CLabel::SetLinkCursor(HCURSOR hCursor)
{
m_hCursor = hCursor;
return *this;
}