Programming Question # #: Output specified result two
Source: Peking University Online Program evaluation system POJ (Coursera statement: The exercises completed on POJ will not count to the final results of Coursera. )
Total time limit: 1000ms memory limit: 1024kB
Describe
Fill in the blanks to make the output of the program conform to the following requirements.
#include <iostream> #include <map>using namespace std;//here to supplement your code int a::count = 0;void func (b b) {}int main () { A A1 (5), A2; cout << a::count << Endl; B B1 (4); cout << a::count << Endl; Func (B1); cout << a::count << Endl; A * pa = new B (4); cout << a::count << Endl; Delete pa; cout << a::count << Endl; return 0;}
Input
No input required.
Output
The result of the program output is:
2
3
B::d estructor
A::d estructor
3
4
B::d estructor
A::d estructor
3
B::d estructor
A::d estructor
A::d estructor
A::d estructor
Sample input
No input required.
Sample output
23B::d estructora::d estructor34b::d estructora::d estructor3b::d estructora::d estructora::d estructora::d estructor
Tips
int a::count = 0; This variable is used to record the total number of classes A and class A of the derived class object.
1#include <iostream>2#include <map>3 using namespacestd;4 //Add your code here5 classA {6 Public:7 Static intcount;8A () {count++;}9AintA) {count++;}Ten Virtual~A () { Onecout<<"A::d estructor"<<Endl; A } - void operator Delete(void*a) { -count--; the } - }; - classB: PublicA { - Public: + B (): A () {} -Bintb): A () {} +B &operator= (B &b) { A returnb; at } - Virtual~B () { -cout<<"B::d estructor"<<Endl; - } - }; - intA::count =0; in voidfunc (b b) {} - intMain () to { +A A1 (5), A2; -cout << A::count <<Endl; theB B1 (4); *cout << A::count <<Endl; $ func (B1);Panax Notoginsengcout << A::count <<Endl; -A * PA =NewB4); thecout << A::count <<Endl; + DeletePA; Acout << A::count <<Endl; the return 0; +}
POJ C + + Programming Program # # #: Output specified result two