-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent
More file actions
243 lines (205 loc) · 7.66 KB
/
Student
File metadata and controls
243 lines (205 loc) · 7.66 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
using System;
using System.Numerics;
using static Chapter06.Program;
namespace Chapter06
{
class Program
{
public class RandomNumbers
{
public static void GenerateAndAnalyze()
{
Random random = new Random();
int oddCount = 0, minValue = int.MaxValue, maxValue = int.MinValue;
for (int i = 0; i < 1000; i++)
{
int randomNumber = random.Next(0, 100001);
if (randomNumber % 2 != 0)
oddCount++;
if (randomNumber < minValue)
minValue = randomNumber;
if (randomNumber > maxValue)
maxValue = randomNumber;
}
Console.WriteLine($"Number of odd values: {oddCount}");
Console.WriteLine($"Smallest value: {minValue}");
Console.WriteLine($"Largest value: {maxValue}");
}
}
public class InputValidator
{
public static void ValidateInput()
{
int validCount = 0, invalidCount = 0;
string input;
do
{
Console.Write("Enter a positive integer less than 100 (or type 'done' to finish): ");
input = Console.ReadLine();
if (input.ToLower() == "done")
break;
if (int.TryParse(input, out int number) && number > 0 && number < 100)
validCount++;
else
invalidCount++;
}
while (true);
Console.WriteLine($"Number of valid entries: {validCount}");
Console.WriteLine($"Number of invalid entries: {invalidCount}");
}
}
public class ScoreCalculator
{
public static void CalculateAverageAndGrade()
{
int total = 0, count = 0;
string input;
do
{
Console.Write("Enter a score between 0 and 100 (or type '-1' to finish): ");
input = Console.ReadLine();
if (int.TryParse(input, out int score) && score >= 0 && score <= 100)
{
total += score;
count++;
}
else if (input == "-1")
{
break;
}
else
{
Console.WriteLine("Invalid input, please enter a valid score.");
}
}
while (true);
if (count > 0)
{
double average = (double)total / count;
Console.WriteLine($"Average score: {average:F2}");
string grade = average >= 90 ? "A" :
average >= 80 ? "B" :
average >= 70 ? "C" :
average >= 60 ? "D" : "F";
Console.WriteLine($"Recorded grade: {grade}");
}
else
{
Console.WriteLine("No valid scores were entered.");
}
}
}
public class MultiplicationTable
{
public static void GenerateTable()
{
Console.Write("Enter the starting base (2-8): ");
if (!int.TryParse(Console.ReadLine(), out int startBase) || startBase < 2 || startBase > 8)
{
Console.WriteLine("Invalid starting base value. Please enter a value between 2 and 8.");
return;
}
Console.Write("Enter the ending base (2-8): ");
if (!int.TryParse(Console.ReadLine(), out int endBase) || endBase < 2 || endBase > 8 || endBase < startBase)
{
Console.WriteLine("Invalid ending base value. Please enter a value between 2 and 8, greater than or equal to the starting base.");
return;
}
Console.WriteLine("\nMultiplication Table:");
for (int row = 1; row <= 25; row++)
{
for (int col = startBase; col <= endBase; col++)
{
Console.Write($"{row * col,5} ");
}
Console.WriteLine();
}
}
}
public class JugglerSequence
{
public static void CalculateJugglerSequence()
{
Console.Write("Enter a positive integer between 1 and 50: ");
if (!int.TryParse(Console.ReadLine(), out int number) || number < 1 || number > 50)
{
Console.WriteLine("Invalid input. Please enter a number between 1 and 50.");
return;
}
BigInteger current = number;
BigInteger maxValue = current;
int steps = 0;
Console.WriteLine($"\nJuggler Sequence starting with {number}:");
while (current != 1)
{
Console.Write($"{current} ");
if (current % 2 == 0)
{
current = (BigInteger)Math.Sqrt((double)current);
}
else
{
current = (BigInteger)Math.Pow((double)current, 1.5);
}
if (current > maxValue)
maxValue = current;
steps++;
}
Console.WriteLine("1");
Console.WriteLine($"Maximum value in sequence: {maxValue}");
Console.WriteLine($"Total steps to reach 1: {steps}");
}
}
static void Main(string[] args)
{
Tester.RunAllTests();
}
}
public static class Tester
{
public static void RunAllTests()
{
Console.WriteLine("Running Task 1: Generate 1000 Random Numbers");
RandomNumbers.GenerateAndAnalyze();
Console.WriteLine("\n-------------------------------------------\n");
Console.WriteLine("Running Task 2: Input Validation");
InputValidator.ValidateInput();
Console.WriteLine("\n-------------------------------------------\n");
Console.WriteLine("Running Task 3: Calculate Average and Grade");
ScoreCalculator.CalculateAverageAndGrade();
Console.WriteLine("\n-------------------------------------------\n");
Console.WriteLine("Running Task 4: Multiplication Table");
MultiplicationTable.GenerateTable();
Console.WriteLine("\n-------------------------------------------\n");
Console.WriteLine("Running Task 5: Juggler's Sequence");
JugglerSequence.CalculateJugglerSequence();
Console.WriteLine("\n-------------------------------------------\n");
}
// You could also add methods here to run individual tests
public static void TestRandomNumbers()
{
Console.WriteLine("Testing Task 1: Generate Random Numbers");
RandomNumbers.GenerateAndAnalyze();
}
public static void TestInputValidation()
{
Console.WriteLine("Testing Task 2: Input Validation");
InputValidator.ValidateInput();
}
public static void TestScoreCalculator()
{
Console.WriteLine("Testing Task 3: Calculate Average and Grade");
ScoreCalculator.CalculateAverageAndGrade();
}
public static void TestMultiplicationTable()
{
Console.WriteLine("Testing Task 4: Multiplication Table");
MultiplicationTable.GenerateTable();
}
public static void TestJugglerSequence()
{
Console.WriteLine("Testing Task 5: Juggler's Sequence");
JugglerSequence.CalculateJugglerSequence();
}
}
}