您的位置:首页 > 其它

MOOC程序设计期中考试1.9

2014-05-04 00:02 246 查看
输出与样例输出相同的结果

#include <iostream>
#include <string>
using namespace std;

class Student {
private:
int id;
static int count;
public:

// 在此处补充你的代码


};
int Student::count;
void PrintCount() {
cout << "Total " << Student::count << " students" << endl;
}
void Print(Student s)
{
cout << "the id is " << s.id << endl;
}

int main()
{
Student::InitCount();
Student s;
PrintCount();
Student s1(10);
Student s2(s1);
PrintCount();
Print(s2);
PrintCount();
return 0;
}


输入

输出
Total 1 students

Total 3 students

the id is 10

Total 3 students
样例输入


样例输出
Total 1 students
Total 3 students
the id is 10
Total 3 students#include <iostream> #include <string> using namespace std; class Student { private: int id; static int count; public:
static Student InitCount(){return count = 0;};
Student(){count = 1;}
Student(int n){id = n;count = 3;}
Student(const Student &c)
{
id = c.id;

}

friend void PrintCount();
friend void Print(Student s);
};
int Student::count;
void PrintCount() {
cout << "Total " << Student::count << " students" << endl;
}
void Print(Student s)
{
cout << "the id is " << s.id << endl;
}

int main()
{
Student::InitCount();
Student s;
PrintCount();
Student s1(10);
Student s2(s1);
PrintCount();
Print(s2);
PrintCount();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: