绩点计算机代码

smain_Calculator.cpp

#include "sCalculator.h"
char GetChar()
{
	char ch;
	while((ch=cin.get())==' '||ch=='\t'||ch=='\n');
	return ch;
}
void main()//显示全部成绩,必修成绩,全部绩点,部分绩点,平均分,Student修改密码,CManager录入学生信息
{
	/*CStudent a;
	string name;
	string password;
	char sex[3];
	cout<<"input the name of student a:";
	cin>>name;
	cout<<"input the password of student a:";
	cin>>password;
	cout<<"input the sex of student:";
	cin>>sex;
	a.SetStudentPrivacy(password,name,sex);
	cout<<"output the password of student a:"<<a.GetStudentPassword()<<endl;
	cout<<"output the name of student a:"<<a.GetStudentName()<<endl;
	cout<<"output the num of student a:"<<a.GetStudentNum()<<endl;*/
	string managerAccount="woshimanager";//进入管理者的界面
	string managerAccountPassword="woshimanager";
	string account;
	cout<<"input the account of the manager:";
	cin>>account;
	string accountPassword;
	cout<<"input the accoutPassword of the manager:";
	cin>>accountPassword;
	CManager manager;
	if(account==managerAccount&&accountPassword==managerAccountPassword)
	{
		cout<<"scucceed to enter the window of the manager"<<endl;
		
		cout<<"if build a new student,please input 'y':";
		char ch;
		while((ch=GetChar())=='y')
		{
			string name;
			char sex[3];
			cout<<"input the name of the student:";
			cin>>name;
			cout<<"input the sex of the student:";
			cin>>sex;
			manager.BuildStudent(name,sex);
			cout<<"if build a new student,please input 'y':";
		}
		/*cout<<"if show the student's information,please input 's':";
		while((ch=GetChar())=='s')
		{
			cout<<"the num of student:";
			int studentnum;
			cin>>studentnum;
			manager.ShowStudent(studentnum);
			cout<<"if show the student's information,please input 's':";
		}*/
		cout<<"if input the grade of student,please input 'i'";
		while((ch=GetChar())=='i')
		{
			string subject;
			float grade;
			int number;
			cout<<"the number of student:";
			cin>>number;
			do
			{
			cout<<"input the subject of student:";
			cin>>subject;
			cout<<"input the grade of student:";
			cin>>grade;
			cout<<"if it is complusory,please input '1':";
			char h=GetChar();
			manager.InputStudentGrade(grade,subject,number,h);
			cout<<"if wanted input another subject of this student,please input 'd':";
			}while((ch=GetChar())=='d');
			cout<<"if input the grade of student,please input 'i'";
		}
	/*	cout<<"if show the grade and subject of student,please input 'c'";
		while((ch=GetChar())=='c')
		{
			int number;
			cout<<"input the number of student:";
			cin>>number;
			manager.ShowStudentGrade(number);
			cout<<"if show the grade and subject of student,please input 'c'";
		}*/
	}
	else
		cout<<"password is wrong"<<endl;
	//进入学生登录界面
	int numberOfStudent;
	string passwordOfStudent;
	char c;
	cout<<"if enter the student's windows,please input 'w':";
	while((c=GetChar())=='w')
	{
	cout<<"please input your num:";
	cin>>numberOfStudent;
	cout<<"input the password:";
	cin>>passwordOfStudent;
	//判断密码是否正确
	CStudent* p=new CStudent(manager.GetStudent(numberOfStudent));
	if(p->GetStudentPassword()==passwordOfStudent)
	{
		cout<<"succeed to enter the student's window."<<endl;
		cout<<"the name of the student is:"<<p->GetStudentName()<<endl;
		cout<<"if output all the subject, grade and GPA of the student,please input 'a':";
		char cChar;
		//显示全部成绩,绩点,平均分
		if((cChar=GetChar())=='a')
		{
			p->ShowAllSubject_Grade();
			p->CalculateAllGPA();
			p->CalculateAllAverage();
			cout<<"All the average grade is:"<<p->GetAllAverage()<<endl;
			cout<<"All the GPA is:"<<p->GetAllGPA()<<endl;
		}
		//显示必修成绩,绩点,平均分
		cout<<"if output the complusory subject,grade and GPA of the student,please input 'c':";
		if((cChar=GetChar())=='c')
		{
			p->ShowComplusorySubject_Grade();
			p->CalculateCompulsoryAverage();
			p->CalculateCompulsoryGPA();
			cout<<"average grade of the complusory grade is:"<<p->GetComplusoryAverage()<<endl;
			cout<<"average grade of the complusory GPA is:"<<p->GetComplusoryGPA()<<endl;
		}
		//修改密码
		cout<<"if want to revise the password,please input 'r':";
		if((cChar=GetChar())=='r')
		{
			cout<<"input the new password:";
			string newPassword;
			cin>>newPassword;
			manager.GetStudentIP(numberOfStudent)->RevisePassword(newPassword);
		}
	}else
		cout<<"password is wrong!"<<endl;
	delete p;
	cout<<"if enter the student's windows,please input 'w':";
	}
}

