On-Machine Exercise 8 Object-oriented programming (an array of objects) Time limit:1000ms Memory limit:65536k The title description uses an array of class objects to complete the input and output of n student data (number is string type, Grade is integer). Input input has n+1 line:
The integer n of the first line indicates the number of students;
The following n rows are data for n students, the first in each row is a string representing the number of students, and the second is an integer representing the student's score. Output output n student data.
One row for each student's data.
Demo sample Input
501 8902 7803 5604 9205 76
Demo sample Output
01 8902 7803 5604 9205 76
Cue source ZLH Demo sample Program
C + + Object array So, how to say it, use it flexibly. Anyway the code is a look can be clear.
#include <iostream> #include <string>using namespace Std;class student{private: string i; int g;public:void in () {cin >> I >> g;} void out () {cout << i << "" << g << Endl;}}; int main () {int n,i;student stu[500];cin>>n;for (i=0;i<n;i++) stu[i].in (); for (i=0;i<n;i++) stu[i].out (); return 0;}
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
Sdut exercise 8 Object-oriented programming (an array of objects)