第十六周实验报告(任务二)【学生成绩】

来源:互联网 发布:超级基因优化液下载 编辑:程序博客网 时间:2024/06/11 01:12
/* (程序头部注释开始)

* 程序的版权和版本声明部分

* Copyright (c) 2011, 烟台大学计算机学院学生

* All rights reserved.

* 文件名称:学生成绩

* 作 者: 张培培

* 完成日期: 2012年 06月 05日

* 版 本 号:

* 对任务及求解方法的描述部分

* 输入描述:

* 问题描述:

* 程序输出:

* 程序头部的注释结束*/

#include <iomanip>   #include <string>   #include <fstream>   #include <iostream>   using namespace std;    class Student  {  private:      string name;        double score_cpp;        double score_math;        double score_English;        double score_all;        double score_average;   public:      double all_score();        double ave_score();       void Score();      void write_score(ifstream &in);      void read_score(ofstream &out)  ;  };    double Student::all_score()    {        this->score_all = this->score_cpp + this->score_math + this->score_English;        return this->score_all;    }        double Student::ave_score()    {        this->score_average = (this->score_cpp + this->score_math + this->score_English) / 3;        return this->score_average;    }    void Student::Score()  {      cout << setw(6) << setiosflags(ios::left) << this -> name << " "             << this ->score_cpp << '\t' << this ->score_math << '\t' << this ->score_English << '\t'           << this ->score_all << '\t' << this ->score_average << '\t';                cout<<endl;  }  void Student::write_score(ifstream &in)    {        in >> this->name >> this->score_cpp >> this->score_math >> this->score_English;    }    void Student::read_score(ofstream &out)    {        out << this->name << '\t' << this->score_cpp << '\t' << this->score_math << '\t' << this->score_English << endl;    }      void output_score(Student * s, int num)    {        ifstream infile("score.dat",ios::in);            if(!infile)        {            cerr << "open error!" << endl;            exit(1);        }            for(int i = 0; i < 100; ++i)        {            s[i].write_score(infile);        }        infile.close();    }    void bubble_score(Student * s, int num)    {        Student t;        for(int j = 0; j < num-1; j++)        {            for(int i = 0; i < num-1-j; ++i)            {                if(s[i].all_score() <= s[i+1].all_score())                {                    t = s[i];                    s[i] = s[i+1];                    s[i+1] = t;                }            }        }        }    void readfile(Student * s, int num)    {        ofstream outfile("odered_score.dat",ios::out);            if(!outfile)        {            cerr << "open error!" << endl;            exit(1);        }            for(int i = 0; i < 100; ++i)        {            s[i].read_score(outfile);            s[i].all_score();          s[i].ave_score();          s[i].Score();      }        outfile.close();    }        int main()    {        Student stu[100];           output_score(stu, 100);        bubble_score(stu, 100);        readfile(stu, 100);            system("pause");        return 0;    }    #include <iomanip>#include <string>#include <fstream>#include <iostream>using namespace std;class Student{private:string name;      double score_cpp;      double score_math;      double score_English;      double score_all;      double score_average; public:double all_score();      double ave_score(); void Score();void write_score(ifstream &in);void read_score(ofstream &out)  ;};double Student::all_score()  {      this->score_all = this->score_cpp + this->score_math + this->score_English;      return this->score_all;  }    double Student::ave_score()  {      this->score_average = (this->score_cpp + this->score_math + this->score_English) / 3;      return this->score_average;  }  void Student::Score(){    cout << setw(6) << setiosflags(ios::left) << this -> name << " "           << this ->score_cpp << '\t' << this ->score_math << '\t' << this ->score_English << '\t' << this ->score_all << '\t' << this ->score_average << '\t';              cout<<endl;}void Student::write_score(ifstream &in)  {      in >> this->name >> this->score_cpp >> this->score_math >> this->score_English;  }  void Student::read_score(ofstream &out)  {      out << this->name << '\t' << this->score_cpp << '\t' << this->score_math << '\t' << this->score_English << endl;  }  void output_score(Student * s, int num)  {      ifstream infile("score.dat",ios::in);        if(!infile)      {          cerr << "open error!" << endl;          exit(1);      }        for(int i = 0; i < 100; ++i)      {          s[i].write_score(infile);      }      infile.close();  }  void bubble_score(Student * s, int num)  {      Student t;      for(int j = 0; j < num-1; j++)      {          for(int i = 0; i < num-1-j; ++i)          {              if(s[i].all_score() <= s[i+1].all_score())              {                  t = s[i];                  s[i] = s[i+1];                  s[i+1] = t;              }          }      }    }  void readfile(Student * s, int num)  {      ofstream outfile("odered_score.dat",ios::out);        if(!outfile)      {          cerr << "open error!" << endl;          exit(1);      }        for(int i = 0; i < 100; ++i)      {          s[i].read_score(outfile);          s[i].all_score();s[i].ave_score();s[i].Score();    }      outfile.close();  }    int main()  {      Student stu[100];       output_score(stu, 100);      bubble_score(stu, 100);      readfile(stu, 100);        system("pause");      return 0;  }  

