16th Week OJ Brush question--problem J: Fill in the blanks: static members---Calculate the number of students

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.