编到这 剩下的不会了 求帮忙..
#include<string>#include<cmath>
#include<iostream>
#include<cstdlib>
using namespace std;
class Course
{
private:
friend class Systemgrade;
Course *next;
string subject; //课程名称
double credit; //学分
double score; //成绩
string quality; //成绩性质
double GPA; //绩点?
public:
//创建构造与析构函数
Course(string sub="",double cre=0,double s=0,string q="");
Course(const Course& temp)
{
subject=temp.subject;
credit=temp.credit;
score=temp.score;
quality=temp.quality;
GPA=temp.GPA;
}
~Course() {}
void output();
string getSubject() const {return subject;}
int getCredit() const {return credit;}
double getScore() const {return score;}
string getQuality() const {return quality;}
double getGPA() const {return GPA;}
//计算绩点
};
Course::Course(string sub,double cre,double s,string q)
{
subject=sub;
credit=cre;
score=s;
quality=q;
if(score-50>=1e-5)
GPA=(score-50)*0.1;
else
GPA=0;
if(quality=="优秀") GPA=4.0;
if(quality=="良好") GPA=3.0;
if(quality=="中等") GPA=2.0;
if(quality=="及格") GPA=1.0;
if(quality=="不及格") GPA=0.0;
}
void Course::output()
{
cout<<subject<<" "<<credit<<" "<<GPA<<endl;
}
class Systemgrade
{
Course *first;
double ave;
int tot;
public:
Systemgrade()
{
first=new Course;
first->next=NULL;
}
void add(string sub="",double cre=0,double s=0,string q="");
void OUT();
void Add();
void Ave();
};
void Systemgrade::OUT()
{
cout<<" 科目 学分 绩点"<<endl;
Course *p=first->next;
while(p!=NULL)
{
p->output();
p=p->next;
}
cout<<"平均学分绩点"<<endl;
cout<<ave<<endl;
}
void Systemgrade::add(string sub,double cre,double s,string q)
{
Course *p=new Course(sub,cre,s,q);
if(first->next==NULL)
{
first->next=p;
}
else
{
Course *q=first->next;
first->next=p;
p->next=q;
}
}
void Systemgrade::Ave()
{
Course *p=first->next;
double sum1=0,sum2=0;
while(p!=NULL)
{
sum1+=p->credit*p->GPA;
sum2+=p->credit;
p=p->next;
}
ave=sum1/sum2;
}
void Systemgrade::Add()
{
cout<<"请输入成绩相关信息,按 科目 学分 成绩(等级)"<<endl;
string sub;
double cre;
char a[20];
cin>>sub>>cre>>a;
if(a[0]>='0' && a[0]<='9')
{
double s=atoi(a); //将字符串里的数字强制转换成整形数
add(sub,cre,s);
}
else
{
string ss=a;
add(sub,cre,0,ss);
}
}
int main()
{
// freopen("in.txt","r",stdin);
Systemgrade System;
int menu,sonmenu;
repeat0:
cout<<"显示所有信息,请按:1"<<endl;
cout<<"添加信息,请按:2"<<endl;
cin>>menu;
switch(menu)
{
case 1:
System.OUT();
cout<<"返回主菜单,请按:0"<<endl;
cout<<"直接退出,请按:-1"<<endl;
cin>>sonmenu;
if(sonmenu==-1)
goto repeat11;
if(sonmenu==0)
goto repeat0;
case 2:
repeat1:
System.Add();
cout<<"继续,添加请按:1"<<endl;
cout<<"返回主菜单,请按:0"<<endl;
cin>>sonmenu;
if(sonmenu==1)
goto repeat1;
if(sonmenu==0)
goto repeat0;
}
repeat11:
return 0;
}
上面的能运行 输入课程名、学分和成绩,但是要根据 平均学分绩点(GPA)= ∑(课程学分数×绩点数×K)
________________________________________ ∑课程学分数
计算相应的积点 还要判断所获得的绩点是否合格,能给出相应的结果提示 这三个不会 求帮忙