C언어 정수 5개를 입력받아 평균보다 큰 정수 출력(ver.1)
너에게제공
644 0 0
#include <iostream>
#include <string>
using namespace std;
class Numbers
{
private:
int size;
int num[5];
float avg;
public:
Numbers();
void calcAvg();
void prnNumber();
};
Numbers::Numbers()
{
size=5;
cout<<"정수를 입력하시오"<<endl;
for(int i=0; i<size; i++)
{ cin>>num[i]; }
}
void Numbers::calcAvg()
{
int sum=0;
for(int j=0; j<size; j++)
{
sum+=num[j];
}
avg=(float)sum/size;
}
void Numbers::prnNumber()
{
cout<<"입력한 숫자 : ";
for(int h=0; h<size; h++)
{
cout<<num[h]<<"t";
}
cout<<"n";
cout<<"평균 : "<<avg<<endl;
cout<<"평균보다 큰 숫자 : ";
for(int k=0; k<size; k++)
{
if(avg<num[k])
cout<<num[k]<<"t";
}
}
void main()
{
Numbers myNum;
myNum.calcAvg();
myNum.prnNumber();
}
#include <string>
using namespace std;
class Numbers
{
private:
int size;
int num[5];
float avg;
public:
Numbers();
void calcAvg();
void prnNumber();
};
Numbers::Numbers()
{
size=5;
cout<<"정수를 입력하시오"<<endl;
for(int i=0; i<size; i++)
{ cin>>num[i]; }
}
void Numbers::calcAvg()
{
int sum=0;
for(int j=0; j<size; j++)
{
sum+=num[j];
}
avg=(float)sum/size;
}
void Numbers::prnNumber()
{
cout<<"입력한 숫자 : ";
for(int h=0; h<size; h++)
{
cout<<num[h]<<"t";
}
cout<<"n";
cout<<"평균 : "<<avg<<endl;
cout<<"평균보다 큰 숫자 : ";
for(int k=0; k<size; k++)
{
if(avg<num[k])
cout<<num[k]<<"t";
}
}
void main()
{
Numbers myNum;
myNum.calcAvg();
myNum.prnNumber();
}