第6周实验报告1
2012-03-27 15:39
148 查看
实验目的:学会常对象
实验内容:编码改错
* 程序头部注释开始
* 程序的版权和版本声明部分
* 烟台大学计算机学院学生
* 文件名称: 编码改错
* 作 者: 胡斌
* 完成日期: 2012 年 3月27 日
* 版本号: v1.0
* 程序头部的注释结束(此处也删除了斜杠)
#include <iostream>
using namespace std;
class C
{
private:
int x;
public:
C(int x){this->x = x;}
int getX() const{return x;} //把成员函数改成const型
};
void main()
{
const C c(5);
cout<<c.getX();
system("pause");
}
#include <iostream>
using namespace std;
class C
{
private:
int x;
public:
C(int x){this->x = x;}
int getX() {return x;}
};
void main()
{
C c(5);//把对象改成一般型
cout<<c.getX();
system("pause");
}
![](http://my.csdn.net/uploads/201203/27/1332833971_6204.JPG)
我比较喜欢第一种改法,可以让我熟悉常对象。
实验内容:编码改错
* 程序头部注释开始
* 程序的版权和版本声明部分
* 烟台大学计算机学院学生
* 文件名称: 编码改错
* 作 者: 胡斌
* 完成日期: 2012 年 3月27 日
* 版本号: v1.0
* 程序头部的注释结束(此处也删除了斜杠)
#include <iostream>
using namespace std;
class C
{
private:
int x;
public:
C(int x){this->x = x;}
int getX() const{return x;} //把成员函数改成const型
};
void main()
{
const C c(5);
cout<<c.getX();
system("pause");
}
#include <iostream>
using namespace std;
class C
{
private:
int x;
public:
C(int x){this->x = x;}
int getX() {return x;}
};
void main()
{
C c(5);//把对象改成一般型
cout<<c.getX();
system("pause");
}
我比较喜欢第一种改法,可以让我熟悉常对象。