Programming Question # #: Computes the sum of squares of integers
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
The following program reads an integer n each time, and exits if n is 0, otherwise outputs N and N squared.
#include <iostream>using namespace std;//here to supplement your code int main (int argc, char* argv[]) { CType obj; int n; cin>>n; while (n) { obj.setvalue (n); cout<<obj++<< "" <<obj<<endl; cin>>n; } return 0;}
Input
A k integer. Except for the last data, none of the other data is 0.
Output
K-1 line. Line I outputs the number I input and its square.
Sample input
1 5 8) 9 0
Sample output
1 15 258) 649 81
1#include <iostream>2 using namespacestd;3 //Add your code here4 classCType {5 Public:6 intvalue;7CType (): Value (0) {};8 voidSetValueintN) {9Value =N;Ten } One //You must use the static variable ACType &operator++(int) { - StaticCType tmp =CType (); -Tmp.value =value; theValue *=value; - returntmp; - } - +Friend Ostream &operator<< (Ostream &o, CType &CType) { -o<<Ctype.value; + returno; A } at - }; - intMainintargcChar*argv[]) { - CType obj; - intN; -Cin>>N; in while(n) { - obj.setvalue (n); tocout<<obj++<<" "<<obj<<Endl; +Cin>>N; - } the return 0; *}
POJ C + + programming Problem # #: Calculating sum of squares of integers