YTU-OJ-静态成员---计算学生个数
来源:互联网 发布:外文数据库哪个好 编辑:程序博客网 时间:2024/06/08 02:36
Problem J: 填空题:静态成员---计算学生个数
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 114 Solved: 67
[Submit][Status][Web Board]
Description
学生类声明已经给出,在主程序中根据输入信息输出实际建立的学生对象个数,以及所有学生对象的成绩总和。
在下面的程序段基础上完成设计,只提交begin到end部分的代码
#include <iostream>
#include <string>
using namespace std;
class student
{
private:
string name; //学生姓名
int age; //学生年龄
int score; //学生成绩
static int count; //记录学生对象个数
static int sum; //记录所有学生的总成绩
public:
student(string n,int a,int s); //构造函数
static int get_count(); //静态成员函数,获取count的值
static int get_sum(); //静态成员函数,获取sum的值
};
//将程序需要的成份写下来,只提交begin到end部分的代码
//******************** begin ********************
int student::count=0;
_____(1)_______;
________(2)___________
{
name=n;
age=a;
score=s;
count++;
sum+=s;
}
int student::get_count()
{
______(3)_______;
}
int student::get_sum()
{
______(4)______;
}
//********************* end ********************
int main( )
{
string name;
int age;
int score;
int n;
cin>>n; //输入学生对象个数
while(n--)
{
cin>>name>>age>>score;
new student(name,age,score);
}
cout<<"the count of student objects=";
cout<<student::get_count()<<endl;
cout<<"the sum of all students score=";
cout<<student::get_sum()<<endl;
return 0;
}
Input
学生个数
对应学生个数的学生信息(姓名 年龄 成绩)
Output
学生个数
所有学生的成绩之和
Sample Input
3guo 34 98zhang 56 60li 23 87
Sample Output
the count of student objects=3the sum of all students score=245
HINT
只提交begin到end部分的代码
/* *Copyright (c)2015,烟台大学计算机与控制工程学院 *All rights reserved. *作 者:单昕昕 *完成日期:2015年5月16日 *版 本 号:v1.0 */ #include <iostream>#include <string>using namespace std;class student{private: string name; //学生姓名 int age; //学生年龄 int score; //学生成绩 static int count; //记录学生对象个数 static int sum; //记录所有学生的总成绩public: student(string n,int a,int s); //构造函数 static int get_count(); //静态成员函数,获取count的值 static int get_sum(); //静态成员函数,获取sum的值};//将程序需要的成份写下来,只提交begin到end部分的代码//******************** begin ********************int student::count=0;int student::sum=0;student::student(string n,int a,int s){ name=n; age=a; score=s; count++; sum+=s;}int student::get_count(){ return count;}int student::get_sum(){ return sum;}//********************* end ********************int main( ){ string name; int age; int score; int n; cin>>n; //输入学生对象个数 while(n--) { cin>>name>>age>>score; new student(name,age,score); } cout<<"the count of student objects="; cout<<student::get_count()<<endl; cout<<"the sum of all students score="; cout<<student::get_sum()<<endl; return 0;}
0 0
- YTU-OJ-静态成员---计算学生个数
- YTU 2641: 填空题:静态成员---计算学生个数
- [YTU]_2641 9 填空题:静态成员---计算学生个数)
- 静态成员---计算学生个数
- 静态成员——计算学生个数
- OJ第二批——Problem J:填空题:静态成员---计算学生个数
- 第十六周oj刷题——Problem J: 填空题:静态成员---计算学生个数
- OJ第六批——Problem N: 填空题:静态成员---计算学生个数
- 嘻唰唰第六批Problem N: 填空题:静态成员---计算学生个数
- YTU-OJ-友元类-计算两点间距离
- OJ-----计算字符个数
- YTU-OJ-统计程序设计基础课程学生的平均成绩
- YTU-OJ-求类中数据成员的最大值-类模板
- YTU-OJ-类中私有成员的访问
- 华为OJ:计算字符个数
- 【华为OJ】计算字符个数
- 华为oj 计算字符个数
- 华为oj 计算字符个数
- zookeeper和java实现的统一配置管理和集群节点管理简单案例
- 质数
- android自动化测试--编译、生成jar文件,push到手机
- Tomcat 配置 以及一台电脑同时配置上同时配置多个Tomcat
- android之Notification通知
- YTU-OJ-静态成员---计算学生个数
- 基于单链表的循环链表以及双链表的实现
- 类
- Java反射机制学习笔记
- 使用IDE编写python代码
- Codevs1378选课题解
- YTU-OJ-类模板---求数组的最大值
- iOS中TextField 和 TextView 控件的基本使用
- 占空比是什么