Created
April 28, 2018 05:31
-
-
Save FraGoTe/496eadf5a38634e0c5c7abc31554b531 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using std::cout; | |
using std::endl; | |
class Increment { | |
public: | |
Increment( int c = 0, int i = 1 ); // default constructor | |
void addIncrement() | |
{ | |
count += increment; | |
} // end function addIncrement | |
void print() const; // prints count and increment | |
private: | |
int count; | |
const int increment; // const data member | |
}; // end class Increment | |
// constructor | |
Increment::Increment( int c, int i ) | |
: count( c ), // initializer for non-const member | |
increment( i ) // required initializer for const member | |
{ | |
// empty body | |
} // end constructor Increment | |
// print count and increment values | |
void Increment::print() const | |
{ | |
cout << "count = " << count | |
<< ", increment = " << increment << endl; | |
} // end function print | |
int main() | |
{ | |
Increment value( 10, 5 ); | |
cout << "Before incrementing: "; | |
value.print(); | |
for ( int j = 0; j < 3; j++ ) { | |
value.addIncrement(); | |
cout << "After increment " << j + 1 << ": "; | |
value.print(); | |
} | |
return 0; | |
} // end main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment