Skip to main content

C#: Program #33 (Structures)

using System;

namespace Structure
{
    class Program
    {
        static void Main(string[] args)
        {
           triangle tri1, tri2;
           tri1.breadth = 2;
           tri1.height = 3;
           tri1.area = 4;
           tri1.areaCal();

           tri2.breadth = 0;
           tri2.height = 0;
           tri2.area = 0;
           tri2.areaCal(5.2f, 4.4f);

           Console.ReadKey();

        }

        struct triangle
        {
            public float breadth;
            public float height;
            public float area;
           public triangle(float b,float l,float a)
            {
                breadth =b;
                height = l;
                area = a;
            }

            public void areaCal()
            {
                area = 0.5f*(breadth * height);
                Console.WriteLine("The area of the triangle is {0}",area);
            }
            public void areaCal(float l,float b)
            {
               area = 0.5f * (b * l);
                Console.WriteLine("The area of the triangle is {0}", area);
            }
        }
    }
}

Comments

Popular posts from this blog

C#: Program #35 (Oop2)

using System; namespace OOP_CONSTRUCTORS { class Animals     {         private string name;         private string sound;         public const string shelter = "Aibo's Hangout";         public Animals()             : this("No Name", "No Sound") { }         public Animals(string name)             : this(name, "No Sound") { }         public Animals(string n, string s)         {             setName(n);             SoundCap = s;             Console.WriteLine(SoundCap);             Counter = 1;             Console.WriteLine(Count);         }         public void introduced()         {             Console.WriteLine("Voice of {0} sounds like {1}", name, sound);         }         public void setName(string n)         {             int i = 1;                foreach(char c in n)                {                    if (!char.IsLetter(c))                    {                        i = 0;                    }

C#: Program #24 (DoWhile Loop)

using System; namespace DoWhile {     class Program     {         static void Main(string[] args)         {             Random no = new Random();             int numbergenerated = no.Next(1,20);             int numberguessed;             int turns=0;             do             {                 if (turns != 0)                 {                     Console.WriteLine("Guessed Wrong Number!");                 }                 Console.WriteLine("Guess a number between 1 and 20");                 numberguessed = Convert.ToInt32(Console.ReadLine());                 turns++;             } while (numberguessed != numbergenerated);             Console.WriteLine("Correct you got it in {0} turns",turns);             Console.ReadKey();         }     } }