急求!!!C++编程题,如果有需要可以提高悬赏!!!
3个回答
展开全部
//没有调试,自己调试吧!浪费了我几个小时。。。
//student.hpp
#include<iostream>
#include <string>
#include <map>
using namespace std;
enum ESex
{
ESex_male = 0,
ESex_female
};
class student
{
public:
student():m_number(0), m_strName(""), m_ESex(ESex_female), m_total(0)
{
}
virtual ~student()
{
//NULL
}
int getNumber()
{
return m_number;
}
string getName()
{
return m_strName;
}
virtual void changeStudentInfo() = 0;
virtual double getAverageScores() = 0;
virtual double getOneCourseScores(ECourseB courseType) = 0;
virtual void showAllinfo() = 0;
void showBaseInfo()
{
printf("num:%d, name:%s, sex:%s, \n\ttotalScores:%f\n\t",
m_number, m_strName.c_str(), (m_ESex)?"female":"male", m_total);
}
int m_number;
string m_strName;
ESex m_ESex;
double m_total;
};
enum ECourseA
{
ECourseA_english,
ECourseA_math,
ECourseA_chinese,
ECourseA_physics,
ECourseA_chemistry,
ECourseA_biology,
ECourseA_Num
};
string strCourseA[ECourseA_Num] =
{
"english", "math", "chinese", "physics", "chemistry", "biology"
};
enum ECourseB
{
ECourseB_english,
ECourseB_math,
ECourseB_chinese,
ECourseB_Num
};
string strCourseB[ECourseB_Num] =
{
"english", "math", "chinese"
};
class studentA:public student
{
public:
studentA()
{
memset(m_scores, 0, sizeof(m_scores));
}
~studentA()
{
cout << "This procedure coding by A type student:" << m_strName << endl;
}
void changeStudentInfo();
double getAverageScores();
double getOneCourseScores(ECourseB courseType);
void showAllinfo();
private:
double m_scores[ECourseA_Num];
};
class studentB:public student
{
public:
studentB()
{
memset(m_scores, 0, sizeof(m_scores));
}
~studentB()
{
cout << "This procedure coding by B type student: " << m_strName << endl;
}
void changeStudentInfo();
double getAverageScores();
double getOneCourseScores(ECourseB courseType);
void showAllinfo();
private:
double m_scores[ECourseB_Num];
};
//student.cpp
#include "student.hpp"
void studentA::changeStudentInfo()
{
cout << "input student number:";
cin >> m_number;
cout << "input student sex(0 is male, 1 is female):";
cin >> m_ESex;
cout << "input student name:";
cin >> m_strName;
for (int i = 0; i < ECourseA_Num; ++i)
{
cout << "input student " << strCourseA[i] << "scores:";
cin >> m_scores[i];
m_total += m_scores[i];
}
}
double studentA::getAverageScores()
{
double totalScores = 0;
for (int i = 0; i < ECourseA_Num; ++i)
{
totalScores += m_scores[i];
}
return totalScores / ECourseA_Num;
}
double studentA::getOneCourseScores(ECourseA courseType)
{
return m_scores[courseType];
}
void studentA::showAllinfo()
{
showBaseInfo();
for (int i = 0; i < ECourseA_Num; ++i)
{
printf("%s:%f\n", strCourseA[i], m_scores[i]);
}
}
void studentB::changeStudentInfo()
{
cout << "input student number:";
cin >> m_number;
cout << "input student sex(0 is male, 1 is female):";
cin >> m_ESex;
cout << "input student name:";
cin >> m_strName;
for (int i = 0; i < ECourseA_Num; ++i)
{
cout << "input student " << strCourseA[i] << "scores:";
cin >> m_scores[i];
m_total += m_scores[i];
}
}
double studentB::getAverageScores()
{
double totalScores = 0;
for (int i = 0; i < ECourseB_Num; ++i)
{
totalScores += m_scores[i];
}
return totalScores / ECourseB_Num;
}
double studentB::getOneCourseScores(ECourseB courseType)
{
return m_scores[courseType];
}
void studentB::showAllinfo()
{
showBaseInfo();
for (int i = 0; i < ECourseB_Num; ++i)
{
printf("%s:%f\n", strCourseB[i], m_scores[i]);
}
}
//oneClass.hpp
#include "student.hpp"
#define NUM_OF_STUDENT_A 2 //一个班中的 A类学生个数
#define NUM_OF_STUDENT_B 3 //一个班中的 B类学生个数
class OneClass
{
public:
OneClass();
~OneClass();
void CalculateEveryCourseAverageScores();
void calculateEveryStudentAverageScores();
void ShowAllStudentInfo();
void findStudent(int num);
void findStudent(string name);
private:
map<int , student*> m_numberMap;
map<stirng, student*> m_nameMap;
student* m_studentA[NUM_OF_STUDENT_A];
student* m_studentB[NUM_OF_STUDENT_B];
};
//oneClass.cpp
#include "oneClass.hpp"
OneClass::OneClass()
{
for (int AIndex = 0; AIndex < NUM_OF_STUDENT_A; AIndex++)
{
m_studentA[AIndex] = new studentA();
m_studentA[AIndex]->changeStudentInfo();
m_numberMap[m_studentA[AIndex].getNumber()] = m_studentA[AIndex];
m_nameMap[m_studentA[AIndex].getName()] = m_studentA[AIndex];
}
for (int BIndex = 0; BIndex < NUM_OF_STUDENT_B; BIndex++)
{
m_studentB[BIndex] = new studentB();
m_studentB[BIndex]->changeStudentInfo();
m_numberMap[m_studentB[BIndex].getNumber()] = m_studentB[BIndex];
m_nameMap[m_studentB[BIndex].getName()] = m_studentB[BIndex];
}
}
~OneClass::OneClass()
{
for (int AIndex = 0; AIndex < NUM_OF_STUDENT_A; AIndex++)
{
delete m_studentA[AIndex];
}
for (int BIndex = 0; BIndex < NUM_OF_STUDENT_B; BIndex++)
{
delete m_studentB[BIndex];
}
}
void OneClass::CalculateEveryCourseAverageScores()
{
for (int i = 0; i < ECourseA_Num; ++i)
{
double total = 0.0;
double average = 0.0;
double maxScores = 0;
double minScores = 100;
for (int AIndex = 0; AIndex < NUM_OF_STUDENT_A; AIndex++)
{
double tempScores = m_studentA[AIndex]->getOneCourseScores(i);
total += tempScores;
maxScores = (tempScores > maxScores)?tempScores:maxScores;
minScores = (tempScores < minScores)?tempScores:minScores;
}
if (i <= ECourseA_chinese)
{
for (int BIndex = 0; BIndex < NUM_OF_STUDENT_B; BIndex++)
{
double tempScores = m_studentB[BIndex]->getOneCourseScores(i)
total += tempScores;
maxScores = (tempScores > maxScores)?tempScores:maxScores;
minScores = (tempScores < minScores)?tempScores:minScores;
}
average = total/(NUM_OF_STUDENT_A + NUM_OF_STUDENT_B);
}
else
{
average = total/(NUM_OF_STUDENT_A);
}
cout << strCourseA[i] << " average scores is " << average << endl;
cout << strCourseA[i] << " max scores is " << average << endl;
cout << strCourseA[i] << " min scores is " << average << endl;
}
}
void OneClass::calculateEveryStudentAverageScores()
{
for (int AIndex = 0; AIndex < NUM_OF_STUDENT_A; ++AIndex)
{
cout << m_studentA[AIndex]->getName << "average is " << ()m_studentA[AIndex]->getAverageScores() << endl;
}
for (int BIndex = 0; BIndex < NUM_OF_STUDENT_B; ++BIndex)
{
cout << m_studentB[BIndex]->getName << "average is " << ()m_studentB[BIndex]->getAverageScores() << endl;
}
}
void OneClass::changeOneStudentInfo(int num)
{
if (m_numberMap.find(num) == m_numberMap.end())
{
cout << "can not find this student: " << num << endl;
return;
}
m_numberMap[num]->changeStudentInfo();
}
void OneClass::changeOneStudentInfo(int name)
{
if (m_nameMap.find(name) == m_nameMap.end())
{
cout << "can not find this student: " << name << endl;
return;
}
m_nameMap[name]->changeStudentInfo()
}
void OneClass::ShowAllStudentInfo()
{
for (int AIndex = 0; AIndex < NUM_OF_STUDENT_A; ++AIndex)
{
m_studentA[AIndex]->showAllinfo();
}
for (int BIndex = 0; BIndex < NUM_OF_STUDENT_B; ++BIndex)
{
m_studentB[BIndex]->showAllinfo();
}
}
void OneClass::findStudent(int num)
{
if (m_numberMap.find(num) == m_numberMap.end())
{
cout << "can not find this student: " << num << endl;
return;
}
m_numberMap[num]->showAllinfo();
}
void OneClass::findStudent(string name)
{
if (m_nameMap.find(name) == m_nameMap.end())
{
cout << "can not find this student: " << name << endl;
return;
}
m_nameMap[name]->showAllinfo();
}
//main.cpp
#include "oneClase.hpp"
int main()
{
OneClass myClass;
myClass.changeOneStudentInfo("gougou");
myClass.findStudent(0);
return 0;
}
展开全部
课程难道是自己随便选几个吗,感觉这题目不清不楚的
更多追问追答
追问
所有要求全都要有
追答
看来看去也用不到函数重载,重载要么是参数类型不同要么是参数数量不同,本题求平均成绩用不着参数啊。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
MFC可以吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询