大佬来帮我看看怎么回事!!!!

qq_44501430 2019-06-18 12:55:39
//kese1.h 文件,实现类的声明
#include <iostream>
#include <iomanip>
#include <list>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <iterator>
using namespace std;
//student.h学生类
class Student;
class StuList;
ostream& operator<<(ostream& os, const Student& stu); //输出流文件声明
class Student
{
private:
char stuname[20]; //学生姓名
char stunum[12]; //学生学号
float stuscore[4]; //四门课程的成绩
float total; //总分数
public:
Student() //构造函数
{}
Student(char* name, char* num, float s1, float s2, float s3, float s4);//构造函数
void print(int n = -1); //输出函数
char* Getnum() //输出学号
{
return stunum;
}
float* Getstuscore() //输出分数
{
return stuscore;
}

friend ostream& operator<<(ostream& os, const Student& stu); //读出文件
bool operator<(const Student& stu) //重载<运算符
{
return total > stu.total;//
}
friend class StuList; //友元类
};

//StuList.h 学生信息的相关处理
class StuList
{
private:
list<Student> thestu; //链表对象
public:
list<Student> Getthestu() //输出链表
{
return thestu;
}
void Add(Student stu); //添加学生信息
void Seek(char* num); //查询学生信息,按学号查询,返回记录号,-1表示没有找到

void Show(); //遍历列表显示
void SorttoFile(char* filename); //按学生总成绩从高到低排序并写到文件中
void Max(); //各科的最高分
void Min(); //各科的最低分
};

//Class.h班级类
class Class
{
private:
char clgrade[10]; //一共四个年级,其中的一个年级
char clclass[10]; //班级名称
list<Student> cl; //链表对象,一个班最多30个学生
public:
Class() {} //构造函数
Class(char* grade, char* cclass, list<Student> l) //构造函数
{
strncpy(clgrade, grade, 10);
strncpy(clclass, cclass, 10);
cl = l;
}
char* Getclclass() //输出学号
{
return clclass;
}
void CPrint(); //输出学生信息
friend ostream& operator<<(ostream& os, const Class& cl); //读出文件
};

//ClList.h班级链表类
class ClList
{
private:
list<Class> thecl;
public:
void CAdd(Class cl); //添加班级信息
void CSeek(char* cclass); //查询班级信息,按班级名称查询
void CModify(char* cclass, Class& cl); //修改班级信息
void CDelete(char* cclass); //删除班级信息
void CShow(); //遍历列表显示
}; Student::Student(char* name, char* num, float s1, float s2, float s3, float s4)//构造函数
{
strncpy(stuname, name, 20);
strncpy(stunum, num, 12);
stuscore[0] = s1;
stuscore[1] = s2;
stuscore[2] = s3;
stuscore[3] = s4;
total = stuscore[0] + stuscore[1] + stuscore[2] + stuscore[3];
}
void Student::print(int n)//输出函数
{
static bool stuHead = false;
if (!stuHead)
{
if (n > 0)
cout << setw(3) << "序号";
cout << setw(10) << "姓名" << setw(20) << "学号"\
<< setw(6) << "大外" << setw(6) << "高数"\
<< setw(6) << "模电" << setw(10) << "面向对象"\
<< setw(10) << "总分" << endl;
stuHead = true;
}
if (n > 0)
cout << setw(3) << n;
cout << setw(10) << stuname << setw(20) << stunum\
<< setw(6) << stuscore[0] << setw(6) << stuscore[1]\
<< setw(6) << stuscore[2] << setw(10) << stuscore[3]\
<< setw(10) << total << endl;
}
ostream& operator<<(ostream& os, const Student& stu)//读出文件
{
os.write(stu.stuname, 20);
os.write(stu.stunum, 12);
os.write((char*)stu.stuscore, sizeof(stu.stuscore));
os.write((char*)& stu.total, sizeof(float));
return os;
}

//StuList.cpp

void StuList::Add(Student stu) //添加学生信息的函数
{
thestu.push_back(stu);
}
void StuList::Seek(char* num) //按学号查找
{
int sign = -1, i = 0;
list<Student>::iterator it = thestu.begin(); //定义迭代器指针
Student stu;
while (it != thestu.end())
{
stu = *it;
if (strcmp(stu.Getnum(), num) == 0)
{
sign = i;
break;
}
it++;
i++;
}
if (sign >= 0)
{
cout << "找到的结果为" << endl;
stu.print(sign + 1);
}
else
cout << "没有找到!" << endl;


}
void StuList::Show() //遍历列表显示
{
list<Student>::iterator it = thestu.begin(); //定义迭代器指针
int i = 0;

while (it != thestu.end())
{
it->print(++i);
it++;
}
}
void StuList::SorttoFile(char* filename) //按学生总成绩进行排序
{
thestu.sort();
Show();
//排序后的内容保存到文件中
ofstream out(filename);
copy(thestu.begin(), thestu.end(), ostream_iterator<Student>(out));
}
void StuList::Max() //各科的最高分
{

float max[4] = { 0, 0, 0, 0 };

for (int i = 0; i < 4; i++)
{
list<Student>::iterator it = thestu.begin(); //定义迭代器指针
Student stu;
while (it != thestu.end())
{
stu = *it;
if (max[i] < stu.stuscore[i])
max[i] = stu.stuscore[i];
it++;
}
}
cout << "各科的最高分 :" << "大外" << max[0] << "高数" << max[1] << "模电" << max[2] << "面向对象" << max[3] << endl;
}
void StuList::Min() //各科的最低分
{

float min[4] = { 100, 100, 100, 100 };

for (int i = 0; i < 4; i++)
{
list<Student>::iterator it = thestu.begin(); //定义迭代器指针
Student stu;
while (it != thestu.end())
{
stu = *it;
if (min[i] > stu.stuscore[i])
min[i] = stu.stuscore[i];
it++;
}
}
cout << "各科的最低分 :" << "大外" << min[0] << "高数" << min[1] << "模电" << min[2] << "面向对象" << min[3] << endl;
}

