Monday, December 17, 2012

PROGRAM TO DEMONSTRATE FUNCTION OVER-LOADING

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication14
{
class Demo
{
public void sum()
{
Console.WriteLine("This sum is without any data");
}
public void sum(int a, int b)
{
int p = a;
int q = b;
int s = p + q;
Console.WriteLine("Sum of two int values: "+s);
}
public void sum(int a, int b, int c)
{
int i = a;
int j = b;
int k = c;
int s = i + j + k;
Console.WriteLine("Sum of three int values: "+s);
}
}
class OverLoadDemo
{
static void Main(string[] args)
{
Demo obj = new Demo();
obj.sum();
obj.sum(5,7);
obj.sum(2,7,12);
Console.ReadLine();
}
}
}

<<<<<<<<<<<<<<<<<<<< OUTPUT >>>>>>>>>>>>>>>>>>>>>>>

This sum is without any data
Sum of two int values: 12
Sum of three int values: 21

PROGRAM TO DEMONSTRATE INHERITANCE

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

namespace ConsoleApplication13
{
class A
{
int a, b, c;
public void show()
{
a = 10;
b = 15;
c=a+b;
Console .WriteLine ("Result of class A: "+c);
}
}
class B : A
{
public void display()
{
Console.WriteLine("We are in class B ");
}
}
class InheritanceDemo
{
static void Main(string[] args)
{
B obj = new B();
obj.show(); //accessing class A's function by B's object
obj.display();
Console.ReadLine();
}
}
}

<<<<<<<<<<<<<<<<<<<<<<< OUTPUT >>>>>>>>>>>>>>>>>>>>>>>

Result of class A: 25

We are in class B

PROGRAM TO GET POWER OF A NUMBER RAISED TO ANOTHER

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

namespace ConsoleApplication12
{
class Program
 {
static void Main(string[] args)
{
int num, pow, temp;
Console.Write("Enter the number: ");
String strNUM=Console.ReadLine();
num = int.Parse(strNUM);
Console.Write("Enter the power: ");
String strPOW = Console.ReadLine();
pow = int.Parse(strPOW);
temp = num*num;
for (int i = 2; i {
temp = (temp * num);
}
Console.WriteLine("Result= "+temp);
Console.ReadLine();
}
}
}

<<<<<<<<<<<<<<<<<<<<<<<< OUTPUT >>>>>>>>>>>>>>>>>>>>>>>>>>>>

Enter the number:12

Enter the power:2

Result= 144