Lab
Lab
switch(ch)
{
} while(ch<3);
}
}
Output:
2. C# program to convert a decimal no to its binary equivalent and vice versa using the
method. The program should illustrate the use of reference variables and output.
using System;
switch (ch)
{
case 1:
Console.WriteLine("Enter a decimal number:");
int n = int.Parse(Console.ReadLine());
int[] a = new int[10];
bin(a, n);
break;
case 2:
Console.WriteLine("Enter a binary number:");
string s = Console.ReadLine();
int[] a1 = dec(s);
break;
case 3:
Console.Write("Exiting");
break;
default:
Console.Write("Invalid choice");
break;
}
Output:
3. Write a C# program to create a shopping list of electronic goods and another of books.
Provide options to add an item at the specified location, to append an item, or to
delete an item. The shopping list has to be merged and sorted alphabetically.
using System;
using System.Collections.Generic;
// Options
int option;
do
{
Console.WriteLine("\nOptions:");
Console.WriteLine("1. Add item to electronic goods list at specified
location");
Console.WriteLine("2. Add item to books list at specified location");
Console.WriteLine("3. Append an item to electronic goods list");
Console.WriteLine("4. Append an item to books list");
Console.WriteLine("5. Delete an item from electronic goods list");
Console.WriteLine("6. Delete an item from books list");
Console.WriteLine("7. Merge and sort lists");
Console.WriteLine("8. Exit");
option = int.Parse(Console.ReadLine());
switch (option)
{
case 1:
Console.WriteLine("Enter electronic item to add:");
string electronicItem = Console.ReadLine();
Console.WriteLine("Enter index where to add:");
int electronicIndex = int.Parse(Console.ReadLine());
AddItemAtLocation(electronicGoods, electronicIndex, electronicItem);
break;
case 2:
Console.WriteLine("Enter book to add:");
string bookItem = Console.ReadLine();
Console.WriteLine("Enter index where to add:");
int bookIndex = int.Parse(Console.ReadLine());
AddItemAtLocation(books, bookIndex, bookItem);
break;
case 3:
Console.WriteLine("Enter electronic item to append:");
string electronicItemToAppend = Console.ReadLine();
AppendItem(electronicGoods, electronicItemToAppend);
break;
case 4:
Console.WriteLine("Enter book to append:");
string bookItemToAppend = Console.ReadLine();
AppendItem(books, bookItemToAppend);
break;
case 5:
Console.WriteLine("Enter electronic item to delete:");
string electronicItemToDelete = Console.ReadLine();
DeleteItem(electronicGoods, electronicItemToDelete);
break;
case 6:
Console.WriteLine("Enter book to delete:");
string bookItemToDelete = Console.ReadLine();
DeleteItem(books, bookItemToDelete);
break;
case 7:
MergeAndSortLists(electronicGoods, books);
break;
case 8:
Console.WriteLine("Exiting...");
break;
default:
Console.WriteLine("Invalid option");
break;
}
using System;
struct Customer
{
public string Name;
public int AccountNumber;
public double Balance;
public string AccountStatus;
}
customers[1].Name = "Alice";
customers[1].AccountNumber = 1002;
customers[1].Balance = 2000;
customers[1].AccountStatus = "Inactive";
customers[2].Name = "Bob";
customers[2].AccountNumber = 1003;
customers[2].Balance = 7000;
customers[2].AccountStatus = "Active";
Console.WriteLine("\nActive Accounts:");
foreach (Customer customer in customers)
{
if (customer.AccountStatus == "Active")
{
DisplayCustomerDetails(customer);
}
}
Console.WriteLine("\nInactive Accounts:");
foreach (Customer customer in customers)
{
if (customer.AccountStatus == "Inactive")
{
DisplayCustomerDetails(customer);
}
}
}
Output:
5. Design an abstract class BankAccount with necessary data members. Derive the
following classes BankAccount->[current, fixed->[short, long], savings]. The savings
class provides with checkbook facility, withdrawal, and deposit facility. The current
class provides only a withdrawal and deposit facility. The fixed class is derived by 2
classes short-term (1-2yr @8%)and long-term (3-5yr @10%). Write a driver program
for this.
using System;
Balance += amount;
Console.WriteLine($"Deposited {amount}. New balance is {Balance}.");
}
public virtual void Withdraw(double amount)
{
if (amount <= 0 || amount > Balance)
{
Console.WriteLine("Insufficient balance or invalid amount.");
return;
}
Balance -= amount;
Console.WriteLine($"Withdrew {amount}. New balance is {Balance}.");
}
class Program
{
static void Main()
{
var accounts = new BankAccount[] {
new Savings(101, 1000),
new Current(102, 2000),
new Fixed(103, 5000, 0.08),
new Fixed(104, 10000, 0.10)
};
accounts[0].Deposit(500);
accounts[0].Withdraw(300);
accounts[1].Deposit(1000);
accounts[1].Withdraw(500);
}
}Output:
6. Design an interface in C# for displaying product details like product list, product
features, product color, and price. implement the interface for the product car and
mobile phone. write a program for this.
using System;
Console.WriteLine();
using System;
class Point
{
private int x;
private int y;
// Display method
public void Display()
{
Console.WriteLine($"({x}, {y})");
}
}
class Program
{
static void Main(string[] args)
{
// Creating points
Point point1 = new Point(5, 10);
Point point2 = new Point(3, 7);
// Displaying results
Point sum = point1 + point2;
sum.Display();
Console.ReadLine();
Console.ReadKey();
}
}
Output:
8. Design c# class Result to calculate the internal assessment marks of a
student(minor1+ minor2+assignment).Use the delegate feature for this application.
Write a driver program for this.
using System;
Structured Query
To build any form of web application with database connectivity
Step 1
XAMPP makes it possible to create a local server with Apache and MySQL databases with
other features. Click on Start on Apache, and MySQL. The buttons turn the labels into Stop.
Step 2
Click on Databases.
Now, Under Create Database, Type the name of the new database we are going to
create.
Create a Table
You can view the table on the database from the Structure Option in the bar.
Step 4
Install Visual Studio. The Professional Edition is free and can be accessed from the
Microsoft Official Website.
Once installed, the Visual Studio Installer can be opened. Now, click on Launch.
Step 5
Step 6
Step 7
Step 9
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
string MyConnectionString = "Server=127.0.0.1;Database=testdb;Uid=root;Pwd=";
public Form1()
{
InitializeComponent();
}
}
catch (Exception)
{
throw;
}
finally
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
LoadData();
}
}
}
private void LoadData()
{
MySqlConnection connection = new MySqlConnection(MyConnectionString);
connection.Open();
try
{
MySqlCommand cmd = connection.CreateCommand();
cmd.CommandText = "SELECT * FROM signup";
MySqlDataAdapter adap = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adap.Fill(ds);
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
catch (Exception)
{
throw;
}
finally
{
if (connection.State == ConnectionState.Open)
{
connection.Clone();
}
}
}
}
}
Step 10
Click on Run
Enter the values in the respective fields
Click on Submit button
Observe the output in the datagridview
The output found in datagridview is found is stored in Database