YTU 2641: 빈칸 채우기 문제: 정적 구성원---학생 개수 계산
2641: 빈칸 채우기 문제: 정적 구성원---학생 개수 계산
시간 제한: 1 Sec
메모리 제한: 128MB
제출: 267
해결: 206
제목 설명
학생류 성명은 주 프로그램에서 입력된 정보에 따라 실제 구축된 학생 대상 개수와 모든 학생 대상의 성적 총계를 제시했다.
다음 프로그램 구간에서 설계를 완성하고 begin에서end 부분의 코드만 제출합니다
#include
#include
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의 값 가져오기
};
//프로그램에 필요한 성분을 적어서 begin에서end 부분의 코드만 제출
//******************** begin ********************
int student::count=0;
_____(1)_______;
________(2)___________
{
name=n;
age=a;
score=s;
count++;
sum+=s;
}
int student::get_count()
{
______(3)_______;
}
int student::get_sum()
{
______(4)______;
}
//********************* end ********************
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<
cout<
}
입력
학생 수
학생 개수에 대응하는 학생 정보(성명 연령 성적)
출력
학생 수
모든 학생의 성적의 합
샘플 입력
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;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.