Department: CS
Submitted To:Mam.Isra
Full Name: Sufyan Liaqat
Reg No.: UW-21-CS-BS-002 Section: “5thA”
Subject:Advance Programing Date of Submission: 19/12/2023
Q1:-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp11
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string inputString = textBox1.Text;
if (!string.IsNullOrEmpty(inputString))
{
string reversedString = ReverseString(inputString);
textBox1.Text = reversedString;
}
else
{
MessageBox.Show("Please enter a non-empty string.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show("An error occurred: " + ex.Message);
}
}
private string ReverseString(string input)
{
char[] charArray = input.ToCharArray();
Array.Reverse(charArray);
return new string(charArray);
}
}
}
OutPut:-
Q2:-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp11
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
int n = int.Parse(textBox1.Text);
DisplayFibonacciSequence(n);
}
catch (FormatException)
{
MessageBox.Show("Please enter a valid number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception ex)
{
MessageBox.Show("An error occurred: "+ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void DisplayFibonacciSequence(int n)
{
if (n < 0)
{
MessageBox.Show("Please enter a non-negative number.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
textBox1.Text = "The Fibonacci series of " + n + " number is:";
for (int i = 0; i < n; i++)
{
textBox1.Text += " " + Fibonacci(i);
}
}
private int Fibonacci(int number)
{
if (number <= 1)
{
return number;
}
else
{
return Fibonacci(number - 1) + Fibonacci(number - 2);
}
}
}
}
OutPut:-
Q3:-
using System;
using System.Windows.Forms;
namespace WindowsFormsApp13
{
public class SummerCourse
{
public int CourseID { get; set; }
public string CourseName { get; set; }
public string Instructor { get; set; }
public DateTime StartDate { get; set; }
public int DurationInWeeks { get; set; }
public SummerCourse(int courseID, string courseName, string instructor, DateTime startDate, int durationInWeeks)
{
CourseID = courseID;
CourseName = courseName;
Instructor = instructor;
StartDate = startDate;
DurationInWeeks = durationInWeeks;
}
public void SetData(int courseID, string courseName, string instructor, DateTime startDate, int durationInWeeks)
{
CourseID = courseID;
CourseName = courseName;
Instructor = instructor;
StartDate = startDate;
DurationInWeeks = durationInWeeks;
}
public string GetData()
{
return $"Course ID: {CourseID}\n" +
$"Course Name: {CourseName}\n" +
$"Instructor: {Instructor}\n" +
$"Start Date: {StartDate.ToShortDateString()}\n" +
$"Duration (weeks): {DurationInWeeks}";
}
}
public partial class Form1 : Form
{
private SummerCourse mySummerCourse;
public Form1()
{
InitializeComponent();
mySummerCourse = new SummerCourse(002, "Advance Programing", "Sufyan", DateTime.Now, 8);
}
private void button1_Click(object sender, EventArgs e)
{
try
{
MessageBox.Show(mySummerCourse.GetData(), "Course Data", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred: {ex.Message}", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}
Q4:-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp14
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string enteredEmailOrPhone = textBox1.Text;
string enteredPassword = textBox2.Text;
bool isAuthenticated = Login.CheckCredentials(enteredEmailOrPhone, enteredPassword);
if (isAuthenticated)
{
MessageBox.Show("Login successful!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Invalid credentials. Please check your email/phone and password.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred: {ex.Message}", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
public class Login
{
private const string CorrectEmailOrPhone = "user@example.com";
private const string CorrectPassword = "password123";
public static bool CheckCredentials(string emailOrPhone, string password)
{
return emailOrPhone == CorrectEmailOrPhone && password == CorrectPassword;
}
}
}