求C++大神编一个程序: n个学生考完面向对象程序设计期末考试,老师评卷完成后,需要划定及格线, 面向对象程序设计(C++语言)期末考试

\u7528c++\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\u7cfb\u7edf<<\u9762\u5411\u5bf9\u8c61\u7a0b\u5e8f\u8bbe\u8ba1\u300b\u8bfe\u7a0b\u7684\u8003\u8bd5\u6210\u7ee9

\u601d\u8def\uff1a
1.\u5b9a\u4e49\u4e00\u4e2a\u94fe\u8868\u6765\u4fdd\u5b58\u5168\u73ed\u540c\u5b66\u7684\u8003\u8bd5\u6210\u7ee9\uff08\u81f3\u4e8e\u8bfb\u53d6\u65b9\u6cd5\u53ef\u4ee5\u662f\u4ece\u6570\u636e\u5e93\u6216\u8005\u6587\u672c\u8bfb\u53d6\uff0c\u6216\u8005\u76f4\u63a5\u8d4b\u503c\u7ed9\u94fe\u8868\u7684\u65b9\u5f0f\uff09
2.\u5047\u8bbe\u5b57\u7b26\u4e32\u7ed3\u675f\u6807\u5fd7\u4e3a@\uff0c\u5faa\u73af\u8bfb\u53d6\u94fe\u8868\u5185\u7684\u6570\u636e\uff0c\u5224\u65ad\u53ea\u8981\u8bfb\u53d6\u6570\u636e\u8bfb\u5230@\uff0c\u5c31\u8df3\u51fa\u5faa\u73af\uff0c\u5176\u5b9e\u6ca1\u5fc5\u8981\u505a\u8fd9\u4e2a\u7ed3\u675f\u6807\u5fd7\uff0c\u94fe\u8868\u957f\u5ea6\u5c31\u662f\u7edf\u8ba1\u4eba\u6570\uff0c\u6839\u636e\u94fe\u8868\u957f\u5ea6\u5faa\u73af\u8bfb\u53d6\u6570\u636e\u5373\u53ef\u3002
3.\u5faa\u73af\u5916\u9762\u5b9a\u4e49\u4e00\u4e2a\u6700\u9ad8\u5206MAX=0\uff1b\u6700\u4f4e\u5206MIN=0\uff1b\u603b\u6210\u7ee9SUM=0;\u5728\u5faa\u73af\u91cc\u9762\u67e5\u627e\uff0c\u53ea\u8981\u6210\u7ee9\u5927\u4e8eMAX\u5c31\u7ed9MAX\uff0c\u5c0f\u4e8eMIN\u5c31\u7ed9MIN\uff0c\u7136\u540eSUM+=\u4f20\u8fdb\u6765\u7684\u503c\u3002
4.\u5faa\u73af\u7ed3\u675f\u540eSUM/\u94fe\u8868\u957f\u5ea6\u5c31\u662f\u5e73\u5747\u6210\u7ee9

