c++上机作业

#include<iostream>
using namespace std;
class Coordinate
{
public:
Coordinate()
{
times = 2;
cout << "Coordinate construction1 called!" << endl;
}
Coordinate(int times1)
{
times = times1;
cout << "Coordinate construction2 called!" << endl;
}
~Coordinate()
{
cout << "Coordinate destruction called!" << endl;
}
void InputCoord()
{
for (int i = 0; i < times; i++)
{
cout << "Please input x:" << endl;
cin >> Coord[i][1];
cout << "Please input y:" << endl;
cin >> Coord[i][2];
}

}
void ShowCrood()
{
cout << "The Coord is :" << endl;
for (int i = 0; i < times; i++)
{
cout << "(" << Coord[i][1] << "," << Coord[i][2]<< ")" << endl;
}
}
void ShowAvgCrood()
{
float avgx = 0;
float avgy = 0;
for (int i = 0; i < times; i++)
{
avgx = avgx + Coord[i][1];
avgy = avgy + Coord[i][2];
}
avgx = avgx / times;
avgy = avgy / times;
cout << "The AVG Crood is:" << endl;
cout << "(" << avgx << "," << avgy << ")" << endl;
}
private:
float Coord[100][100];
int  times;
int  times1;
};
int main()
{
Coordinate x;
x.InputCoord();
x.ShowCrood();
x.ShowAvgCrood();
return 0;
}

 

#include<iostream> #include<string> using namespace std; class StudentScore { public:     StudentScore()     {         student_nr = 2;     }     StudentScore(int student_count)     {         student_nr = student_count;     }     void InputStudentNameAndScore()     {         for (int student_id = 0; student_id < student_nr; student_id++)         {             cout << "请输入学生姓名:" << endl;             cin >> name_array[student_id];             cout << "请输入科目A成绩:" << endl;             cin >> score_table[student_id][1];             cout << "请输入科目B成绩:" << endl;             cin >> score_table[student_id][2];             cout << "请输入科目C成绩:" << endl;             cin >> score_table[student_id][3];         }     }     void ShowStudentNameAndScore()     {         for (int student_id = 0; student_id < student_nr; student_id++)         {             cout << "姓名:" << name_array[student_id] << "科目A成绩:"                 << score_table[student_id][1] << "科目B成绩:"                 << score_table[student_id][2] << "科目C成绩:"                 << score_table[student_id][3] << endl;         }     }     void ShowStdentAvgScore(int student_id)     {         cout << "姓名:" << name_array[student_id] << "平均成绩:" << (score_table[student_id][1] +             score_table[student_id][2] + score_table[student_id][3]) / 3 << endl;     }     void ShowCourseAvgScore(string course_name)     {         float sum = 0;         cout << "课程名称:" << course_name << "平均成绩:";         for (int student_id = 0; student_id < student_nr; student_id++)         {             sum += score_table[student_id][1];         }         cout << sum / student_nr << endl;     }     void orderScoreByCourse(string course_name)     {         string v;         cout << "课程名称:" << course_name << endl;         for (int student_id = 0, t; student_id < student_nr - 1; student_id++)             for (int sco = 0; sco < student_nr - 1 - student_id; sco++)             {                 t = score_table[sco][2];                 score_table[sco][2] = score_table[sco + 1][2];                 score_table[sco + 1][2] = t;                 v = name_array[sco];                 name_array[sco] = name_array[sco + 1];                 name_array[sco + 1] = v;             }         for (int student_id = 0; student_id < student_nr; student_id++)             cout << "姓名:" << name_array[student_id] << "成绩:"             << score_table[student_id][2] << endl;     } private:     float score_table[100][3], score_table1[100][3];     string name_array[100], name_array1[100];     int student_nr; }; int main() {     StudentScore x;     x.InputStudentNameAndScore();     x.ShowStudentNameAndScore();     x.ShowStdentAvgScore(1);     x.ShowCourseAvgScore("A");     x.orderScoreByCourse("B");     return 0; }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值