第16週ミッション2
3446 ワード
/*【 2】
score.dat 100 C++ 、 。
(1) , 、C++ 、 、 ,
。
(2) , 。
(3) 。
(4) ( , )
(5) , ( ) odered_score.dat
。*/
#include
#include
#include
using namespace std;
class Student
{
public:
Student();
void set_name(string name);
void set_c_score(int c_score);
void set_m_score(int m_score);
void set_e_score(int e_score);
void set_s_score(int s_score);
void set_a_score(int a_score);
string get_name(){return name;}
int get_c_score(){return c_score;}
int get_m_score(){return m_score;}
int get_e_score(){return e_score;}
int s_score;
int a_score;
private:
string name;
int c_score;
int m_score;
int e_score;
};
Student::Student()
{
name = '\0';
c_score = 0;
m_score = 0;
e_score = 0;
s_score = 0;
a_score = 0;
}
void Student::set_name(string name)
{
this->name = name;
}
void Student::set_c_score(int c_score)
{
this-> c_score = c_score;
}
void Student::set_m_score(int m_score)
{
this->m_score = m_score;
}
void Student::set_e_score(int e_score)
{
this->e_score = e_score;
}
void Student::set_s_score(int s_score)
{
this->s_score = s_score;
}
void Student::set_a_score(int a_score)
{
this->a_score = a_score;
}
int main()
{
Student stu[100];
int m;
string n;
ifstream infile("score.txt",ios::in);
if (! infile)
{
cerr << "open error" << endl;
exit(1);
}
string name;
int c_score;
int m_score;
int e_score;
int s_score;
int a_score;
for (int i = 0; i < 100; i++ )
{
infile >> name >> c_score >> m_score >> e_score;
stu[i].set_name(name);
stu[i].set_c_score(c_score);
stu[i].set_m_score(m_score);
stu[i].set_e_score(e_score);
s_score = stu[i].get_c_score() + stu[i].get_m_score() + stu[i].get_e_score();
stu[i].set_s_score(s_score);
a_score = stu[i].s_score / 3;
stu[i].set_a_score(a_score );
}
infile.close();
int s_max = stu[0].s_score;
for ( int i = 0; i < 100; i++ )
{
if ( stu[i].s_score > s_max )
{
s_max = stu[i].s_score;
}
}
int c_max = stu[0].get_c_score();
for ( int i = 0; i < 100; i++ )
{
if (stu[i].get_c_score() > c_max)
{
c_max = stu[i].get_c_score();
}
}
int m_max = stu[0].get_m_score();
for ( int i = 0; i < 100; i++ )
{
if (stu[i].get_m_score() > m_max)
{
m_max = stu[i].get_m_score();
}
}
int e_max = stu[0].get_e_score();
for ( int i = 0; i < 100; i++ )
{
if (stu[i].get_e_score() > e_max)
{
e_max = stu[i].get_e_score();
}
}
cout << " " << s_max << endl << "c++ " << c_max << endl < stu[i+1].s_score )
{
n = stu[i].get_name();
stu[i].get_name() = stu[i+1].get_name();
stu[i+1].get_name() = n;
m = stu[i].s_score;
stu[i].s_score = stu[i+1].s_score;
stu[i+1].s_score = m;
}
}
ofstream outfile("inscore.txt",ios::out);
if (! outfile)
{
cerr << "open error" << endl;
exit(1);
}
for (int i = 0; i < 100; i++ )
{
outfile << stu[i].get_name() << stu[i].get_c_score() << stu[i].get_m_score() << stu[i].get_e_score() << stu[i].s_score ;
}
outfile.close();
system("pause");
return 0;
}