马来西亚人的时间观念:求一道C++的问题,初学者望指教

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/09 05:50:26
定义一个学生类,输入学生的姓名,语文成绩,数学成绩,英语成绩,计算并输出每位学生的各门功课的成绩,总成绩和平均成绩
下面是老师给的一些提示好像:
class TStudent{
private:
char name[20];
double score_Yuwen,score_Shuxue,score_Yingyu;
public:
......
}
谢谢各位达人了

//Win32 Console Application
//VC++ 6.0 SP6
//a.cpp
//借鉴了ashuixu同学的源码

#include"iostream.h"

class TStudent{
private:
char name[20];
double score_Yuwen,score_Shuxue,score_Yingyu;
public:
TStudent(char AName[], double Ascore_Yuwen,double Ascore_Shuxue,double score_Yingyu);
~TStudent();
Print();
};
TStudent::TStudent(char AName[],double Ascore_Yuwen,double Ascore_Shuxue,double Ascore_Yingyu)
{
//Name 赋值
for (int i=0;i<=19;i++)
{
name[i]=AName[i];
}

score_Yuwen = Ascore_Yuwen ;
score_Shuxue = Ascore_Shuxue;
score_Yingyu = Ascore_Yingyu ;
}
TStudent::~TStudent()
{
}

TStudent::Print()
{
cout<<"Name:"<<name<<endl;
cout<<"Yuwen:"<<score_Yuwen<<endl;
cout<<"Shuxue:"<<score_Shuxue<<endl;
cout<<"Yingyu:"<<score_Yingyu<<endl;
cout<<"Average:"<<(score_Yuwen+score_Shuxue+score_Yingyu)/3<<endl;
cout<<"Sum:"<<score_Yuwen+score_Shuxue+score_Yingyu<<endl;
}

void main()
{

char name[20];
double yuwen,shuxue,yingyu;
cout<<"Input Name, Yuwen, Shuxue, Yingyu:\n";
cin.getline(name,20);
cin>>yuwen;
cin>>shuxue;
cin>>yingyu;

TStudent Astudent(name,yuwen,shuxue,yingyu);
Astudent.Print();
}

//字符输入和字符数组赋值注意下就可以了

/*运行结果
Input Name, Yuwen, Shuxue, Yingyu:
Xiaoming
88.5
85
88
Name:Xiaoming
Yuwen:88.5
Shuxue:85
Yingyu:88
Average:87.1667
Sum:261.5
*/

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

class TStudent{
private:
char name[20];
double score_Yuwen, score_Shuxue, score_Yingyu;
public:
TStudent(char *);
~TStudent();

// getInfo 得到学生的成绩
// outInfo 按要求输出学生的信息

void getInfo(double, double, double);
void outInfo();
};

TStudent::TStudent(char *name)
{
strcpy(this->name, name);
}
TStudent::~TStudent()
{

}

void TStudent::getInfo(double score_Yuwen, double score_Shuxue, double score_Yingyu)
{
this->score_Yuwen = score_Yuwen;
this->score_Shuxue = score_Shuxue;
this->score_Yingyu = score_Yingyu;
}

void TStudent::outInfo()
{
double total = 0, average = 0;

total += this->score_Yuwen;
total += this->score_Shuxue;
total += this->score_Yingyu;

average = total / 3.0;

// Print out Student Info:
cout << "Student Name: " << this->name << endl;
cout << "Scores below: " << endl;
cout << "\tYuwen : " << this->score_Yuwen << endl;
cout << "\tShuxue: " << this->score_Shuxue << endl;
cout << "\tYingyu: " << this->score_Yingyu << endl;
cout << "\nAverage: " << average << " Total: " << total << endl;
}

int main(int argc, char *argv)
{
char name[20];
cout << "Student name: ";
cin >> name;
cout >> endl;

TStudent tS(name);
tS.getInfo(30.5, 20.8, 40.5);
tS.outInfo();

return 0;
}

============================================
程序运行:

Student name: abc

Student Name: abc
Yuwen : 30.5
Shuxue: 20.8
Yingyu: 40.5

Average: 30.6 Total: 91.8

class Student()
{
int mardrian;
int math;
int name;
int englisth;
int sum;
int average;

public Student()
{

}

public String getSun()
{
return mardrian + math + englist;
}

public String getAverage()
{
return (mardrian + math + englist)/3;
}

public int getMath()
{
return this.math;
}
.........................
}

基本意思 偶只会写JAVA

class TStudent{
private:
char name[20];
double score_Yuwen,score_Shuxue,score_Yingyu;
public:
TStudent(char AName[], double Ascore_Yuwen,double Ascore_Shuxue,double score_Yingyu);
~TStudent();
Print();
};
TStudent::TStudent(char AName[],double Ascore_Yuwen,double Ascore_Shuxue,double Ascore_Yingyu)
{
*name = *AName;
score_Yuwen = Ascore_Yuwen ;
score_Shuxue = Ascore_Shuxue;
score_Yingyu = Ascore_Yingyu ;
}
TStudent::~TStudent()
{
}

TStudent::Print()
{
printf("%s: %d, %d, %d. sum=%d, ave=%d", name, score_Yuwen, score_Shuxue, score_Yingyu,
score_Yuwen+score_Shuxue+score_Yingyu, score_Yuwen+score_Shuxue+score_Yingyu/3);
}

可以的