0% found this document useful (0 votes)
22 views3 pages

C Sharplab4

The document demonstrates a C# .NET console application to calculate the sum of all elements in a jagged array with 3 inner arrays. It also shows arrays of interface types in C# .NET and constructing an abstract class and abstract method.

Uploaded by

Pushpa Prashanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

C Sharplab4

The document demonstrates a C# .NET console application to calculate the sum of all elements in a jagged array with 3 inner arrays. It also shows arrays of interface types in C# .NET and constructing an abstract class and abstract method.

Uploaded by

Pushpa Prashanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

4.Develop a c#.neT console application to find sum of all the elements present in a jagged array of 3 inner arrays.

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();
}
}
}

5.Demonstarte arrays of interface typesd in c#.NET

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);
}
}

You might also like