-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
481 lines (425 loc) · 17.6 KB
/
Program.cs
File metadata and controls
481 lines (425 loc) · 17.6 KB
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
//namespace CSPractices
//{
// class Program
// {
// static void Main(string[] args)
// {
// }
// }
//}
//// 19. ABC Taxi Company has the following meter charges based on the kilometres travelled.
//// Minimum charge: $2.40 (first 0.5 km no additional charges apply)
//// For the next 8.5 kms the rate is 4 cents for every 100 meters
//// After that: 5 cents for evey 100 meters
//// In the above example you should assume that the meter falls every 100 meters.So assume that
//// if the distance travelled (i.e.input) is 12.13 km then it is rounded to 12.20 and the cost would be:
//// $ 2.40 (first 0.5 km) +
//// $ 85 * 0.04 (next 8.5 km) +
//// $ (122 -90) * 0.05 (for distance over 9.0 km)
//// = $7.40
//namespace CSPractices
//{
// class Program
// {
// static void Main(string[] args)
// {
// Console.Write("Enter the distance of the journey in km: ");
// double distance = Convert.ToDouble(Console.ReadLine());
// double distance1 = (Math.Ceiling(distance * 10)) / 10;
// Console.WriteLine();
// Console.WriteLine("You travelled {0} km.", distance1);
// Console.WriteLine();
// double price1, price2, price3, price4;
// Console.WriteLine("\tTaxi Fare");
// Console.WriteLine("-----------------------------");
// if (0 < distance1 && distance1 <= 0.5 )
// {
// price1 = 2.4;
// Console.WriteLine("\tFirst 0.5 km = {0:c}", price1);
// Console.WriteLine("-----------------------------");
// Console.WriteLine("\tTOTAL = {0:c}", price1);
// }
// if (0.5 < distance1 && distance1 <= 9)
// {
// price1 = 2.4;
// price2 = (distance1 - 0.5)*10*0.04;
// Console.WriteLine("\tFirst 0.5 km = {0:c}", price1);
// Console.WriteLine("\tSecond leg (0.6 to 8.5 km) = {0:c}", price2);
// Console.WriteLine("-----------------------------");
// price4 = price1 + price2;
// Console.WriteLine("\tTOTAL = {0:c}", price4);
// }
// if (9 < distance1)
// {
// price1 = 2.4;
// price2 = 8.5 * 10 * 0.04;
// price3 = (distance1 - 9) * 10 * 0.05;
// Console.WriteLine("\tFirst 0.5 km = {0:c}", price1);
// Console.WriteLine("\tSecond leg (0.6 to 85 km) = {0:c}", price2);
// Console.WriteLine("\tThird leg (>85 km) = {0:c}", price3);
// Console.WriteLine("-----------------------------");
// price4 = price1 + price2 + price3;
// Console.WriteLine("\tTOTAL = {0:c}", price4);
// }
// }
// }
//}
//// 18. Write a program that would compute the grade for a mark that the student gets.
//// The program should take an integer number between 0 and 100 and print the following:
//// You scored 73 marks which is B grade.where 73 is the input and B is calculated by the program.
//// Use the following table for computing the grades:
//namespace CSPractices
//{
// class Program
// {
// static void Main(string[] args)
// {
// Console.Write("Please enter your grade: ");
// double GRADE = Convert.ToDouble(Console.ReadLine());
// if (GRADE < 0 || GRADE > 100)
// {
// Console.WriteLine("**Error**");
// }
// else
// {
// if (GRADE > 0 && GRADE < 39)
// {
// Console.WriteLine("You scored {0} marks which is an F grade.", GRADE);
// }
// else if (GRADE > 40 && GRADE < 59)
// {
// Console.WriteLine("You scored {0} marks which is a C grade.", GRADE);
// }
// else if (GRADE > 60 && GRADE < 79)
// {
// Console.WriteLine("You scored {0} marks which is a B grade.", GRADE);
// }
// else
// {
// Console.WriteLine("You scored {0} marks which is an A grade.", GRADE);
// }
// }
// }
// }
//}
//// 17. Write a program that would request for your name, gender and age and would print a greeting like
//// this: Good morning Uncle Sam ( if Sam, M, 45 is entered)
//// (any gentlemen 40 years or more is Uncle any lady 40 years or more is Aunty,
//// if less than forty they become just Mr or Ms. as the case may be.)
//namespace CSPractices
//{
// class Program
// {
// static void Main(string[] args)
// {
// Console.Write("Please enter your name: ");
// string NAME = Console.ReadLine();
// Console.Write("Please enter your gender (M/F): ");
// string GENDER = (Console.ReadLine()).ToLower();
// Console.Write("Please enter your age: ");
// int AGE = Convert.ToInt32(Console.ReadLine());
// if(GENDER == "m")
// {
// if(AGE >=40)
// {
// Console.WriteLine("Hi, Uncle {0}.", NAME);
// }
// else
// {
// Console.WriteLine("Hi, Mr. {0}.", NAME);
// }
// }
// else
// {
// if (AGE >= 40)
// {
// Console.WriteLine("Hi, Auntie {0}.", NAME);
// }
// else
// {
// Console.WriteLine("Hi, Ms. {0}.", NAME);
// }
// }
// }
// }
//}
//// 16. Write a program that would request for your name and gender (M or F assume capital letter) and
//// print a greeting like this: Good Morning Mr. Venkat where you entered Venkat for name and M for gender.
//namespace CSPractices
//{
// class Program
// {
// static void Main(string[] args)
// {
// //Console.Write("Please enter your name and gender, separated by a \",\" : ");
// //string full = Console.ReadLine();
// //string[] parts = full.Split(',');
// //string first = parts[0];
// //string last = parts[1];
// //Console.WriteLine("Hi, {0}!", first);
// //Console.WriteLine("You're a {0}.", last);
// Console.Write("Please enter your name: ");
// string NAME = Console.ReadLine();
// Console.Write("Please enter your gender (M/F): ");
// string GENDER = (Console.ReadLine()).ToLower();
// if (GENDER == "m")
// {
// Console.WriteLine($"Good Morning, Mr. {NAME}!");
// }
// else
// {
// Console.WriteLine($"Good Morning, Ms. {NAME}!");
// }
// }
// }
//}
//// 15. Given a three-digit integer as input write a C# program to determine whether the number is an Armstrong number.
//// An Armstrong number is one for which the sum of each digit raised to the power of number of digits results
//// in the number itself.
//// For a three digit number 153 = 13 + 53 + 33
//// None confine to 3 digit examples only ie., number values 100…999.
//// Minor comment change
//namespace CSPractices
//{
// class Program
// {
// static void Main(string[] args)
// {
// bool tryagain = true;
// while (tryagain)
// {
// Console.Write("Please enter a three-digit integer: ");
// string input;
// while (true)
// {
// input = Console.ReadLine();
// if (Int32.TryParse(input, out int A) && Regex.IsMatch(input, @"^[0-9]{3}$"))
// {
// break;
// }
// else
// {
// Console.Write("Please just enter a three-digit integer: ");
// }
// }
// Console.WriteLine();
// int B = Convert.ToInt32(input);
// Console.WriteLine($"You've entered {B}.");
// // 3-digit integer XYZ has Z as first digit (position or power 0),
// // Y as second digit (position or power 1)
// // and X as third digit (position or power 2)
// int firstdigit = (int)((B / Math.Pow(10, 0)) % 10);
// int seconddigit = (int)((B / Math.Pow(10, 1)) % 10);
// int thirddigit = (int)((B / Math.Pow(10, 2)) % 10);
// Console.WriteLine($"In the ONES place is {firstdigit}.");
// Console.WriteLine($"In the TENS place is {seconddigit}.");
// Console.WriteLine($"In the HUNDREDS place is {thirddigit}.");
// Console.WriteLine();
// Console.Write("Is {0} an Armstrong number?", B);
// Console.WriteLine(" i.e. Is {0} = {1}^3 + {2}^3 + {3}^3 ?", B, thirddigit, seconddigit, firstdigit);
// Console.WriteLine();
// double third = Math.Pow((double)thirddigit, 3);
// double second = Math.Pow((double)seconddigit, 3);
// double first = Math.Pow((double)firstdigit, 3);
// double sum = first + second + third;
// Console.WriteLine("\t{0}^3 = {1}", thirddigit, third);
// Console.WriteLine("\t{0}^3 = {1}", seconddigit, second);
// Console.WriteLine("\t{0}^3 = {1}", firstdigit, first);
// Console.WriteLine("-----------------------");
// Console.WriteLine("\tSUM = {0}", sum);
// Console.WriteLine();
// if ((int)sum == B)
// {
// Console.WriteLine("{0} is an Armstrong number!", B);
// Console.WriteLine();
// Console.Write("Play again? Y/N ");
// string answer = Console.ReadLine();
// if (answer.ToLower() == "y")
// {
// tryagain = true;
// }
// else
// {
// Console.WriteLine();
// Console.WriteLine("Thanks for playing, goodbye!\n");
// tryagain = false;
// }
// }
// else
// {
// Console.WriteLine("Sorry, {0} is not an Armstrong number.", B);
// Console.WriteLine();
// Console.Write("Try again? y/n ");
// string answer = Console.ReadLine();
// if (answer.ToLower() == "y")
// {
// tryagain = true;
// }
// else
// {
// Console.WriteLine();
// Console.WriteLine("Thanks for playing, goodbye!");
// tryagain = false;
// }
// }
// }
// }
// }
//}
//// 14. Consider the simple Geometric example of determining the area of a triangle,
//// given the lengths of its three sides a, b and c.
//// Use the formula: AREA = SQUAREROOT[s(s - a)(s - b)(s - c)] where s = (a+b+c) / 2
//// Does your program always work? If not alter it to consider situations fro which it fails.
//namespace CSPractices
//{
// class Program
// {
// static void Main(string[] args)
// {
// bool again = true;
// while(again)
// {
// Console.Write("Enter value of a: ");
// double a = Convert.ToDouble(Console.ReadLine());
// Console.Write("Enter value of b: ");
// double b = Convert.ToDouble(Console.ReadLine());
// Console.Write("Enter value of c: ");
// double c = Convert.ToDouble(Console.ReadLine());
// double s = (a + b + c) / 2;
// double s1 = s - a;
// double s2 = s - b;
// double s3 = s - c;
// double s4 = s * s1 * s2 * s3;
// double Area = Math.Round(Math.Sqrt(s4), 2);
// Console.WriteLine($"Area = {Area}");
// Console.WriteLine("");
// //if(double.IsNaN(Area))
// //{
// // Console.WriteLine("Not a number! Try again!");
// // again = true;
// //}
// Console.WriteLine("Try again? y/n ");
// string reply = Console.ReadLine();
// reply.ToLower();
// if(reply == "y")
// {
// again = true;
// }
// else
// {
// Console.WriteLine("Thanks for playing.");
// again = false;
// }
// }
// }
// }
//}
//// 11. ABC Taxi Company has the following meter charges based on the kilometres travelled.
//// Minimum fixed charge: $2.40
//// In addition the fare would be computed at 40 cents per kilometer.
//// E.g.If the distance traveled is 3.24 km then the total fare is 2.40 + 3.24 * 0.4
//// 12. In the ABC Taxi Company example above, print the output so that the fare is
//// the output is printed always rounded to nearest 10 cents and printed to two decimal places.
//// 13. In the above problem, if you have always to round upwards – how would you do that?
//namespace CSPractices
//{
// class Program
// {
// static void Main(string[] args)
// {
// Console.Write("Please enter distance travelled: ");
// decimal x = Convert.ToDecimal(Console.ReadLine());
// decimal fare = (decimal)2.4 + x * (decimal)0.4;
// decimal fare1 = Math.Round(fare, 2);
// Console.WriteLine("Your taxi fare for this journey: {0:c2}", fare1);
// decimal fare2 = (Math.Ceiling(fare * 10) / 10);
// Console.WriteLine("Your taxi fare for this journey: {0:c2}", fare2);
// }
// }
//}
//// 10. Write a program that reads the (x,y) coordinates of two points.
//// Compute the distance between the two points using the formula:
//// Distance = Square Root of[(x2 – x1 ) 2 + (y2 – y1 ) 2]
//namespace CSPractices
//{
// class Program
// {
// static void Main(string[] args)
// {
// Console.Write("Enter x coordinate of point 1: ");
// double x1 = Convert.ToDouble(Console.ReadLine());
// Console.Write("Enter y coordinate of point 1: ");
// double y1 = Convert.ToDouble(Console.ReadLine());
// Console.Write("Enter x coordinate of point 2: ");
// double x2 = Convert.ToDouble(Console.ReadLine());
// Console.Write("Enter y coordinate of point 2: ");
// double y2 = Convert.ToDouble(Console.ReadLine());
// double z = Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
// decimal z1 = Convert.ToDecimal(z);
// z1 = Math.Round(z1, 3);
// Console.WriteLine($"The distance between ({x1}, {y1}) and ({x2}, {y2}) is {z1}.");
// }
// }
//}
//// 7. The ABC Company pays its employees salary plus benefits.
//// The benefits are calculated as a percentage of the salary.
//// The company pays every employee 10% housing allowance and 3% transport allowance.
//// Write a program that takes the salary as input and prints the total income
//// (salary + housing allowance + transport allowance) as output. Format the output in currency format.
//namespace CSPractices
//{
// class Program
// {
// static void Main(string[] args)
// {
// Console.Write("Please enter your salary: ");
// double sal = Convert.ToDouble(Console.ReadLine());
// Console.WriteLine();
// Console.WriteLine("Salary Breakdown");
// Console.WriteLine("------------------------------------------------");
// Console.WriteLine("\tSalary: \t\t {0:c}", sal);
// Console.WriteLine("\tHousing Allowance: \t {0:c}", sal * 0.1);
// Console.WriteLine("\tTransport Allowance: \t {0:c}", sal * 0.03);
// }
// }
//}
// 5. Write a program that takes a double precision number as input and prints the square root of the number.
// The square root should be rounded to 3 decimal places.
//namespace CSPractices
//{
// class Program
// {
// public static void ReadDouble()
// {
// Console.Write("Please enter an integer: ");
// string tested;
// while (true)
// {
// tested = Console.ReadLine();
// if (Int32.TryParse(tested, out int A))
// {
// break;
// }
// else
// {
// Console.Write("You must enter an integer. Please try again: ");
// }
// }
// int X = Convert.ToInt32(tested);
// double X1 = Convert.ToDouble(X);
// double Xroot = Math.Sqrt(X1);
// decimal Xroot1 = Convert.ToDecimal(Xroot);
// decimal Xrounded = Math.Round(Xroot1, 3);
// Console.WriteLine($"For {X},");
// Console.WriteLine($"its square root is {Xroot}");
// Console.WriteLine($"which rounded to 3 decimal places, is {Xrounded}.");
// }
// static void Main(string[] args)
// {
// ReadDouble();
// }
// }
//}