ArthurSAS
2015-05-11 12:06
采纳率: 33.3%
浏览 5.4k

C++ char数组不能赋值中文

#include
using namespace std;
class student
{
public:
char *getname()
{
cout << "姓名:";
cin >> name[10]; //为什么输入字母、数字都可以正常运行,输入中文就不行
count++;
return name;
}
void seteng()
{
cout << "英语:";
cin >> english;
engtotal += english;
}
void setchi()
{
cout << "语文:";
cin >> chinese;
chitotal += chinese;
}
void setmath()
{
cout << "数学:";
cin >> math;
mattotal += math;
}
static float getaverage(float x){ return x / count;}
static void show()
{
cout << "英语总分:" << engtotal << " 平均分:" << getaverage(engtotal)< cout cout }
protected:
char name[10];
static int count;
int chinese;
int math;
int english;
static int engtotal;
static int chitotal;
static int mattotal;
};
int student::count = 0; //类的成员可以这样初始化吗?
int student::engtotal = 0;
int student::chitotal = 0;
int student::mattotal = 0;
class rg :public student
{
public:
void setjava()
{
cout cin >> java;
rgcount++;
javatotal += java;
}
void setweb()
{
cout << "web:";
cin >> web;
webtotal += web;
}
static void show()
{
cout << "java总分:" < cout }
protected:
static int rgcount;
int java;
int web;
static int javatotal;
static int webtotal;
};
int rg::rgcount = 0;
int rg::javatotal = 0;
int rg::webtotal = 0;
class xa :public student
{
public:
void setwangluo()
{
cout cin >> wangluo;
xacount++;
wangluototal += wangluo;
}
void setanquan()
{
cout << "安全:";
cin >> anquan;
anquantotal += anquan;
}
static void show()
{
cout << "网络总分:" << wangluototal << "平均分:" << (float)wangluototal /xacount << endl;
cout << "安全总分" << anquantotal << "平均分:" << (float)anquantotal /xacount << endl;
}
protected:
static int xacount;
int wangluo;
int anquan;
static int wangluototal;
static int anquantotal;
};
int xa::xacount = 0;
int xa::wangluototal = 0;
int xa::anquantotal = 0;
int main()
{
int rgnum, xanum;
rg rgst[300];
xa xast[300];
cout<< "输入软件工程专业学生人数( cin >> rgnum;
for (int i = 0; i < rgnum; i++)
{
rgst[i].getname();
rgst[i].seteng();
rgst[i].setchi();
rgst[i].setmath();
rgst[i].setjava();
rgst[i].setweb();
}
cout< cin >> xanum;
for (int n = 0; n < xanum; n++)
{
xast[n].getname();
xast[n].seteng();
xast[n].setchi();
xast[n].setmath();
xast[n].setwangluo();
xast[n].setanquan();
}
student::show();
rg::show();
xa::show();
cout << endl;
return 0;
}

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题