e_4_1_182_刘星辰.cpp

来自「对整数进行判别」· C++ 代码 · 共 58 行

CPP
58
字号
#include<iostream.h>
class CheckINT
{
public:
	CheckINT();
	void Check(int);  
	void show();
private:
	int positiveCount;
	int negativeCount;
	int zeroCount;
};
CheckINT::CheckINT()
{
	positiveCount=0;
	negativeCount=0;
	zeroCount=0;
}
void CheckINT::Check(int n)
{
	if (n>0)
	  positiveCount=positiveCount+1;
    if (n<0)
	  negativeCount=negativeCount+1;
	if (n==0)
	  zeroCount=zeroCount+1;
}
void CheckINT::show()
{
	int s;
    s=positiveCount+negativeCount+zeroCount;
	cout<<"所判别的整数共"<<s<<"个"<<endl;
    cout<<"其中正整数"<<positiveCount<<"个,";
	cout<<"负整数"<<negativeCount<<"个,";
	cout<<"零"<<zeroCount<<"个。"<<endl;
}
void CheckInputValue(int in[], int num, CheckINT &checker)
{
	int k;
	for(k=0;k<num;k++)
		checker.Check(in[k]);
}
main()
{
	int sum,i;
	int number[100];
	CheckINT N;
	cout<<"请输入所要判别的整数的总数为:";
	cin>>sum;
	cout<<"请输入所要判别的整数:"<<endl;
	for(i=0;i<sum;i++)
	{
		cin>>number[i];
	}
	CheckInputValue(number,sum,N);
	N.show();
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?