Professional Documents
Culture Documents
(20-Arid-811) (Mustajab Ahmed) (Assignment-02)
(20-Arid-811) (Mustajab Ahmed) (Assignment-02)
class Program
{
static void Main()
{
List<string> patientNames = new List<string>();
Console.WriteLine("Enter ten patient names:");
for (int i = 1; i <= 10; i++)
{
Console.Write($"Enter Patient Name {i}: ");
string name = Console.ReadLine();
patientNames.Add(name);
}
patientNames.Sort();
Console.WriteLine("\nPatient Names:");
for (int i = 0; i < patientNames.Count; i++)
{
Console.WriteLine($"Input: {i + 1} - {patientNames[i]}");
}
}
}
ScreenShot:
Question 02:
Code:
using System;
using System.Windows.Forms;
namespace WinFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
long result = 1;
for (int i = 1; i <= n; i++)
{
result *= i;
}
return result;
}
}
}
Screen Shot:
Question 03:
Write the code for the following design form, design this form in your Visual Studio and then
write complete code using C# programming language.
Code:
using System;
using System.Windows.Forms;
namespace WinFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
private void btnCalculate_Click(object sender, EventArgs e)
{
if (double.TryParse(textBox1.Text, out double num1) &&
double.TryParse(textBox2.Text, out double num2))
{
double sum = num1 + num2;
resultLabel.Text = $"Sum: {sum}";
}
else
{
resultLabel.Text = "Please enter valid numbers in both fields.";
}
}
}
}
ScreeenShot:
Question: 04
Code:
using System;
using System.Windows.Forms;
namespace WinFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
ScreenShot:
Question:05
Code:
using System;
using System.Windows.Forms;
namespace WinFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
sexComboBox.Items.Add("Male");
sexComboBox.Items.Add("Female");
}
ScreeenShot:
Question: 06
Code:
using System;
using System.Windows.Forms;
namespace WinFormsApp4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
if (months < 0)
{
years--;
months += 12;
}
Question No. 7 Design the following form using numericUpDown Control, button,
lable
Define the Maximum and Minimum Limit of the two numericupdown controls and
then display the time in AM/PM format, as an example is shown in above figure
Source Code:
namespace Question7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
minutes = Convert.ToInt16(numMin.Value);
seconds = Convert.ToInt16(numSec.Value);
// show time
if (minutes < 10 && seconds < 10)
{
// add 0 before minutes and seconds in time
MessageBox.Show("0" + minutes + ":" + "0" + seconds + " " + format);
}
else if (minutes < 10)
{
// add 0 before minutes in time
MessageBox.Show("0" + minutes + ":" + seconds + " " + format);
}
else if (seconds < 10)
{
// add 0 before seconds in time
MessageBox.Show(minutes + ":" + "0" + seconds + " " + format);
}
else
{
MessageBox.Show(minutes + ":" + seconds + " " + format);
}
}
}
}
Output:
Question No. 8 Design the following form using MaskText Control, button, lable
When you press the OK button, then the entered IP address will be shown in
MessageBox
Source Code:
namespace Question8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Output:
Source Code:
namespace Question9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// message box
MessageBox.Show("Your favourite movie: " + favouriteMovie);
}
}
}
Output: