Skip to content

Commit 34d11fb

Browse files
committed
ruler
1 parent 2ac0028 commit 34d11fb

4 files changed

Lines changed: 50 additions & 3 deletions

File tree

helloWorld/classTemplate.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
using namespace std;
66

77
class TEMPLATE {
8-
public:
8+
public:
99
TEMPLATE();
1010

11-
protected:
11+
protected:
1212

13-
private:
13+
private:
1414
};
1515

1616
#endif
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
}

0 commit comments

Comments
 (0)