-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.html
More file actions
220 lines (189 loc) · 6.48 KB
/
examples.html
File metadata and controls
220 lines (189 loc) · 6.48 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Examples - C# MasterClass</title>
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
</head>
<body>
<header>
<div class="logo-container">
<img src="logo.png" alt="C# MasterClass Logo" class="site-logo">
<h1>C# MasterClass</h1>
</div>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="lessons.html">Lessons</a></li>
<li><a href="examples.html" class="active">Examples</a></li>
<li><a href="quiz.html">Quiz</a></li>
</ul>
</nav>
</header>
<main class="container">
<h2>Solved Examples Library</h2>
<p style="margin-bottom: 30px;">A dedicated example for every lesson in the curriculum.</p>
<div class="example-card">
<h3>Ex 1: Printing a Receipt (Output)</h3>
<p><strong>Lesson 1:</strong> Using <code>Console.WriteLine</code> to print formatted text lines.</p>
<div class="code-block">
<pre><code>Console.WriteLine("--- STORE RECEIPT ---");
Console.WriteLine("Item: Gaming Laptop");
Console.WriteLine("Price: $1200");
Console.WriteLine("Tax: $120");
Console.WriteLine("---------------------");
Console.WriteLine("Total: $1320");</code></pre>
</div>
<div class="output-box">
<strong>Output:</strong><br>
--- STORE RECEIPT ---<br>
Item: Gaming Laptop<br>
Price: $1200<br>
Tax: $120<br>
---------------------<br>
Total: $1320
</div>
</div>
<hr>
<div class="example-card">
<h3>Ex 2: User Profile (Input)</h3>
<p><strong>Lesson 2:</strong> Asking the user for their name and year of birth.</p>
<div class="code-block">
<pre><code>Console.Write("Enter your Name: ");
string name = Console.ReadLine();
Console.Write("Enter Birth Year: ");
int year = Convert.ToInt32(Console.ReadLine());
int age = 2025 - year;
Console.WriteLine("Welcome " + name + ", you are " + age + " years old.");</code></pre>
</div>
<div class="output-box">
<strong>Output:</strong><br>
Enter your Name: Mahmoud<br>
Enter Birth Year: 2000<br>
Welcome Mahmoud, you are 25 years old.
</div>
</div>
<hr>
<div class="example-card">
<h3>Ex 3: BMI Calculator (Operators)</h3>
<p><strong>Lesson 3:</strong> Using division and multiplication.</p>
<div class="code-block">
<pre><code>double weight = 70.5;
double height = 1.75;
// Formula: Weight / (Height * Height)
double bmi = weight / (height * height);
Console.WriteLine("Your BMI is: " + bmi);</code></pre>
</div>
<div class="output-box">
<strong>Output:</strong><br>
Your BMI is: 23.020408...
</div>
</div>
<hr>
<div class="example-card">
<h3>Ex 4: Grade Checker (Conditions)</h3>
<p><strong>Lesson 4:</strong> Using <code>if</code> and <code>else if</code>.</p>
<div class="code-block">
<pre><code>int score = 85;
if (score >= 90) {
Console.WriteLine("Grade: A");
}
else if (score >= 75) {
Console.WriteLine("Grade: B");
}
else {
Console.WriteLine("Grade: F");
}</code></pre>
</div>
<div class="output-box">
<strong>Output:</strong><br>
Grade: B
</div>
</div>
<hr>
<div class="example-card">
<h3>Ex 5: Factorial Calculator (Loops)</h3>
<p><strong>Lesson 5:</strong> Using a <code>for</code> loop.</p>
<div class="code-block">
<pre><code>int number = 5;
int result = 1;
for (int i = 1; i <= number; i++)
{
result = result * i;
}
Console.WriteLine("Factorial of 5 is: " + result);</code></pre>
</div>
<div class="output-box">
<strong>Output:</strong><br>
Factorial of 5 is: 120
</div>
</div>
<hr>
<div class="example-card">
<h3>Ex 6: Find Max Number (Arrays)</h3>
<p><strong>Lesson 6:</strong> Looping through an array.</p>
<div class="code-block">
<pre><code>int[] scores = { 10, 50, 95, 40, 20 };
int max = scores[0];
for (int i = 1; i < scores.Length; i++)
{
if (scores[i] > max) max = scores[i];
}
Console.WriteLine("Highest Score is: " + max);</code></pre>
</div>
<div class="output-box">
<strong>Output:</strong><br>
Highest Score is: 95
</div>
</div>
<hr>
<div class="example-card">
<h3>Ex 7: Day of Week (Switch)</h3>
<p><strong>Lesson 7:</strong> Converting a number to a day name.</p>
<div class="code-block">
<pre><code>int dayCode = 3;
switch (dayCode)
{
case 1: Console.WriteLine("Saturday"); break;
case 2: Console.WriteLine("Sunday"); break;
case 3: Console.WriteLine("Monday"); break;
default: Console.WriteLine("Weekend"); break;
}</code></pre>
</div>
<div class="output-box">
<strong>Output:</strong><br>
Monday
</div>
</div>
<hr>
<div class="example-card">
<h3>Ex 8: Tax Calculator (Methods)</h3>
<p><strong>Lesson 8:</strong> Creating a reusable method.</p>
<div class="code-block">
<pre><code>class Program
{
static double CalculateTax(double price)
{
return price * 0.10;
}
static void Main(string[] args)
{
double tax = CalculateTax(1000.0);
Console.WriteLine("Tax Amount: $" + tax);
}
}</code></pre>
</div>
<div class="output-box">
<strong>Output:</strong><br>
Tax Amount: $100
</div>
</div>
</main>
<footer>
<p>© 2025 C# MasterClass Project - AOU. All Rights Reserved.</p>
</footer>
<script src="script.js"></script>
</body>
</html>