本文主要是介绍第三周【项目4-考了语文数学的学生】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//第三周【项目4-考了语文数学的学生】
#include <iostream>
#include "Stu.h"
using namespace std;
int main()
{
Stu s1,s2;
s1.set_Student("Lin daiyu",98,96);
s2.set_Student("Jia baoyu",90,88);
s1.show();
cout << endl;
s2.show();
cout << endl;
s1.set_name("xue baochai");
s1.show();
cout << endl;
cout << "s1.Name: "<<s1.get_Name() << endl;
cout << "s1.average: "<<s1.average() << endl;
return 0;
}
//Stu.h
#ifndef STU_H_INCLUDED
#define STU_H_INCLUDED
#include <iostream>
using namespace std;
class Stu
{
private:
string name;
float chinese;
float math;
public:
void set_Student(string n,float b,float c );
inline void show()
{
cout<<name<<'\t'<<chinese<<'\t'<<math;
}
inline void set_name(string n)
{
name=n;
}
inline string get_Name()
{
return name;
}
inline double sum()
{
return (math+chinese);
}
inline double average()
{
return sum()/2;
}
};
#endif // STU_H_INCLUDED
//else.cpp
#include <iostream>
#include "Stu.h"
using namespace std;
void Stu::set_Student(string n,float b,float c )
{
name=n;
chinese=b;
math=c;
}
运行结果:
这篇关于第三周【项目4-考了语文数学的学生】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!