sCalculator.h

#ifndef _SCALCULATOR_H_
#define _SCALCULATOR_H_

#include <iostream>
#include <string>
using namespace std;

const SubjectLen=10;
const MaxStudent=20;

class CManager;

class CStudent
{
	friend CManager;
public:
	static int num;
public:
	void* operator new(size_t obj);
	void operator delete(void *p);
//	CStudent operator =(CStudent &obj);
	CStudent()
	{
		m_AllGrade=0;
		m_ComplusoryGrade=0;
		m_num=num;
		num++;
		m_numberOfGrade=0;
		m_password="woshistudent";
		m_numberOfComplusory=0;
		m_allSum=0;
		m_ComplusorySum=0;

	}
	void ShowComplusorySubject_Grade();
	void ShowGrade();
	float GetAllGPA();
	void CalculateAllGPA();
	float GetAllAverage();
	float GetComplusoryAverage();
	float GetComplusoryGPA();
	//重设密码
	void RevisePassword(string newPassword);
	~CStudent(){}
	/*int GetNumberOfGrade()
	{
		return m_numberOfGrade;
	}*/
	void ShowAllSubject_Grade();
//	void SetStudentPrivacy(string password,string name,char sex[]);
	string GetStudentPassword();
	string GetStudentName();
//	int GetStudentNum();
//protected:	int GetStudentNumberOfGrade();
//	void ADDStudentNumberOfGrade();
	void CalculateAllAverage();
	void CalculateCompulsoryGPA();
	void CalculateCompulsoryAverage();
private:
	int m_num;//学生的学号
	string m_password;
	string m_name;
	char m_sex[3];
	int m_grade[SubjectLen];
	string m_subject[SubjectLen];
	int m_complusory[SubjectLen];
	int m_numberOfGrade;
	float m_GPA;
	//float m_allGrade;
	float m_ComplusoryGPA;
	float m_average;
	float m_ComplusoryAverage;
	float m_AllGrade;
	float m_ComplusoryGrade;
	float m_allSum;
	float m_ComplusorySum;
	int m_numberOfComplusory;
};

class CManager
{
public:
	CManager();//初始化CManager
//	SetStudentGrade();
	/*SetAccoutPassword()
	{
		m_accout="woshimanager";
		m_accoutPassword="woshimanager";
	}*/
	//创建学生的各种信息
	void BuildStudent(string name,char sex[]);
	//void ShowStudent(int number);
	void InputStudentGrade(float grade,string subject,int number,char j);
	//void ShowStudentGrade(int number);
	~CManager(){}
	CStudent GetStudent(int number);
	CStudent *GetStudentIP(int number);
private:
	int m_studentNumber;
//	string m_account;
//	string m_accountPassword;
	CStudent *p_student[MaxStudent];
};
#endif

sCalculator.cpp

#include "sCalculator.h"

int CStudent::num=0;
void CManager::BuildStudent(string name,char sex[])
{
	p_student[m_studentNumber]=new CStudent;
	p_student[m_studentNumber]->m_name=name;
	strcpy(p_student[m_studentNumber]->m_sex,sex);
	m_studentNumber++;
}
string CStudent::GetStudentPassword()
{
	return m_password;
}
string CStudent::GetStudentName()
{
	return m_name;
}
/*int CStudent::GetStudentNum()
{
	return m_num;
}*/

