⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stuarray.h

📁 我自己写的学生成绩记录源代码!!!谢谢!
💻 H
字号:
#include "stustruct.h"
#include<cstring>
#include<iostream>
using namespace std;

#ifndef STUARRAY_H
#define STUARRAY_H


const int m_nRecMax=20;
STUDENT *theArray= new STUDENT[m_nRecMax];
int     m_nCurRecNum=0;


void Copy(STUDENT*d, STUDENT s)
{
	strcpy(d->name,s.name); strcpy(d->id,s.id);
	for(int i=0;i<3;i++)
		d->score[i]=s.score[i];
	d->ave=s.ave; d->sum=s.sum;
}
void Output(STUDENT one)
{
	cout<<"\n 学号\t 姓名\t 成绩1\t 成绩2\t 成绩3\t 平均分\t 总分\n";
	cout<<one.id<<"\t"<<one.name;
	for(int j=0;j<3;j++)
		cout<<"\t"<<one.score[j];
	cout<<"\t"<<one.ave<<"\t"<<one.sum<<endl;
}
void Add(void)
{
	STUDENT stu;
	cout<<"姓名: ";  cin>>stu.name;
	cout<<"学号: "; cin>>stu.id;
	cout<<"三门成绩: ";
	cin>>stu.score[0]>>stu.score[1]>>stu.score[2];
	stu.sum=stu.score[0]+stu.score[1]+stu.score[2];
	stu.ave=stu.sum/3.0;
	Copy(&theArray[m_nCurRecNum],stu);
	m_nCurRecNum++;
	if(m_nCurRecNum>=m_nRecMax)
	{
		cout<<"内存空间不够,无法添加记录!"<<endl;
		exit(1);
	}
}
void List(void)
{
	for(int i=0;i<m_nCurRecNum;i++)
		Output(theArray[i]);
}
void Find(char*name)
{
	bool isFind=false;
	for(int i=0;i<m_nCurRecNum;i++)
	{
		if(strcmp(theArray[i].name,name)==0)
		{
		    isFind=true; Output(theArray[i]);
		}
	}
    if(!isFind)
        cout<<"没有找到!"<<endl;
}
void RemoveAll(void)
{
	if(theArray)
	{
		delete[]theArray; theArray=NULL;
	}
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -