YTU 2641: 빈칸 채우기 문제: 정적 구성원---학생 개수 계산

4567 단어

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<<"the sum of all students score=";
  cout<  return 0;
}

입력


학생 수
학생 개수에 대응하는 학생 정보(성명 연령 성적)

출력


학생 수
모든 학생의 성적의 합

샘플 입력

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;
}

좋은 웹페이지 즐겨찾기