王琦 98 95 98 291 97宋宗杰 94 100 92 286 95.3333杨阔 90 91 98 279 93冼丹 100 89 89 278 92.6667魏佳 100 94 80 274 91.3333范振光 98 87 89 274 91.3333张昊 94 83 96 273 91赵旭洋 87 91 94 272 90.6667吴清正 89 97 85 271 90.3333高举 81 99 91 271 90.3333冯松 89 98 83 270 90马婧 98 84 87 269 89.6667李朋 90 82 97 269 89.6667韩明 83 97 88 268 89.3333王芳 71 97 99 267 89张迪 99 88 80 267 89文静 93 88 85 266 88.6667王磊 87 86 92 265 88.3333刘盈 99 72 93 264 88王瑞麒 89 83 91 263 87.6667叶丹 87 80 96 263 87.6667杨洁 96 79 87 262 87.3333李桐 93 83 86 262 87.3333董一伟 93 88 80 261 87张佳玮 61 98 96 255 85杨梦婕 89 99 67 255 85刘紫亮 72 98 84 254 84.6667刘亚新 77 81 95 253 84.3333王蒙 67 97 89 253 84.3333黄金龙 85 90 78 253 84.3333徐嘉琦 90 75 87 252 84王姝 70 91 90 251 83.6667崔赞 91 67 93 251 83.6667葛志伟 100 79 71 250 83.3333张笑 86 88 76 250 83.3333马佳 60 90 100 250 83.3333王锐 63 90 96 249 83张敏 85 75 89 249 83裴培 75 82 91 248 82.6667冷云 89 88 71 248 82.6667宋媛媛 61 94 92 247 82.3333马立 73 90 83 246 82张里响 85 65 96 246 82何煜中 90 73 82 245 81.6667王竞 90 87 67 244 81.3333高清 76 83 84 243 81梁雅宁 55 88 100 243 81吴佳林 96 65 82 243 81唐楠 68 97 77 242 80.6667宋航彬 80 71 91 242 80.6667蔺剑飞 88 75 79 242 80.6667马里 73 95 73 241 80.3333张龙 62 100 78 240 80李悦 63 79 97 239 79.6667贾伟林 63 90 86 239 79.6667鲁继森 84 79 75 238 79.3333周恒 87 82 69 238 79.3333田苗苗 75 91 71 237 79徐金竹 75 89 73 237 79陈美珠 82 72 83 237 79佟欣 60 79 98 237 79边里 56 94 87 237 79薛淇文 89 71 75 235 78.3333张扬 77 65 93 235 78.3333高路 63 74 98 235 78.3333印虹 92 68 75 235 78.3333于浩 78 84 72 234 78刘得意 60 98 75 233 77.6667黄京 62 75 96 233 77.6667张雯 69 70 93 232 77.3333王欣欣 71 83 78 232 77.3333苏明霞 59 79 94 232 77.3333孙大伟 65 69 98 232 77.3333郭倩 69 94 69 232 77.3333任盛达 57 86 88 231 77王悦 79 82 70 231 77杨华鑫 81 81 68 230 76.6667贺祺 61 96 72 229 76.3333金昕 92 67 69 228 76陈世勃 70 92 65 227 75.6667宋静 69 85 73 227 75.6667王磊 71 78 77 226 75.3333方圆 70 79 76 225 75林倩 67 77 80 224 74.6667汤娜 68 85 71 224 74.6667兰天 83 66 74 223 74.3333刘京西 67 78 78 223 74.3333何佳成 70 75 78 223 74.3333杨超 67 73 82 222 74冯佳媛 61 79 81 221 73.6667周俊升 57 68 96 221 73.6667马骁 62 67 90 219 73赵媛媛 77 75 66 218 72.6667卫青 66 73 77 216 72白涛 57 82 75 214 71.3333吴玮 69 76 68 213 71于莉 55 66 78 199 66.3333桂佳 60 73 65 198 66徐一菡 85 45 62 192 64王欢欢 57 33 66 156 52请按任意键继续. .

原创粉丝点击