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 题目描述 给出一串具体长度的数据,删除指定数据. 已经给出部分代 ...
随机推荐
- error trying to exec 'cc1plus': execvp: 没有那个文件或目录
出现这个问题,有两种可能: 第一,你没有安装g++ 第二,你的gcc的版本和g++版本不相符合 安装gcc和g++及一些依赖包 sudo apt-get install build-essential ...
- ajax中文乱码解决(java)
方法1: 页面端发出的数据做一次encodeURI,服务器端使用new String(old.getBytes("iso8859-1"), "utf-8") 方 ...
- PHP:Mysqli 基础类
文章来源:http://www.cnblogs.com/hello-tl/p/7592594.html <?php /** * __construct($Mysql_config) 构造函数 $ ...
- history.go history.back()
转http://www.mikebai.com/Article/2009-11/757.html <input type=button value=刷新 onclick="window ...
- TensorFlow - 相关 API
来自:https://cloud.tencent.com/developer/labs/lab/10324 TensorFlow - 相关 API TensorFlow 相关函数理解 任务时间:时间未 ...
- 【06】对AJAX的总结(转)
对AJAX的总结 通过前面对 AJAX 的讲解,我们可以将 AJAX 请求分成以下几个步骤: 创建 XMLHttpRequest 对象: 设置事件处理函数,处理返回的数据: 初始化并发送请求. 可 ...
- Leetcode 207.课程表
课程表 现在你总共有 n 门课需要选,记为 0 到 n-1. 在选修某些课程之前需要一些先修课程. 例如,想要学习课程 0 ,你需要先完成课程 1 ,我们用一个匹配来表示他们: [0,1] 给定课程总 ...
- linux & command line & console & logs
linux & command line & console & logs how to get the logs form linux command console htt ...
- VIM使用技巧15
在vim的插入模式下,有时需要插入寄存器中的文本: 1.使用<C-r>{register} 2.使用<C-r><C-p>{register} 3.使用<C-r ...
- Intent使用Parcelable传递对象
package com.pingyijinren.test; import android.os.Parcel; import android.os.Parcelable; import java.i ...