一个计算GPA的工具

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

static void getscore(unsigned int *allp,unsigned int *allc,unsigned int opt,unsigned int score,unsigned int credit)
{
	unsigned int s_score;
	switch(opt)
	{
		case 1:
			if(score<60)
				s_score=0;
			else 
				s_score=(score-50)/10;
			break;
		case 2:
			break;
		case 3:
			s_score=score-'E';
			break;
		default:
			cout<<"input error opt : "<<opt<<endl;
			break;

	}
	*allc+=credit;
	*allp+=credit*s_score;
}

int main()
{
	cout<<"introducation:\n90-100:A(4)\n80-89:B(3)\n70-79:C(2)\n60-69:D(1)\n0-59:E(0)"<<endl;
	cout<<"choose:"<<endl;
	cout<<"1.input 0-100 scores/credit;"<<endl;
	cout<<"2.input 0-4 points/credit:"<<endl;
	cout<<"3.input A-E/credit."<<endl;
	short opt;
	unsigned int score,credit,allpoint,allcredit;
	allpoint = 0;
	allcredit = 0;
	cin>>opt;
	if(opt<1||opt>3)
	{
		cout<<"your input is wrong"<<endl;
		return -1;
	}
	cout<<"please input as my_score,credit end with credit=0"<<endl;
	scanf("%u,%u",&score,&credit);
	while(0!=credit)
	{
		getscore(&allpoint,&allcredit,opt,score,credit);
		scanf("%u,%u",&score,&credit);
	}
	cout<<"all points:"<<allpoint<<endl;
	cout<<"all credits:"<<allcredit<<endl;
	cout<<"GPA:"<<(float)allpoint/(float)allcredit<<endl;
}


  注:按照美国标准分计算。

90~100为4分……60~79为1分,<60为0分。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值