Problem C: 农夫果园
Description
一果农,家里有苹果树、梨树,2016年收成不错,现在需要你来编程,求一下去年总共收获了多少斤的水果。
Input
第一行N表示之后有N行输入。
之后的N行输入,每行一个水果。包括一个字符和一个整数。
其中字符是‘a’或‘p’,分别表示是一个苹果或梨。整数是这个水果的重量。
Output
见样例。
Sample Input
Sample Output
HINT
请使用C++的面向对象来实现,练习下如何编写类、使用类。
Append Code
#include <iostream>
using namespace std;class sellFruit
{
private:static int numOfFruits, numOfApples,numOfPeach,numOfAll;
public:sellFruit(){}void setFruit(char f,int h){if(f == 'a'){numOfApples++;numOfFruits++;cout << "The "<<numOfFruits<<"th fruit is created."<< endl;cout << "The "<<numOfApples<<"th apple is created." << endl;}else{numOfFruits++;numOfPeach++;cout << "The "<<numOfFruits<<"th fruit is created."<< endl;cout << "The "<<numOfPeach<<"th peach is created." << endl;}numOfAll += h;}static void getAll(){cout << "There are "<<numOfFruits<<" fruits, including "<<numOfApples<<" apples and "<<numOfPeach<<" peaches. Their total weights is "<<numOfAll<<".";}
};
int sellFruit::numOfAll = 0;
int sellFruit::numOfPeach = 0;
int sellFruit::numOfFruits = 0;
int sellFruit::numOfApples= 0;
int main()
{int num,h;char c;sellFruit *s;cin >> num;s = new sellFruit[num];for(int i = 0;i < num;i++){cin >> c >> h;s[i].setFruit(c,h);}sellFruit::getAll();return 0;
}
Problem C: 农夫果园相关推荐
- Problem A: 农夫果园
Problem A: 农夫果园 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 2089 Solved: 1702 [Submit][Status][ ...
- Problem E: 农夫果园
Home Web Board ProblemSet Standing Status Statistics Problem E: 农夫果园 Time Limit: 1 Sec Memory Limit ...
- 实验9:Problem C: 农夫果园
Home Web Board ProblemSet Standing Status Statistics Problem C: 农夫果园 Problem C: 农夫果园 Time Limit: 1 S ...
- SDUSTOJ1670 Problem C: 农夫果园
Description 秋天到了,果园里的水果成熟了,商贩们来收水果了,农夫们都希望自己的水果能卖个好价钱. 现在果园里有三种水果正在销售,苹果(Apple).香蕉(Banana).梨(Pear).每 ...
- linux下yum错误:[Errno 14] problem making ssl connection Trying other mirror.
所有的base 都要取消注释 mirrorlist 加上注释 另外所有的enable都要设为零 目录 今天是要yum命令安装EPEL仓库后 yum install epel-release 突然发现y ...
- A + B Problem
1001: A + B Problem Description 计算 A + B. Input 多组测试数据,每组测试数据占一行,包括2个整数. Output 在一行中输出结果. Sample Inp ...
- Error:(49, 1) A problem occurred evaluating project ':guideview'. Could not read script 'https://r
出现问题如下: Error:(49, 1) A problem occurred evaluating project ':guideview'. > Could not read script ...
- #418 Div2 Problem B An express train to reveries (构造 || 全排列序列特性)
题目链接:http://codeforces.com/contest/814/problem/B 题意 : 有一个给出两个含有 n 个数的序列 a 和 b, 这两个序列和(1~n)的其中一个全排列序列 ...
- ADPRL - 近似动态规划和强化学习 - Note 3 - Stochastic Infinite Horizon Problem
Stochastic Infinite Horizon Problem 3.Stochastic Infinite Horizon Problem 定义3.1 无限范围的马尔可夫决策过程 (Marko ...
最新文章
- hdu-4825(01字典树)
- VUE:解决 [Vue warn]: Error in render: “TypeError: item.slice is not a function“ (取部分数据)
- 【kafka】kafka BindException: Address already in use 一个失误或者愚蠢的问题
- SQL Server商业智能中ODS表和Dim表必须有的字段
- C#:获取访问端口号
- centos7安装tomcat9过程
- oracle集群如何搭建,Oracle集群搭建步骤.docx
- 我所钟爱的电影之一-文艺片
- 安装Pillow指定版本出错
- CutefishOS 0.6 Beta 发布
- uniny 物体运动到一个点停止_unity控制运动
- DNS资源纪录(Resource Record)介绍
- 你在工作中遇到过印象深刻的困难是什么,你怎么克服的?
- 如何跳过htpps安全连接(webservice/get/post)
- 1小时,不会代码的我如何完成 网易云音乐 大作业网页制作?(IVX 第2篇)
- vue给div绑定keyup的enter事件实现接电话(结合阿里云软电话SDK)
- 程序开发团队之团队精神篇(转)
- 网络安全运维工程师数据库的核心能力有什么?
- android系统提供的常用命令行工具
- Mina MEID Activator 2.120210512更新使用说明支持三网(移动、联通、电信)国行版手机解锁打电话4G苹果手机激活锁停用Hello密码锁绕ID屏幕锁密码