-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecursion(number-pattern).cpp
178 lines (127 loc) · 3.42 KB
/
recursion(number-pattern).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <iostream>
#include <cmath>
using namespace std;
class pattern {
private:
int userNumber;
void printAscendingLine(int num) {
if (num > 0) {
printAscendingLine(num - 1);
cout << " " << num;
}
}
void printDesendingLine(int num) {
if (num > 0) {
cout << " " << num;
printDesendingLine(num - 1);
}
}
void printStericLine(int num) {
if (num > 0) {
cout << " *";
printStericLine(num - 1);
}
}
void printWhiteLine(int num) {
if (num > 0) {
cout << " ";
printWhiteLine(num - 1);
}
}
void printAlphabets(int num, int &counter, int i = 0) {
if (i < num) {
cout << static_cast<char>(64 + counter);
counter++;
i++;
printAlphabets(num, counter, i);
}
}
public:
pattern() {
userNumber = 0;
}
pattern(int num) {
userNumber = num;
// pattern(num - 1);
}
void ascendingNumberPattern(int num) {
if (num > 0) {
printAscendingLine(num);
cout << endl;
ascendingNumberPattern(num - 1);
}
}
void desendingNumberPattern(int num) {
if (num > 0) {
printDesendingLine(num);
cout << endl;
desendingNumberPattern(num - 1);
}
}
void printPlainPattern(int num) {
if (num > 0) {
printStericLine(num);
cout << endl;
printPlainPattern(num - 1);
}
}
void printPlainReversePattern(int num) {
if (num > 0) {
printPlainReversePattern(num - 1);
cout << endl;
printStericLine(num);
}
}
void printDiamond(int num, int counter = 1) {
if (counter <= num) {
if (counter <= (num/2)) {
printWhiteLine((num/2) - counter);
printStericLine(counter * 2);
cout << endl;
}
else {
printWhiteLine(counter - (num/2));
printStericLine((num - counter) * 2);
cout << endl;
}
printDiamond(num, (counter + 1));
}
}
void printDiamondOdd(int num, int counter = 1) {
if (counter <= num) {
if (counter <= ceil(num / 2.0)) {
printWhiteLine(ceil(num / 2.0) - counter);
printStericLine(counter);
printStericLine(counter - 1);
}
else {
printWhiteLine(counter - ceil(num / 2.0));
printStericLine((num - counter) + 1);
printStericLine(num - counter);
}
cout << endl;
printDiamondOdd(num, counter + 1);
}
}
void printAlphabetPattern(int num, int counter, int num1) {
if (num1 <= num) {
printAlphabets(num1, counter);
cout << endl;
printAlphabetPattern(num, counter, num1 + 1);
}
}
};
int main() {
pattern p1;
int number;
char yesOrNo;
cout << "\nDo you want to some patterns da? ";
cin >> yesOrNo;
if (yesOrNo == 'y') {
cout << "\nEnter number: ";
cin >> number;
p1 = pattern(number);
p1.printAlphabetPattern(number, 1, 1);
}
return 0;
}