line下载苹果版:求一道C++的问题,初学者望指教
来源:百度文库 编辑:神马品牌网 时间:2024/07/03 08:01:17
下面是老师给的一些提示好像:
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);
}
可以的