YTU 2641: 填空题:静态成员---计算学生个数
2641: 填空题:静态成员---计算学生个数
时间限制: 1 Sec 内存限制: 128 MB
提交: 267 解决: 206
题目描述
输入
学生个数
对应学生个数的学生信息(姓名 年龄 成绩)
输出
学生个数
所有学生的成绩之和
样例输入
3
guo 34 98
zhang 56 60
li 23 87
样例输出
the count of student objects=3
the sum of all students score=245
提示
只提交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的值
};
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;
}
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;
}
#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的值
};
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;
}
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;
}
YTU 2641: 填空题:静态成员---计算学生个数的更多相关文章
- 第十六周oj刷题——Problem J: 填空题:静态成员---计算学生个数
Description 学生类声明已经给出.在主程序中依据输入信息输出实际建立的学生对象个数,以及全部学生对象的成绩总和. Input 学生个数 相应学生个数的学生信息(姓名 年龄 成绩) ...
- YTU 2586: 填空题B-字画鉴别
2586: 填空题B-字画鉴别 时间限制: 1 Sec 内存限制: 128 MB 提交: 509 解决: 131 题目描述 注:本题只需要提交填写部分的代码,请按照C语言方式提交. 古玩店老板小勇 ...
- YTU 2579: 填空题----删除指定字符
2579: 填空题----删除指定字符 时间限制: 1 Sec 内存限制: 128 MB 提交: 164 解决: 61 题目描述 小明想要做个小程序,能够删除字符串中特定的字符. 例如:想要在下面 ...
- YTU 2642: 填空题:类模板---求数组的最大值
2642: 填空题:类模板---求数组的最大值 时间限制: 1 Sec 内存限制: 128 MB 提交: 646 解决: 446 题目描述 类模板---求数组的最大值 找出一个数组中的元 ...
- OJ题:计算各个数的位数之和
题目描述: 输入一个大于0的数,要求各个位数的和. 例如: 输入12345 那么输出15 程序如下: ) ; }
- 计算概论(A)/基础编程练习2(8题)/8:1的个数
#include<stdio.h> int main() { ; // 存储测试数据的二进制形式中1的个数 int bian[N]; // 输入十进制整数N 表示N行测试数据 scanf( ...
- 计算概论(A)/基础编程练习2(8题)/7:整数的个数
#include<stdio.h> int main() { ] = {}; // 输入k个正整数 scanf("%d",&k); // 循环读入和进行算术 w ...
- YTU 2607: A代码填空题--更换火车头
2607: A代码填空题--更换火车头 时间限制: 1 Sec 内存限制: 128 MB 提交: 91 解决: 73 题目描述 注:本题只需要提交填写部分的代码,请按照C++方式提交. 假设火车有 ...
- YTU 2601: 熟悉题型——填空题(删除线性表节点)
2601: 熟悉题型--填空题(删除线性表节点) 时间限制: 1 Sec 内存限制: 128 MB 提交: 357 解决: 212 题目描述 给出一串具体长度的数据,删除指定数据. 已经给出部分代 ...
随机推荐
- vijos1382寻找主人
题目大意: 给出两个串(长度<=1e6),问是否同构,如果同构输出最小表示. 题解: 这是最小表示法模板题.在这里好好讲一下最小表示法. 首先有一个最暴力的方法:把所有表示搞出来排序. 时间复杂 ...
- [SCOI2011]棘手的操作(可并堆/并查集/线段树)
我懒死了 过于棘手 但这题真的很水的说 毕竟写啥都能过 常见思路: ①:由于不强制在线,所以重新编号之后线段树维护 ②:用各种可以高速合并的数据结构,比如可并堆,可并平衡树啥的 讲一种无脑算法: 对于 ...
- Python面试快问快答,理论要的就是速度与精准,Python面试题No2
今天的面试题 第1题:python2和python3的range(100)的区别 range()函数的含义 range函数是一个用来创建算数级数序列的通用函数,返回一个[start, start + ...
- 杭电 2035 (快速幂) 求A^B的最后三位数表示的整数
Description 求A^B的最后三位数表示的整数. 说明:A^B的含义是“A的B次方” Input 输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B&l ...
- UVA 230 Borrowers (STL 行读入的处理 重载小于号)
题意: 输入若干书籍和作者名字,然后先按作者名字升序排列,再按标题升序排列,然后会有3种指令,BORROW,RETURN, SHELVE. BORROW 和 RETURN 都会带有一个书名在后面,如: ...
- Vue如何引入jquery实现平滑滚动到指定位置效果
在以往的做法里首选jquery的animate实现,但是Vue里并没有这个方法.如何在Vue项目中实现点击导航平滑滚动到指定位置,为了这效果我是快要崩溃了,上网查阅了很久发现并没有真正意义上解决这个问 ...
- Uvalive - 3026 Period (kmp求字符串的最小循环节+最大重复次数)
参考:http://www.cnblogs.com/jackge/archive/2013/01/05/2846006.html 总结一下,如果对于next数组中的 i, 符合 i % ( i - n ...
- POJ 1769_Minimizing maximizer
题意: 一系列m个1~n区间,每个区间固定对某个子区间进行排序,顺序选择若干区间,使最终覆盖所有区间. 分析: computes the length of the shortest subseque ...
- Delphi:Indy9的IdFTP完全使用
Delphi 7自带的INDY控件,其中包含了IdFTP,可以方便的实现FTP客户端程序,参考自带的例子,其中有上传.下载.删除文件,但是不包含对文件夹的操作,得自己实现上传.下载.删除整个文件夹(带 ...
- Minimum Depth of Binary Tree(二叉树DFS)
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...