CManager::CManager()
{
	m_studentNumber=0;
	for(int i=0;i<MaxStudent+1;i++)
		p_student[i]=NULL;
}
void CManager::InputStudentGrade(float grade,string subject,int number,char j)
{
	
	p_student[number]->m_grade[p_student[number]->m_numberOfGrade]=grade;
	p_student[number]->m_AllGrade+=grade;
	float sum=0.0;
	if(grade<60){;}
		else if(grade>59&&grade<65)
		{
			sum=(float)1.0;
		}else if(grade>64&&grade<70)
		{
			sum=(float)1.7;
		}else if(grade>69&&grade<75)
		{
			sum=(float)2.2;
		}else if(grade>74&&grade<80)
		{
			sum=(float)2.7;
		}else if(grade>79&&grade<85)
		{
			sum=(float)3.2;
		}else if(grade>84&&grade<90)
		{
			sum=(float)3.6;
		}
		else if(grade>89&&grade<95)
		{
			sum=(float)3.8;
		}else
			sum=(float)4;
	p_student[number]->m_allSum+=sum;
	if(j=='1')
	{
		p_student[number]->m_complusory[p_student[number]->m_numberOfGrade]=1;
		p_student[number]->m_ComplusoryGrade+=grade;
		p_student[number]->m_ComplusorySum+=sum;
		(p_student[number]->m_numberOfComplusory)++;
	}
	else 
		p_student[number]->m_complusory[p_student[number]->m_numberOfGrade]=0;
	p_student[number]->m_subject[p_student[number]->m_numberOfGrade]=subject;
	(p_student[number]->m_numberOfGrade)++;
}
/*void CManager::ShowStudent(int number)
{
	if(p_student[number]==NULL)
	{
		cout<<"不存在改学生,输入有误!"<<endl;
	}
	else
	{
	cout<<"show the information of student whose num is "<<number<<endl;
	cout<<"the name of student:"<<p_student[number]->m_name<<endl;
	cout<<"the sex of the student:"<<p_student[number]->m_sex<<endl;
	}
}(/
/*int CStudent::GetStudentNumberOfGrade()
{
	return m_numberOfGrade;
}*/
/*void CStudent::ADDStudentNumberOfGrade()
{
	m_numberOfGrade++;
}*/
/*void CManager::ShowStudentGrade(int number)
{
	cout<<"the student's number is:"<<number<<endl;
	for(int i=0;i<p_student[number]->m_numberOfGrade;i++)
	{
		cout<<"the student's subject is:"<<p_student[number]->m_subject[i]<<endl;
		cout<<"this subject's grade is"<<p_student[number]->m_grade[i]<<endl;
	}
}*/
void CStudent::ShowGrade()
{
	for(int i=0;i<m_numberOfGrade;i++)
	{
		cout<<"the student's subject is:"<<m_subject[i]<<endl;
		cout<<"this subject's grade is"<<m_grade[i]<<endl;
	}
}
float CStudent::GetAllGPA()
{
	return m_GPA;
}
//	95-100		90-94   85-89  80-84   75-79   70-74  65-69	60-64	<60

//绩点 4.0      3.8     3.6    3.2     2.7     2.2    1.7     1.0     0
void CStudent::CalculateAllGPA()
{
	//m_sumGPA=0.0;
	m_GPA=m_allSum/m_numberOfGrade;
}
	//重设密码
void CStudent::RevisePassword(string newPassword)
{
	m_password=newPassword;
	cout<<"succeed to revise the password!"<<endl;
}
CStudent CManager::GetStudent(int number)
{
	return *p_student[number];
}
void* CStudent ::operator new(size_t obj)
{
//	cout<<"new一个CStudent对象"<<endl;
	return malloc(obj);
}
//CStudent CStudent::operator =(CStudent &obj)
void CStudent::operator delete(void *p)
{
	//cout<<"消除对象p"<<endl;
	free(p);
}
void CStudent::ShowAllSubject_Grade()
{
	for(int i=0;i<m_numberOfGrade;i++)
	{
		cout<<"the name of the subject "<<i<<":"<<m_subject[i]<<endl;
		cout<<"the grade of the subject "<<i<<":"<<m_grade[i]<<endl;
		if(m_complusory[i]==1)
			cout<<"the subject "<<i<<" is complusory"<<endl;
		else
			cout<<"the subject "<<i<<" isn't complusory"<<endl;
	}
}
CStudent* CManager::GetStudentIP(int number)
{
	return p_student[number];
}
void CStudent::CalculateAllAverage()
{
	m_average=m_AllGrade/m_numberOfGrade;
}
void CStudent::CalculateCompulsoryGPA()
{
	m_ComplusoryGPA=m_ComplusorySum/m_numberOfComplusory;
}
void CStudent::CalculateCompulsoryAverage()
{
	m_ComplusoryAverage=m_ComplusoryGrade/m_numberOfComplusory;
}
float CStudent::GetAllAverage()
{
	return m_average;
}
float CStudent::GetComplusoryAverage()
{
	return m_ComplusoryAverage;
}
float CStudent::GetComplusoryGPA()
{
	return m_ComplusoryGPA;
}
void CStudent::ShowComplusorySubject_Grade()
{
	int j=0;
	for(int i=0;i<m_numberOfGrade;i++)
	{
		if(m_complusory[i]==1)
		{
			cout<<"the name of complusory subject "<<j<<":"<<m_subject[i]<<endl;
			cout<<"the grade of complusory subject "<<j<<":"<<m_grade[i]<<endl;
			j++;
		}
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值