POLIMORPHISM AND ABSTRACTION DEMONSTRATION
using System;
using [Link];
// Abstract base class
abstract class Student
{
public string Name { get; set; }
public Student(string name)
{
Name = name;
}
// Abstract method
public abstract string CalculateGrade();
}
// Undergraduate student class
class UndergraduateStudent : Student
{
private double Score;
public UndergraduateStudent(string name, double score)
: base(name)
{
Score = score;
}
public override string CalculateGrade()
{
if (Score >= 90) return "A";
if (Score >= 80) return "B";
if (Score >= 70) return "C";
if (Score >= 60) return "D";
return "F";
}
}
// Graduate student class
class GraduateStudent : Student
{
private double Score;
public GraduateStudent(string name, double score)
: base(name)
{
Score = score;
}
public override string CalculateGrade()
{
if (Score >= 85) return "A";
if (Score >= 75) return "B";
if (Score >= 65) return "C";
return "F";
}
}
class Program
{
static void Main()
{
List<Student> students = new List<Student>()
{
new UndergraduateStudent("Alice", 82.5),
new UndergraduateStudent("Bob", 67.0),
new GraduateStudent("Charlie", 88.0),
new GraduateStudent("Diana", 72.0)
};
foreach (Student student in students)
{
[Link]("Student: " + [Link]);
[Link]("Grade: " + [Link]());
[Link]("-----------------------");
}
[Link]();
}
}
OUTPUT:
SWITCH STATEMENT DEMONSTRATION PROJECT
using System;
class Program
{
static void Main()
{
[Link]("Enter a number (1 to 7): ");
int day = Convert.ToInt32([Link]());
switch (day)
{
case 1:
[Link]("Sunday");
break;
case 2:
[Link]("Monday");
break;
case 3:
[Link]("Tuesday");
break;
case 4:
[Link]("Wednesday");
break;
case 5:
[Link]("Thursday");
break;
case 6:
[Link]("Friday");
break;
case 7:
[Link]("Saturday");
break;
default:
[Link]("Invalid input! Please enter a number between 1
and 7.");
break;
}
}
}
OUTPUT :
MAIN WINDOW FORM USING WINDOWS CLASS
using System;
using [Link];
namespace WindowsFormsApp
{
public class MainWindow : Form
{
private Button btnClickMe;
public MainWindow()
{
[Link] = "Main Window";
[Link] = new [Link](400, 300);
[Link] = [Link];
btnClickMe = new Button();
[Link] = "Click Me";
[Link] = new [Link](100, 40);
[Link] = new [Link](150, 120);
[Link] += BtnClickMe_Click;
[Link](btnClickMe);
}
private void BtnClickMe_Click(object sender, EventArgs e)
{
[Link]("Hello ,welcome to the main window!", "Message",
[Link], [Link]);
}
[STAThread]
static void Main()
{
[Link]();
[Link](false);
[Link](new MainWindow());
}
}
}
Output:
PURCHASING ORDER APPLICATION
using System;
using [Link];
namespace PurchaseOrderApp
{
class Program
{
static void Main(string[] args)
{
var orders = new List<string>();
bool exit = false;
while (!exit)
{
[Link]("\nSelect an option:");
[Link]("1. Create a new order");
[Link]("2. View all orders");
[Link]("3. Exit");
[Link]("Your choice: ");
var choice = [Link]();
switch (choice)
{
case "1":
// Create a new order
[Link]("Enter Product Name: ");
string productName = [Link]();
[Link]("Enter Quantity: ");
int quantity = [Link]([Link]());
[Link]("Enter Unit Price: ");
decimal unitPrice = [Link]([Link]());
decimal totalPrice = quantity * unitPrice;
// Corrected the string to use interpolation
string order = "Product: " + productName + ", Quantity: " +
quantity + ", Total Price: " + totalPrice;
[Link](order);
[Link]("Order added successfully!");
break;
case "2":
// View all orders
[Link]("\nAll Orders:");
if ([Link] > 0)
{
foreach (var orderDetails in orders)
{
[Link](orderDetails);
}
}
else
{
[Link]("No orders available.");
}
break;
case "3":
// Exit
exit = true;
break;
default:
[Link]("Invalid option, please try again.");
break;
}
}
}
}
}
OUTPUT:
LOGIN FORM APPLICATION
using System;
class Program
{
static void Main(string[] args)
{
[Link]("=== Simple Login ===");
[Link]("Enter username: ");
string username = [Link]();
[Link]("Enter password: ");
string password = [Link]();
if (username == "admin" && password == "1234")
{
[Link]("Login successful!");
}
else
{
[Link]("Invalid username or password.");
}
[Link]();
}
}
OUTPUT:
APPLICATION USING TREEVIEW CONTROL
using System;
using [Link];
namespace ConsoleTreeViewApp
{
class Program
{
// Define a simple TreeNode class for console
class TreeNode
{
public string Text { get; set; }
public List<TreeNode> Children { get; set; }
public TreeNode(string text)
{
Text = text;
Children = new List<TreeNode>();
}
}
static void Main(string[] args)
{
// Build tree structure
TreeNode root = new TreeNode("Animals");
TreeNode mammals = new TreeNode("Mammals");
[Link](new TreeNode("Dog"));
[Link](new TreeNode("Cat"));
[Link](new TreeNode("Elephant"));
TreeNode birds = new TreeNode("Birds");
[Link](new TreeNode("Eagle"));
[Link](new TreeNode("Parrot"));
[Link](new TreeNode("Penguin"));
[Link](mammals);
[Link](birds);
// Print the tree to console
PrintTree(root, "");
[Link]("\nPress any key to exit...");
[Link]();
}
// Recursive method to print tree with indentation
static void PrintTree(TreeNode node, string indent)
{
[Link](indent + [Link]);
foreach (var child in [Link])
{
PrintTree(child, indent + " "); // Increase indent for children
}
}
}
}
OUTPUT:
APPLICATION USING FONT DIALOG CONTROL
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if ([Link]() == [Link])
{
[Link] = [Link];
}
}
}
}
OUTPUT:
APPLICATION USING COLOR DIALOG CONTROL
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (ColorDialog colorDialog = new ColorDialog())
{
[Link] = true; // Allow picking any color
[Link] = true; // Show help button
[Link] = [Link]; // Start with label’s
current color
if ([Link]() == [Link])
{
[Link] = [Link]; // Set label background
to chosen color
}
}
}
}
}
OUTPUT :
WEB BROWSER CONTROL TO DISPLAY SELECTED FILE
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (OpenFileDialog dlg = new OpenFileDialog())
{
[Link] = "Select a file to display";
[Link] = "All files (*.*)|*.*";
if ([Link]() == [Link])
{
string filePath = [Link];
// Display the file in the WebBrowser control
[Link](filePath);
}
}
}
}
}
OUTPUT:
TREE VIEW STRUCTURE FOR DISPLAYING INPUTS
using System;
using [Link];
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
TextBox parentTextBox;
Button addParentButton;
TextBox childTextBox;
Button addChildButton;
TreeView treeView;
public Form1()
{
InitializeComponent();
[Link] = "Parent-Child TreeView";
[Link] = new [Link](400, 400);
parentTextBox = new TextBox() { Left = 10, Top = 10, Width = 200 };
addParentButton = new Button() { Left = 220, Top = 8, Text = "Add
Parent" };
[Link] += AddParentButton_Click;
childTextBox = new TextBox() { Left = 10, Top = 40, Width = 200 };
addChildButton = new Button() { Left = 220, Top = 38, Text = "Add
Child" };
[Link] += AddChildButton_Click;
treeView = new TreeView() { Left = 10, Top = 70, Width = 350, Height
= 300 };
[Link](parentTextBox);
[Link](addParentButton);
[Link](childTextBox);
[Link](addChildButton);
[Link](treeView);
[Link] += Form1_Load;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void AddParentButton_Click(object sender, EventArgs e)
{
string parentText = [Link]();
if ()
{
if ([Link](parentText))
{
[Link]("Parent node already exists.");
return;
}
TreeNode parentNode = new TreeNode(parentText) { Name =
parentText };
[Link](parentNode);
[Link]();
}
else
{
[Link]("Please enter a parent node name.");
}
}
private void AddChildButton_Click(object sender, EventArgs e)
{
string childText = [Link]();
if ([Link] == null)
{
[Link]("Please select a parent node to add a child.");
return;
}
if ([Link](childText))
{
[Link]("Please enter a child node name.");
return;
}
TreeNode parentNode = [Link];
foreach (TreeNode child in [Link])
{
if ([Link] == childText)
{
[Link]("Child node already exists under this parent.");
return;
}
}
[Link](childText);
[Link]();
[Link]();
}
}
}
OUTPUT:
EXCEPTION HANDLING IMPLEMENTATION IN C#
using System;
namespace ExceptionHandlingDemo
{
class Program
{
static void Main(string[] args)
{
try
{
[Link]("Enter the numerator (integer):");
int numerator = Convert.ToInt32([Link]());
[Link]("Enter the denominator (integer):");
int denominator = Convert.ToInt32([Link]());
int result = DivideNumbers(numerator, denominator);
[Link]("Result of " + numerator + " / " + denominator + "
= " + result);
}
catch (FormatException)
{
[Link]("Error: Please enter valid integers only.");
}
catch (DivideByZeroException)
{
[Link]("Error: Cannot divide by zero.");
}
finally
{
[Link]("Thank you for using the division app.");
}
[Link]("Press any key to exit...");
[Link]();
}
static int DivideNumbers(int num1, int num2)
{
return num1 / num2;
}
}
}
OUTPUT:
COFFEE SHOP BILLING SYSTEM
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string name;
int price;
int tot;
private void Form1_Load(object sender, EventArgs e)
{
private void groupBox1_Enter(object sender, EventArgs e)
{
[Link]();
if([Link])
{
name="Coffee";
int qty=[Link]([Link]());
price=20;
tot=qty*price;
[Link](name,price,qty,tot);
}
if([Link])
{
name="tea";
int qty=[Link]([Link]());
price=15;
tot=qty*price;
[Link](name,price,qty,tot);
}
[Link]();
int sum = 0;
for (int row = 0; row < [Link]; row++)
{
sum = sum +
Convert.ToInt32([Link][row].Cells[3].Value);
}
[Link] = [Link]();
}
private void label2_Click(object sender, EventArgs e)
{
}
}
}
OUTPUT:
BULLETED LIST CONTROL APPLICATION
using System;
using [Link];
class Program
{
static void Main()
{
List<string> items = new List<string>();
while (true)
{
[Link]();
[Link]("Simple Bulleted List App");
[Link]("------------------------");
if ([Link] == 0)
[Link]("(No items yet)");
else
foreach (var item in items)
[Link]("• " + item);
[Link]("\nOptions:");
[Link]("1 - Add item");
[Link]("2 - Exit");
[Link]("Choose an option: ");
string input = [Link]();
if (input == "1")
{
[Link]("Enter item to add: ");
string newItem = [Link]();
if ()
[Link]([Link]());
}
else if (input == "2")
{
break;
}
}
}
}
OUTPUT:
CALENDAR CONTROL FOR SINGLE DAY SELECTION
using System;
using [Link];
namespace singledayselectorapp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Limit calendar selection to a single day
[Link] = 1;
// Set initial label text
[Link] = "Select a date";
// Attach event handler for date changes
[Link] += MonthCalendar1_DateChanged;
}
private void MonthCalendar1_DateChanged(object sender,
DateRangeEventArgs e)
{
// Update the label with the selected date
[Link] = "Selected Date: " + [Link]();
}
private void Form1_Load(object sender, EventArgs e)
{
private void monthCalendar_Click(object sender, EventArgs e)
{
private void monthCalendar1_DateChanged_1(object sender,
DateRangeEventArgs e)
{
}
}
}
OUTPUT:
SCROLL BAR FEATURE WITH PANEL CONTROL
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
for (int i = 0; i < 10; i++)
{
Button btn = new Button()
{
Text = "Button " + (i + 1),
Location = new Point(10, i * 30),
Size = new Size(100, 25)
};
[Link](btn);
}
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
}
}
OUTPUT: