简单的c++实现学生类Student属性有姓名、年龄、C++分数、高等数学分数等请编写代码实现输出成绩优秀的学生的个数成绩优秀指的是C++分数和高等数学分数都大于等于90 void isGood 判断学生对象自己是不是优秀学生如果是是的话优秀的学生的个数+1 static int getCount用户自己输入学生信息
#include
class Student { private: string name; int age; int cppScore; int mathScore; static int count; // 优秀学生个数 public: Student(string n, int a, int cpp, int math): name(n), age(a), cppScore(cpp), mathScore(math) {} void isGood() { if (cppScore >= 90 && mathScore >= 90) { count++; } } static int getCount() { return count; } };
int Student::count = 0;
int main() { int n; cout << "请输入学生人数:"; cin >> n; for (int i = 1; i <= n; i++) { string name; int age, cpp, math; cout << "请输入第" << i << "个学生的姓名、年龄、C++分数、高等数学分数:"; cin >> name >> age >> cpp >> math; Student s(name, age, cpp, math); s.isGood(); } cout << "成绩优秀的学生个数为:" << Student::getCount() << endl; return 0; }
原文地址: https://www.cveoy.top/t/topic/bZri 著作权归作者所有。请勿转载和采集!