NAME: ANMOL BANSAL
SECTION: G1
ROLL NO:16
SUBJECT: PROGRAMING WITH .NET C#
PROBLEM STATEMENT 7: Wap to create a class circle and its method.
using System;
class Circle
{ public double Radius { get; set; }
public Circle(double radius)
{ Radius = radius; }
public double CalculateArea()
{ return Math.PI * Radius * Radius;}
public double CalculateCircumference()
{ return 2 * Math.PI * Radius;}}
class Program
{static void Main(string[] args){
Console.Write("Enter the radius of the circle: ");
double radius = Convert.ToDouble(Console.ReadLine());
Circle circle = new Circle(radius);
Console.WriteLine($"Area of the circle: {circle.CalculateArea()}");
Console.WriteLine($"Circumference of the circle:
{circle.CalculateCircumference()}");
}
}
OUTPUT:
NAME: ANMOL BANSAL
SECTION: G1
ROLL NO:16
SUBJECT: PROGRAMING WITH .NET C#
PROBLEM STATEMENT 9: Wap to create the method overloading and
method overriding
CODE OF METHOD OVERLOADING:
using System;
class Calculator
{ public int Add(int a, int b){
return a + b; }
public int Add(int a, int b, int c)
{ return a + b + c;}
public double Add(double a, double b)
{ return a + b; }}
class Program
{
static void Main(string[] args)
{ Calculator calculator = new Calculator();
Console.WriteLine("THE SUM OF TWO NO ARE "+calculator.Add(10,
20));
Console.WriteLine("THE SUM OF THREE NO ARE "+calculator.Add(10,
20, 30));
Console.WriteLine("THE SUM OF DOUBLE VALUE ARE
"+calculator.Add(10.5, 20.3)); }}
OUTPUT:
NAME: ANMOL BANSAL
SECTION: G1
ROLL NO:16
SUBJECT: PROGRAMING WITH .NET C#
CODE FOR METHOD OVERRIDING:
using System;
class Animal
{public virtual void Speak() {
Console.WriteLine("The animal makes a sound.");}}
class Dog : Animal
{ public override void Speak(){
Console.WriteLine("The dog barks.");}}
class Cat : Animal
{ public override void Speak() {
Console.WriteLine("The cat meows."); }}
class Program
{ static void Main(string[] args){
Animal myAnimal = new Animal();
Animal myDog = new Dog();
Animal myCat = new Cat();
myAnimal.Speak();
myDog.Speak();
myCat.Speak(); }}
OUTPUT:
NAME: ANMOL BANSAL
SECTION: G1
ROLL NO:16
SUBJECT: PROGRAMING WITH .NET C#
PROBLEM STATEMENT 10: Wap to demonstrate all the operators
ARITHEMATIC OPERATOR:
CODE:
using System;
class Program
{static void Main(string[] args)
{int a = 10, b = 3;
Console.WriteLine($"Addition: {a + b}");
Console.WriteLine($"Subtraction: {a - b}");
Console.WriteLine($"Multiplication: {a * b}");
Console.WriteLine($"Division: {a / b}");
Console.WriteLine($"Modulus (Remainder): {a % b}");
}
}
OUTPUT:
NAME: ANMOL BANSAL
SECTION: G1
ROLL NO:16
SUBJECT: PROGRAMING WITH .NET C#
RELATIONAL OPERATOR:
CODE:
class Program
{
static void Main(string[] args)
{
int a = 10, b = 20;
Console.WriteLine($"a == b: {a == b}"); // False
Console.WriteLine($"a != b: {a != b}"); // True
Console.WriteLine($"a > b: {a > b}"); // False
Console.WriteLine($"a < b: {a < b}"); // True
Console.WriteLine($"a >= b: {a >= b}"); // False
Console.WriteLine($"a <= b: {a <= b}"); // True
}
}
OUTPUT:
NAME: ANMOL BANSAL
SECTION: G1
ROLL NO:16
SUBJECT: PROGRAMING WITH .NET C#
LOGICAL OPERATOR
CODE:
class Program
{
static void Main(string[] args)
{
bool x = true, y = false;
Console.WriteLine($"x && y: {x && y}"); // False (AND)
Console.WriteLine($"x || y: {x || y}"); // True (OR)
Console.WriteLine($"!x: {!x}"); // False (NOT)
}
}
OUTPUT:
NAME: ANMOL BANSAL
SECTION: G1
ROLL NO:16
SUBJECT: PROGRAMING WITH .NET C#
BITWISE OERATOR:
CODE:
class Program
{
static void Main(string[] args)
{
int a = 5, b = 3; // 5 = 0101, 3 = 0011 in binary
Console.WriteLine($"a & b: {a & b}");
Console.WriteLine($"a | b: {a | b}");
Console.WriteLine($"a ^ b: {a ^ b}")
Console.WriteLine($"~a: {~a}");
Console.WriteLine($"a << 1: {a << 1}");
Console.WriteLine($"a >> 1: {a >> 1}");
}
OUTPUT:
NAME: ANMOL BANSAL
SECTION: G1
ROLL NO:16
SUBJECT: PROGRAMING WITH .NET C#
ASSIGNMENT OPERATOR:
CODE;
class Program
{
static void Main(string[] args)
{
int a = 10;
a += 5;
Console.WriteLine($"a += 5: {a}");
a -= 3;
Console.WriteLine($"a -= 3: {a}");
a *= 2;
Console.WriteLine($"a *= 2: {a}");
a /= 2;
Console.WriteLine($"a /= 2: {a}");
a %= 3;
Console.WriteLine($"a %= 3: {a}");
}
}
OUTPUT: