File tree Expand file tree Collapse file tree
source/chpt_3_ArraysLinkedListsAndRecursion/drawRuler Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55using namespace std ;
66
77class TEMPLATE {
8- public:
8+ public:
99 TEMPLATE ();
1010
11- protected:
11+ protected:
1212
13- private:
13+ private:
1414};
1515
1616#endif
Original file line number Diff line number Diff line change 1+ #include " Ruler.h"
2+ #include < iostream>
3+ #include < ostream>
4+
5+ using namespace std ;
6+
7+ void Ruler::drawOneTick (int tickLength, int tickLabel) {
8+ for (int i = 0 ; i < tickLength; i++) {
9+ cout << " -" ;
10+ }
11+ if (tickLabel >= 0 ) {
12+ cout << " " << tickLabel;
13+ }
14+ cout << endl;
15+ }
16+
17+ void Ruler::drawTicks (int tickLength) {
18+ if (tickLength > 0 ) {
19+ drawTicks (tickLength - 1 );
20+ drawOneTick (tickLength);
21+ drawTicks (tickLength - 1 );
22+ }
23+ }
24+ void Ruler::drawRuler (int nInches, int majorLength) {
25+ drawOneTick (majorLength, 0 );
26+ for (int i = 1 ; i <= nInches; i++) {
27+ drawTicks (majorLength - 1 );
28+ drawOneTick (majorLength, i);
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ class Ruler {
4+ public:
5+ void drawRuler (int nInches, int majorLength);
6+
7+ private:
8+ void drawOneTick (int tickLength, int tickLabel = -1 );
9+ void drawTicks (int tickLength);
10+ };
Original file line number Diff line number Diff line change 1+ #include " Ruler.h"
2+
3+ int main (int argc, char const *argv[]) {
4+ Ruler ruler;
5+ ruler.drawRuler (3 , 3 );
6+ return 0 ;
7+ }
You can’t perform that action at this time.
0 commit comments