文件名称:counter
介绍说明--下载内容来自于网络,使用问题请自行百度
定义一个类,类名为CounterType。这个类的对象用于计数,记录一个非负的整数。为该类写一个默认构造函数,它能将计数器置0;再写一个构造函数,它接收一个参数,用于将计数器设为由参数指定的值。编写两个成员函数,分别使计数能够递增1和递减1。确保任何成员函数都不允许计数器为负值。成员函数void reset( );能在任何时候将计数器的值重置为0。编写两个成员函数,一个返回当前计数器的值,另一个将计数器的值输出到一个流,这个用于输出的函数有一个ostream类型的形式参数(被调用时,实际参数可以是cout)。考虑哪些成员函数定义为常成员函数。
定义主函数,测试这个类。(Define a class named CounterType. The object of this class is used for counting, recording a non negative integer. Write a default constructor for this class. It can set the counter to 0, and then write a constructor, which receives a parameter, which is used to set the counter to the value specified by the parameter. Two member functions are written to increase the count by 1 and decrease by 1 respectively. Make sure that any member function does not allow the counter to be negative. The member function void reset (); can reset the value of the counter to 0 at any time. Two member functions are written, one returns the value of the current counter, and the other outputs the counter value to a stream. The output function has a ostream type formal parameter (when called, the actual parameter can be cout). Consider which member functions are defined as regular member functions.
Define the main function and test the class.)
定义主函数,测试这个类。(Define a class named CounterType. The object of this class is used for counting, recording a non negative integer. Write a default constructor for this class. It can set the counter to 0, and then write a constructor, which receives a parameter, which is used to set the counter to the value specified by the parameter. Two member functions are written to increase the count by 1 and decrease by 1 respectively. Make sure that any member function does not allow the counter to be negative. The member function void reset (); can reset the value of the counter to 0 at any time. Two member functions are written, one returns the value of the current counter, and the other outputs the counter value to a stream. The output function has a ostream type formal parameter (when called, the actual parameter can be cout). Consider which member functions are defined as regular member functions.
Define the main function and test the class.)
(系统自动生成,下载前可以参看下载内容)
下载文件列表
文件名 | 大小 | 更新时间 |
---|---|---|
counter.c | 507 | 2017-12-23 |
counter.h | 507 | 2017-12-23 |
ReadMe.txt | 1250 | 2017-12-23 |
本网站为编程资源及源代码搜集、介绍的搜索网站,版权归原作者所有! 粤ICP备11031372号
1999-2046 搜珍网 All Rights Reserved.