Description Student class declaration has been given, in the main program according to the input information output the actual number of student objects, as well as the sum of all student objects results. Input
Number of students
Student information corresponding to the number of students (name Age score)
Output
Number of students
The sum of all students ' grades
Sample Input
3guo 98zhang 60li 87
Sample Output
The count of student objects=3
/* All rights reserved. * File name: Test.cpp * Chen Dani * Completion Date: June 27, 2015 * Version number: v1.0 * * #include <iostream> #include <string>using namespace Std;class student{private:string name; Student name int age; Student age int score; Student scores static int count; Record number of student objects static int sum; Record all students ' total public:student (string n,int a,int s); constructor static int get_count (); Static member function, gets the value of Count static int get_sum (); Static member function, gets the value of 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; Enter the number of student objects 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 allStudents score= "; Cout<<student::get_sum () <<endl; return 0;}
Learning experience: Static data members are not difficult, very easy, continue to refuel efforts!!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
16th Week OJ Brush question--problem J: Fill in the blanks: static members---Calculate the number of students