实验九 类和对象的使用.docVIP

  • 36
  • 0
  • 约7.41千字
  • 约 12页
  • 2018-01-09 发布于河南
  • 举报
实验九 类和对象的使用

一.实验目的 1. 掌握构造函数和析构函数的概念和使用方法。 2. 掌握对象数组的使用方法。 3. 掌握类静态成员的定义和使用方法。 4. 掌握友元的定义和使用方法 二.实验任务 1. 用类的成员函数求下列函数的值: 在main函数中重复输入x(x的值必须通过对象初始化得到),多次求y的值。 程序: #includeiostream #includecmath using namespace std; class Box { private: float x, y; public: void input(); void cal(); }box; void Box::input() { cout 请输入x的值:; cin x; } void Box::cal() { if (x -3)y = x + 10; else if (x 5)y = sqrt(x + 3) + x; else y = exp(x); cout y=y endl; } int main() { int i; for (;;) { box.input(); box.cal(); cout 还要继续计算吗?1--YES,0--NO; cin i; if (!i)break; } system(pause); return 0; } 结果: #i

文档评论(0)

1亿VIP精品文档

相关文档