正在学习类和接口分离与现实
题目是输入成绩,输出并求均值,要求用类和接口分离与现实
//.h头文件
#include
class GradeList
{
public:
explicit GradeList(std::string);
void setGradeList(std::string);
std::string getGradeList() const;
void DisplayMessage() const;
static void range() ;
private:
std::string courseName;
};
//头文件配套.cpp
#include "GradeList.h"
#include
#include
using namespace std;
GradeList::GradeList(string name)
{
setGradeList(name);
}
void GradeList::setGradeList(string name)
{
if (name.size() <= 25)
{
courseName = name;
}
else
{
courseName = name.substr(0, 25);
cerr << "Name\"" << name << "\"exceeds maximum length" << endl;
}
}
string GradeList::getGradeList()const
{
return courseName;
}
void GradeList::DisplayMessage()const
{
cout<<"Welcome to the grade list for\n"<<getGradeList()<<"!\n"<void GradeList::range()
{
int total;
total = 0;
int i=1;
while(i<=10)
{
cout<<"Enter grade:";
int grade;
grade=0;
cin>>grade;
total+=grade;
i++;
}
int average;
average = total/10;
cout<<"\ntotal of all grades is"<"Class average is"<
//main函数
#include "GradeList.h"
int main()
{
GradeList myGradeList("C++");
myGradeList.DisplayMessage() ;
myGradeList.range();
return 0;
}
编译器报错,看不明白
[1/1] Linking CXX executable AverageGrade.exe
FAILED: AverageGrade.exe
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
运行过一次,残留的后台进程没关?打开任务管理器看看。