C Sharplab4
C Sharplab4
using System;
namespace System
{
public class Demo
{
public static void Main(string[] args)
{
int[][] jag = new int[3][];
jag[0] = new int[2];
jag[1] = new int[4];
jag[2] = new int[3];
int[]sum = new int[3];
int result = 0;
int i, j;
for (i = 0; i < 3; i++)
sum[i] = 0;
Console.WriteLine(" enter the size of the array");
for(i=0;i<jag.Length;i++)
{
Console.WriteLine("enter the value of array" + (i + 1) + "jag");
for (j = 0; j < jag[i].Length;j++)
{
jag[i][j] = Convert.ToInt32(Console.ReadLine());
}
}
for(i=0;i<jag.Length;i++)
{
for (j = 0; j < jag[i].Length;j++)
{
sum[i] = sum[i] + jag[i][j];
}
}
for (i = 0; i < 3; i++)
result = result + sum[i];
Console.WriteLine("the result of individual jag row wise");
for (i = 0; i < 3; i++)
Console.WriteLine(sum[i] + "\t");
Console.WriteLine();
Console.WriteLine("the final sum of all the elements in jagged array:" + result);
Console.ReadKey();
}
}
}
using System;
public interface IPointy
{
byte GetNumberofpoints();
void Draw();
}
public class Hexagon:IPointy
{
string shape;
public Hexagon() { }
public Hexagon(string name)
{
shape = name;
}
public void Draw(){
Console.WriteLine("--------------");
Console.WriteLine(" drawing the " + shape);
}
public byte GetNumberofpoints()
{
return 6;
}
}
public class Triangle:IPointy
{
string shape;
public Triangle() { }
public Triangle(string name)
{
shape = name;
}
public void Draw()
{
Console.WriteLine("--------------");
Console.WriteLine(" drawing the " + shape);
}
public byte GetNumberofpoints()
{
return 3;
}
}
class arrayExample
{
static void Main(string[] args)
{
Console.WriteLine("Demonstarting arrays of interface");
IPointy[] obj = { new Triangle("Triangle"),new Hexagon("Hexagon") };
foreach(IPointy I in obj)
{
I.Draw();
Console.WriteLine("number of points are{0}\n",I.GetNumberofpoints());
}
Console.ReadLine();
}
}
6.Construct a console application to demonstarte abstract class and abstract method
using System;
abstract class AreaClass
{
protected float rad;
public abstract float Radius { get;
set;
}
public abstract void area(float n);
}
class Circle:AreaClass
{
public override float Radius
{
get
{
return rad;
}
set
{
rad = value;
}
}
public override void area(float r)
{
Console.WriteLine(" area of circle is{0}",3.14*r*r );
}
}
class CircleClass {
public static void Main( ) {
Circle c = new Circle();
Console.WriteLine("enter radius value");
c.Radius=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("radius holding value is{0}", c.Radius);
c.area(c.Radius);
}
}