问题及代码:
/*。
*Copyright(c)2014,烟台大学计算机学院
*All right reserved,
*文件名:test.cpp
*作者:liu_feng_zi_
*完成日期:2015年6月22日
*版本号:v1.0
*问题描述:常对象及常对象成员
*输入描述:
*程序输出:
*/
#include <iostream>
using namespace std;
class Test
{
private:
int x;
const int y;
public:
Test(int a, int b);
void printxy()const; //(1)
} ;
Test::Test(int a,int b):x(a),y(b) {}
void Test::printxy() const //(3)
{
cout<<"x*y="<<x*y<<endl;
}
int main()
{
int x1,x2;
cin>>x1>>x2;
const Test t(x1,x2);
t.printxy( );
return 0;
}
运行结果: