Using System
Using System
namespace pract9
{
class Program
{
}
}
}
Pract10
using System;
namespace pract10
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("pawan \n");
int inr;
Console.WriteLine("Enter an Dollar Rupees");
inr = int.Parse(Console.ReadLine());
double rupee = inr * 82.88;
}
}
}
Pract 11
using System;
namespace pract11
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Pawan ");
int a, b, c;
Console.WriteLine("Enter an 'a' no: ");
a = int.Parse(Console.ReadLine());
Console.WriteLine("Enter an 'b' no: ");
b = int.Parse(Console.ReadLine());
Console.WriteLine("Enter an 'c' no: ");
c = int.Parse(Console.ReadLine());
double d, x1, x2;
d = b * b - 4 * a * c;
if (d == 0)
{
x1 = -b / (2.0 * a);
x2 = x1;
Console.WriteLine("First root 1" + x1);
Console.WriteLine("Second root 1" + x2);
}
else if (d > 0)
{
x1 = (-b + Math.Sqrt(d)) / (2 * a);
x2 = (-b - Math.Sqrt(d)) / (2 * a);
Console.WriteLine("First root " + x1);
Console.WriteLine("Second root " + x2);
}
else
{
Console.WriteLine("The answer is imaginary");
}
Console.ReadKey();
}
}
}
Pract 12
Console.WriteLine("Pawan \n");
double fahrenheit;
double celsius;
Console.WriteLine("Enter an Celsius: \n");
celsius = int.Parse(Console.ReadLine());
Console.WriteLine("Celsius: " + celsius);
fahrenheit = (celsius * 9) / 5 + 32;
Console.WriteLine("Fahrenheit: " + fahrenheit);
Console.ReadLine();
Pract13
using System;
namespace pract13
{
public class MathOperations
{
public int Add(int a, int b)
{
return a + b;
}
class Program
{
}
}
}
Pract 14
using System;
// Base class
public class Vehicle
{
public void Start()
{
Console.WriteLine("The Pawan" +" vehicle is starting.");
}
}
// Multilevel Inheritance: Derived class inherits from a class which itself inherits from
a base class
public class ElectricCar : Car
{
public void Charge()
{
Console.WriteLine("The electric car is charging.");
}
}
// Hierarchical Inheritance: Multiple derived classes inherit from the same base class
public class Truck : Vehicle
{
public void Haul()
{
Console.WriteLine("The truck is hauling.");
}
}
class Program
{
static void Main(string[] args)
{
Car car = new Car();
car.Start();
car.Drive();
namespace pract15
{
public class Student
{
public string Name { get; set; }
public int Age { get; set; }
public string Major { get; set; }
// Default constructor
public Student()
{
Name = "Unknown";
Age = 0;
Major = "Undeclared";
}
class Program
{
static void Main(string[] args)
{
Student student1 = new Student("Pawan", 20, "BscIt");
Student student2 = new Student("Akash", 20, "Mca");
Student student3 = new Student("Ahin", 22, "Computer Science");
Console.WriteLine("Student 1:");
student1.DisplayInfo();
Console.WriteLine("\nStudent 2:");
student2.DisplayInfo();
Console.WriteLine("\nStudent 3:");
student3.DisplayInfo();
Console.ReadKey();
}
}
}
Pract16
using System;
namespace pract16
{
class Program
{
static void Main(string[] args)
{
try
{
Console.Write("Pawan\n");
Console.Write("Enter a number: ");
int num = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"Result: {result}");
}
catch (DivideByZeroException)
{
Console.WriteLine("Error: Cannot divide by zero.");
}
catch (FormatException)
{
Console.WriteLine("Error: Invalid input format.");
}
finally
{
Console.WriteLine("Execution completed.");
}
Console.ReadKey();
}
}
}
Pract17
using System;
namespace pract17
{
// Define a delegate
delegate void MessageHandler(string message);
class Notifier
{
// Declare an event of the delegate type
public event MessageHandler MessageSent;
class Subscriber
{
public void OnMessageReceived(string message)
{
Console.WriteLine($"Received message: {message}");
}
}
class Program
{
static void Main(string[] args)
{
Notifier notifier = new Notifier();
Subscriber subscriber = new Subscriber();