c++编程问题,string类型怎么赋值,怎么引用
.设计一个成绩类,包含两个私有变量:姓名(string类型)、成绩,现有10名同学的成绩(数据自备),请按姓名的大小顺序,显示成绩列表,并查找“张三”同学的成绩。#inc...
.设计一个成绩类,包含两个私有变量:姓名(string类型)、成绩,现有10名同学的成绩(数据自备),请按姓名的大小顺序,显示成绩列表,并查找“张三”同学的成绩。
#include<iostream>
#include<string>
using namespace std;
char *name[10] = { "张一", "张二", "张三", "张四", "张五", "王一", "赵一", "孙一", "章子一", "李天一" };
class Score
{
string name[10], ch, p;
double score1[10];
int i, j;
public:
Score();
Score(string name1[], double score2[]);
void judge();
void show();
};
Score::Score()
{
for (i = 0; i<10; i++)
{
score1[i] = 0;
}
}
Score::Score(string name1[], double score2[])
{
for (i = 0; i<10; i++)
{
name[i] = name1[i];
score1[i] = score2[i];
}
}
void Score::judge()
{
double x;
for (i = 1; i<10; i++)
for (j = 0; j<10 - i - 1; j++)
{
if (name[j]<name[j + 1])
{
ch = name[j], name[j] = name[j + 1], name[j + 1] = ch;
x = score1[j], score1[j] = score1[j + 1], score1[j + 1] = x;
}
}
}
void Score::show()
{
for (i = 0; i<10; i++)
cout << name[i] << " " << score1[i] << endl;
}
int main()
{
string name[10];
double score1[10];
int i;
for (i = 0; i<10; i++)
cin >> score1[i];
Score a(name, score1);
a.judge();
a.show();
return 0;
}
名字怎么cout出来啊。。不会弄啊。。大神给完整的编一下吧 展开
#include<iostream>
#include<string>
using namespace std;
char *name[10] = { "张一", "张二", "张三", "张四", "张五", "王一", "赵一", "孙一", "章子一", "李天一" };
class Score
{
string name[10], ch, p;
double score1[10];
int i, j;
public:
Score();
Score(string name1[], double score2[]);
void judge();
void show();
};
Score::Score()
{
for (i = 0; i<10; i++)
{
score1[i] = 0;
}
}
Score::Score(string name1[], double score2[])
{
for (i = 0; i<10; i++)
{
name[i] = name1[i];
score1[i] = score2[i];
}
}
void Score::judge()
{
double x;
for (i = 1; i<10; i++)
for (j = 0; j<10 - i - 1; j++)
{
if (name[j]<name[j + 1])
{
ch = name[j], name[j] = name[j + 1], name[j + 1] = ch;
x = score1[j], score1[j] = score1[j + 1], score1[j + 1] = x;
}
}
}
void Score::show()
{
for (i = 0; i<10; i++)
cout << name[i] << " " << score1[i] << endl;
}
int main()
{
string name[10];
double score1[10];
int i;
for (i = 0; i<10; i++)
cin >> score1[i];
Score a(name, score1);
a.judge();
a.show();
return 0;
}
名字怎么cout出来啊。。不会弄啊。。大神给完整的编一下吧 展开
2个回答
展开全部
#include<iostream>
#include<string>
using namespace std;
char *name[10] = { "张一", "张二", "张三", "张四", "张五", "王一", "赵一", "孙一", "章子一", "李天一" };
class Score
{
string name[10], ch, p;
double score1[10];
int i, j;
public:
Score();
Score(char* name1[], double score2[]);
void judge();
void show();
};
Score::Score()
{
for (i = 0; i<10; i++)
{
score1[i] = 0;
}
}
Score::Score(char* name1[], double score2[])
{
for (i = 0; i<10; i++)
{
name[i]=name1[i];
score1[i] = score2[i];
}
}
void Score::judge()
{
double x;
for (i = 1; i<10; i++)
for (j = 0; j<10 - i - 1; j++)
{
if (name[j]<name[j + 1])
{
ch = name[j], name[j] = name[j + 1], name[j + 1] = ch;
x = score1[j], score1[j] = score1[j + 1], score1[j + 1] = x;
}
}
}
void Score::show()
{
for (i = 0; i<10; i++)
cout << name[i] << " " << score1[i] << endl;
}
int main()
{
//string name[10];
double score1[10];
int i;
for (i = 0; i<10; i++)
cin >> score1[i];
Score a(name, score1);
a.judge();
a.show();
return 0;
}
2014-05-02
展开全部
构造函数
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询