\u8fd8\u662f\u628a\u4e66\u4e0a\u7684\u5173\u952e\u70b9\u770b\u4e00\u770b\uff0c\u6bd4\u5982\u7c7b\uff0c\u7ee7\u627f\u7b49\uff0c\u8fd9\u4e9b\u662f\u5fc5\u8003\u7684\uff0c\u6982\u5ff5\u9898\u4e5f\u4f1a\u51fa\u4e00\u4e9b\u3002\u8fd9\u6837\u770b\u91cd\u70b9\u5c31\u80fd\u8282\u7701\u5f88\u591a\u65f6\u95f4\u3002\u5728\u590d\u4e60\u4e07\u77e5\u8bc6\u70b9\u540e\u505a\u51e0\u5957\u5377\u5b50\u3002
\u8fd8\u6709\u4e00\u4e2a\u529e\u6cd5\u5c31\u662f\u627e\u5b66\u7684\u597d\u7684\u540c\u5b66\u5e2e\u4f60\u8f85\u5bfc\u8f85\u5bfc\uff0c\u8fd8\u80fd\u589e\u8fdb\u53cb\u8c0a\u3002

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class student
{
public:
int id;
string name;
unsigned score;
};
int main()
{
ifstream ifs("student.txt");
if(ifs.fail()||(ifs.peek() == EOF))
return 1;
student* stu[1024]={NULL};
int i = 0;
while(!ifs.eof()&&(i<1024))
{
stu[i] =new student();
ifs>>stu[i]->id;
ifs>>stu[i]->name;
ifs>>stu[i]->score;
if(ifs.fail())
{
delete stu[i];
break;
}
int j = 0;
for(;j < i;j++)
if(stu[i]->id == stu[j]->id)
{
delete stu[i];
stu[i]=NULL;
break;
}
if(j<i)
//有重复id,跳过此人。
continue;
i++;
}
ifs.close();
if(!i)
return 0;
for(int k =60,m=0;k >= 0;k -= 3)
{
for(int l = 0;l < i;l++)
if(stu[l]->score>=k)
m++;
double rate = (double)m/i;
if(rate>=0.85f)
{
cout<<"及格分数线:"<<k<<endl<<"不及格名单:"<<endl;
for(int n =0;n<i;n++)
if(stu[n]->score<k)
cout<<""<<stu[n]->name;
break;
}
m=0;
}
return 0;
}

 /*       student.txt          */测试文件

5 张三 61

9 李四 62

4 王五 83

6 赵六 44

8 谢二麻子 55

55 Joker 66

23 王大麻子 77

44 掌柜的 35

42 老板娘 100

59 臭老鼠 99

46 瘸瞎子 59

88 黑猫警长 95

41 葫芦娃 88

50 半个人 50



/*测试文件使用了楼上的仁兄的,前后编程了一个小时。
Author:qcq
date:2015-4-10
e-mail:[email protected]
*/
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<sstream>
#include<fstream>
#include<algorithm>
using namespace std;

const float PERCENT = 0.85;
class Student{
private:
string id;
string name;
float score;
public:
Student(){
new (this)Student("", "", 0.0f);
}

Student(string id, string name, float score){
this->id = id;
this->name = name;
this->score = score;
}

void setId(string id){
this->id = id;
}

string getId(){
return id;
}

void setName(string name){
this->name = name;
}

string getName(){
return name;
}

void setScore(float score){
this->score = score;
}

float getScore(){
return score;
}

friend ostream &operator<<(ostream &fout, const Student &stu);
friend istream &operator>>(istream &fin, Student &stu);
};

ostream &operator<<(ostream &fout, const Student &stu){
fout << "Id:" << stu.id << '' << "Name:" << stu.name << '' << "Score:" << stu.score << endl;

return fout;
}

istream &operator>>(istream &fin, Student &stu){
fin >> stu.id >> stu.name >> stu.score;
return fin;
}

bool compare(Student& a, Student& b){
return a.getScore() > b.getScore();
}

void sortStudent(vector<Student> &data){
sort(data.begin(), data.end(), compare);
}

void disp(vector<Student> &data){
int number = data.size();
int min_number = ceil(number * PERCENT);
int pass_line = floor(data[min_number - 1].getScore());
if (pass_line > 60){
pass_line = 60;
}
while (0 != pass_line % 3){
pass_line -= 1;
}
cout << "pass line is:" << pass_line << endl;
cout << "Passed:" << endl;
vector<Student>::iterator student;
for (student = data.begin(); student != data.end(); student++){
if (student->getScore() >= pass_line){
cout << *student;
}
}
cout << "failed:" << endl;
for (student = data.begin(); student != data.end(); student++){
if (student->getScore() < pass_line){
cout << *student;
}
}
}

int main(){
vector<Student> data;
fstream file_in("students.txt", fstream::in);
while (!file_in.eof()){
Student temp;
file_in >> temp;
data.push_back(temp);
}
/*
 here should sort the vector first!.
*/
sortStudent(data);
disp(data);
return 0;
}


扩展阅读:c++简单程序实例 ... c++ 容器 ... c++教程 ... c++ 循环 ... c++编程 ... c语言必背100代码 ... c++程序 ... c++之旅 ... c++ 外挂 框架 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网