//Class.cpp

void Class::CPrint() //输出班级信息
{
cout << setw(3) << "年级" << setw(10) << "班级" << endl;
cout << setw(3) << clgrade << setw(10) << clclass << endl;
cout << setw(3) << "序号";
cout << setw(10) << "姓名" << setw(20) << "学号"\
<< setw(6) << "大外" << setw(6) << "高数"\
<< setw(6) << "模电" << setw(10) << "面向对象"\
<< setw(10) << "总分" << endl;
list<Student>::iterator it = cl.begin();//定义迭代器指针
int i = 0;

while (it != cl.end())
{
it->print(++i);
it++;
}
}

//ClList.cpp

void ClList::CAdd(Class cl) //增加班级信息
{
thecl.push_back(cl);
}
void ClList::CSeek(char* cclass) //查询班级信息
{
int sign = -1;
list<Class>::iterator it = thecl.begin(); //定义迭代器指针
Class cl;
while (it != thecl.end())
{
cl = *it;
if (strcmp(cl.Getclclass(), cclass) == 0)
{
sign = 1;
break;
}
it++;
}
if (sign > 0)
{
cout << "查找的结果为" << endl;
cl.CPrint();
}
else
cout << "没有查找到!" << endl;
}
void ClList::CModify(char* cclass, Class& cl) //修改班级信息
{
list<Class>::iterator it = thecl.begin(); //定义迭代器指针

while (it != thecl.end())
{

if (strcmp((*it).Getclclass(), cclass) == 0)
{
*it = cl;
// sign = 1;
break;
}
it++;
}
cout << "修改的结果为" << endl;
cl.CPrint();
}
void ClList::CDelete(char* cclass) //班级的删除
{
list<Class>::iterator it = thecl.begin();//定义迭代器指针
while (it != thecl.end())
{

if (strcmp((*it).Getclclass(), cclass) == 0)
{
thecl.erase(it);
break;
}
it++;
}
cout << "删除成功" << endl;
}
void ClList::CShow() //年级中所有班级的显示
{
list<Class>::iterator it = thecl.begin(); //定义迭代器指针
Class cl;
while (it != thecl.end())
{
cl = *it;
cl.CPrint();
it++;
}
}int main() //主函数
{
StuList thestu; //存放所有学生
Student stu1("ma", "0803070201", 88, 90, 69, 52.6f);
Student stu2("li", "0803070202", 52, 96, 74, 56);
Student stu3("wang", "0803070101", 85, 25, 95, 79);
Student stu4("yang", "0803070102", 82, 78, 84, 95);
Student stu5("ding", "0803070301", 76, 85.6f, 94, 83);
thestu.Add(stu1);
thestu.Add(stu2);
thestu.Add(stu3);
thestu.Add(stu4);
thestu.Add(stu5);
thestu.Show();

thestu.Seek("0803070201"); //查找学号为0803070201的同学

cout << "排序的结果" << endl;
thestu.SorttoFile("student.dat"); //按总分排序
thestu.Max();
thestu.Min();

StuList s1;
StuList s2;
StuList s3;
s1.Add(stu3);
s1.Add(stu4);
s3.Add(stu5);
s2.Add(stu1);
s2.Add(stu2);

ClList thecl;

Class cl1("二年级", "08030701", s1.Getthestu());
Class cl2("二年级", "08030702", s2.Getthestu());
Class cl3("二年级", "08030703", s3.Getthestu());
thecl.CAdd(cl1);
thecl.CAdd(cl2);
thecl.CShow();
thecl.CSeek("08030702"); //查找班级为08030702的班级
thecl.CAdd(cl3);
cout << "将08030702修改为08030703" << endl;
thecl.CModify("08030702", cl3); //修改班级
cout << "删除08030701班" << endl;
thecl.CDelete("08030701"); //删除08030701班
return 0;
}
...全文
55 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
gouyanfen 2019-06-18
  • 打赏
  • 举报
回复
class Class { } 这样写代码会被打死的 Class(char* grade, char* cclass, list<Student> l) //构造函数 检查你的构造函数需要的数据类型
qq_44501430 2019-06-18
  • 打赏
  • 举报
回复
Class cl1("二年级", "08030701", s1.Getthestu()); Class cl2("二年级", "08030702", s2.Getthestu()); Class cl3("二年级", "08030703", s3.Getthestu()); E0289 没有与参数列表匹配的构造函数 "Class::Class" 实例 ConsoleApplication2 C:\Users\八哥哥\source\repos\ConsoleApplication2\ConsoleApplication2.cpp 353             参数类型为:  (const char [7], const char [9], std::list<Student, std::allocator<Student>>) 这几行一直都是这个错误

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