-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdemo.cpp
310 lines (192 loc) · 8.17 KB
/
demo.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
// Created by: @PySaqib -- Saqib Ali
// 06th Aug, 2020
// MIT License
// Including the library for functionality.
// UR: Saare functions ke kaam karne keliye ham library use karenge.
#include "training-wheels-urdu.h"
// shuroo signifies the start of program.
// UR: shuroo ka matlab program ka start.
shuroo
// To show anything on screen.
// IR: Screen par kuch bhi dikhaane keliye yeh command use karein.
dikhao("Hello, World"); // text
dikhao(123456); // number
// To go to the next line.
// UR: Screen par agli line par jaane keliye.
agli_line;
// To store numbers.
// UR: Numbers store karne keliye.
num_rakho a = 123456789;
dikhao(a);
agli_line;
// num_rakho tells program that we need space for a number.
// 'a' is the name of the number.
// = 123456789 tells program to put this number at a.
// UR:
// num_rakho program ko yeh batata hai ke hame number store karna hai.
// 'a' uss number ka naam hai.
// = 123456789 se number a ke andar store hojaata hai.
letter_rakho c = 'c';
dikhao(c);
agli_line;
// Just like num_rakho, letter_rakho stores a single letter at c.
// UR: num_rakho ki tarah, letter_rakho sirf aik letter ko c mein rakh dega.
text_rakho name = "Saqib Ali";
dikhao(name);
agli_line;
// text_rakho helps you to store complete words and texts.
// UR: text_rakho se aap complete texts rakh sakte ho.
// agar(condition) {} warna {} can be used for decision making
// UR: agar(condition) {} warna {} se aap computer se faisla karwa sakte ho
// If the condition in the brackets is true, then the code is executed.
// Else, the code in warna block will be executed.
// UR: agar(condition) me di gayi condition theek honay par {} ke andar waala code run hoga.
// UR: condition ghalat honay par warna waala block chalega.
// In this example, the code prints "naam saqib hai" if the name is "Saqib Ali".
// UR: iss example mein, agar naam "Saqib Ali" hoga tou program "naam saqib hai" dikhaayega.
agar(name == "Saqib Ali") {
dikhao("naam saqib hai");
agli_line;
} warna {
dikhao("naam saqib nahi hai");
agli_line;
}
// agar (condition) {} warna_agar(condition) {} warna {} can be used for multiple decision making/
// UR: agar (condition) {} warna_agar(condition) {} warna {} kaafi ziada decisions ko sambhaalne keliye
// istemaal hosakti hai.
// In this example, we can build a name recognizer.
// UR: iss example me ham aik naam pehchaan'ne waala program bana sakte hein.
agar (name == "Saqib Ali") {
dikhao("naam saqib ali");
agli_line;
} warna_agar (name == "Ahmed") {
dikhao("naam ahmed hai");
agli_line;
} warna {
dikhao("me naam nahi jaanta");
agli_line;
}
// In the example above we can see that the program will check for
// two conditions. If the name is Saqib Ali, the program will tell us.
// If it is Ahmed, program will tell us. Lastly, if it is neither of those,
// program will say that "me naam nahi jaanta".
// UR: upar example me program 2 cheezen check karraha hai.
// UR: agar naam Saqib hua tou program hame bata dega.
// UR: agar naam Ahmed hua tou program hame bata dega.
// UR: lekin agar naam in dono me se koi bhi na hua tou program keh dega ke
// UR: "me naam nahi jaanta"
// repeat(n) {} can be used to repeat things.
// UR: repeat(n) {} se ham koi bhi cheez n times repeat karwa sakte hein.
// In this example, we will print my name 5 times.
// UR: iss example mein ham "Saqib" 5 dafa print karwayenge.
repeat(5) {
dikhao("Saqib");
agli_line;
}
// jab_tak(condition) {} can be used to repeat something until the condition is true.
// UR: jab_tak(condition) {} ko ham tab use karsakte hein jab hame koi condition sahi rehne tak cheez repeat
// UR: karwaani ho.
// num_rakho k = 0;
// jab_tak(k < 5) {
// dikhao(k);
// agli_line;
// }
// The issue with this program is that k never becomes more than 5. This means that the loop never stops.
// UR: iss program me masla yeh hai ke 'k' kabhi 5 se bara hi nahi hota. issi liye ye hamesha keliye chalta rahega.
// There is an easy way to fix this.
// UR: iss ko theek karne ka asaan tareeqa hai.
num_rakho k = 0;
jab_tak (k < 5) {
dikhao(k);
agli_line;
// This line will increment k by 1 every iteration.
// UR: Iss line se har baar 'k' mein 1 add hojayega.
// UR: Issi liye 'k' 1, 2, 3, 4 ... ke sequence me barhta jayega.
k = k + 1;
}
// We can do cool things with jab_tak(condition) {}.
// UR: Ham jab_tak(condition) {} ke saath kaafi achi cheezen karsakte hein.
// In this example, we will print even numbers less than 10.
// UR: iss example mein ham 10 se kam even numbers dikhayenge.
num_rakho evenNumber = 0;
jab_tak(evenNumber < 10) {
dikhao(evenNumber);
agli_line;
// We increment by 2 because even numbers are spaced by 2.
// UR: ham har baar 2 add karenge kiunke even numbers 2 ke faasle par hote hein.
// 0, 2, 4, 6, 8
evenNumber = evenNumber + 2;
}
// This is an alternate form of jab_tak(conditon).
// In this form, the task executes at least once.
// UR: Ye jab_tak(condition) ki mukhtalif form hai.
// UR: iss block me code kam se kam bhi aik dafa
// UR: zaroor execute hota hai.
// In this example, the program will print "hi"
// at least once even if we can see that hiCount
// is never less than 0.
// UR: iss example mein, hiCount hamesha hi 0 se
// UR: bara hai lekin phir bhi loop aik dafa chalega.
num_rakho hiCount = 1;
karo {
dikhao("hi");
agli_line;
hiCount = hiCount + 1;
} jab_tak(hiCount < 0);
// tordo is used when we want to immediately get out
// of a repetition.
// jari_rakho does something different. It takes the control
// back to the start of the repetition rather than
// executing the next line.
// UR: tordo tab use hota hai jab hame repetition mein se
// UR: foran baahir nikalna ho.
// UR: jari_rakho tab use hota hai jab hamein aage waali
// UR: lines execute kiye baghair repetition ke shuroo mein
// UR: jaana ho.
// This example highlights the use of tordo and jari_rakho
// keywords.
// UR: Iss example mein ham tordo aur jari_rakho keywords
// UR: ka use dekhenge.
num_rakho n = 5;
repeat(100) {
// Even when the loop is set to run 100 times.
// It will exit after 1 repetition.
// Moreover, the "loop chal raha hai" statement
// will not be executed either.
// UR: halaanke hamne loop ko 100 times
// UR: chalne keliye kaha hai, loop 1
// UR: hi dafa chal kar exit karjayega.
// UR: uss ke ilaawa "loop chal raha hai"
// UR: bhi print nahi hogi kiunke loop pehle
// UR: hi toot gaya.
agar(n == 5) {
dikhao("loop khatam.");
tordo;
}
dikhao("loop chal raha hai.");
}
// Use of jari_rakho keyword.
// UR: jari_rakho keyword ka istemaal.
n = 5;
repeat(100) {
// In this example the control will never reach
// "loop chal raha hai" because as soon as
// the program reaches jari_rakho, it takes
// the control back to the top of the loop.
// Iss example mein jari_rakho keyword
// "loop chal raha hai" waali line run nahi
// honay dega kiunke jab bhi program udhar puhanchega
// woh dubara loop ke start par chala jayega.
agar(n == 5) {
dikhao("loop khatam.");
jari_rakho;
}
dikhao("loop chal raha hai.");
}
khatam
// khatam signifies the end of program.
// UR: khatam ka matlab program ka ikhtetaam.
/*
Note to developers: This is a hobby project of mine and I know there are various things that can be improved.
I would appreciate any feedback on this script. This script and idea are free to use under MIT License.
*/