Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Exp 17 Wap To Implement Multiple Inheritance Using Interfaces

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

EXP 17 WAP TO IMPLEMENT MULTIPLE INHERITANCE USING

INTERFACES

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication55
{
interface Addition
{
int Add();
}
interface Multiplication
{
int Mul();
}
class Computation : Addition, Multiplication
{
int x, y;
public Computation(int x, int y)
{
this.x = x;
this.y = y;
}
public int Add()
{
return (x + y);
}
public int Mul()
{
return (x * y);
}

}
class InterfaceTest
{
static void Main()
{
Computation com = new Computation(20, 30);
Addition add = (Addition)com;
Console.WriteLine("sum=" + add.Add());
Multiplication mul = (Multiplication)com;
Console.WriteLine("product =" + mul.Mul());

}
}
}

Exp 18 wap to create and implement dalegate

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication59
{
delegate int ArithOP(int x, int y);
class InstanceMO
{
public int Mul(int a, int b)
{
return (a * b);
}
}

class MO
{
public static int Add(int a, int b)
{
return (a + b);
}
public static int Sub(int a, int b)
{
return (a - b);
}
}
class DelegateTest
{
public static void Main()
{
InstanceMO io = new InstanceMO();
ArithOP multiplication = new ArithOP(io.Mul);
ArithOP addition = new ArithOP(MO.Add);
ArithOP subtraction = new ArithOP(MO.Sub);
int result1 = multiplication(100, 200);
int result2 = addition(200, 100);
int result3 = subtraction(250, 100);
Console.WriteLine("product=" + result1);
Console.WriteLine("addition=" + result2);
Console.WriteLine("subtraction" + result3);
}
}
}

Exp 19 wap to implement a property

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication62
{
class Number
{
private int number;

public int Anumber


{
get
{
return number;
}
set
{
number = value;
}
}
}
class Program
{
public static void Main()
{
Number n = new Number();
n.Anumber = 100;
int m = n.Anumber;
Console.WriteLine("number=" + m);
Console.ReadLine();
}
}
}

Exp 20 wap to index an object of a class as


an array

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication60
{
class Myclass
{
private string[] data = new string[5];
public string this[int index]
{
get
{
return data[index];
}
set
{
data[index] = value;
}
}
}

class Myclient
{
public static void Main()
{
Myclass mc = new Myclass();
mc[0] = " Tarun";
mc[1] = "\n Ajeesh";
mc[2] = "\n Ankit";
mc[3] = "\n Pranav";
mc[4] = "\n Ishant";
Console.WriteLine("{0}{1}{2}{3}{4}", mc[0], mc[1], mc[2],
mc[3], mc[4]);
Console.ReadLine();
}
}
}
Exp 21 wap to implement exception handling
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication58
{
class Program
{
static void Main(string[] args)
{
int a, b, c, x, y;
a = 10;
b = 5;
c = 5;
try
{
x = a / (b - c);
}
catch (DivideByZeroException)
{
Console.WriteLine("Divide by zero error");
}
y = a / (b + c);
Console.WriteLine("y=" + y);
Console.ReadLine();
}
}
}

Shayad krna hai


using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication23
{
class Program
{
static void Main(string[] args)
{
Date d = new Date();
d.display();
Console.ReadLine();

}
}
class Date
{
public int date;
public int month;
public int year;
public void GetDate()
{
Console.WriteLine("enter the date");
date = int.Parse(Console.ReadLine());

}
public void GetMonth()
{
Console.WriteLine("enter the month");
month = int.Parse(Console.ReadLine());

}
public void GetYear()
{
Console.WriteLine("enter the year");
year = int.Parse(Console.ReadLine());

}
public void display()
{

GetDate();
GetMonth();
GetYear();
Console.Write("date is:");
Console.Write(date + "/" + month + "/" + year);

}
}

You might also like