Pages

Make a c# Class that have Two METHODS getData() And display()....using Classes And Methods

INPUT:


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

namespace ConsoleApplication2
{
    class Program
    {
     
        static void Main(string[] args)
        {
           
            Computer c = new Computer();
            c.GetData();
            c.Display();
          
           
        }
        class Computer
        {
            string Colour;
            int Model;
            int ScreenSize;
            public void GetData()
            {

                Console.WriteLine("Plz Enter Colour");
                Colour = Console.ReadLine();
                Console.WriteLine("Plz Enter Model");
                Model = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Plz Enter The Screen Size");
                ScreenSize = Convert.ToInt32(Console.ReadLine());

            }
           
            public void Display()
            {

              
                Console.WriteLine("Computer Colour in {0}",Colour);
                Console.WriteLine("Computer Model  in {0}", Model);
                Console.WriteLine("Computer Model  in {0}",ScreenSize);
              

            }
        }
    }
}

OUTPUT:


Write a program in C# and find the value of final velocity by using S= (〖Vf〗^2-〖Vi〗^2)/2a.

INPUT:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
{   
class myclass
    {
        public double visquare(double vi)
        {
            double s = vi *vi;
            return s;
        }
        public double vfsquare(double vf)
        {
            double s = vf * vf;
            return s;
        }
        public double  s(double  vf,double vi)
    {
        double s = (vfsquare(vf) + visquare(vi)) / (2 * 9.98);
        return s;
    }
        static void Main(string[] args)
        {
            double vf,vi;
            Console.WriteLine("plz enter the final  velocity");
            vf=Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("plz enter the initial velocity ");
            vi= Convert.ToDouble(Console.ReadLine());
            myclass m = new myclass();
         
          Console.WriteLine("vf = (vi2+vf2)/2a = {0}",m.s(vf,vi));
        }  
    }
}

OUTPUT:


Write a program in C# and find the value of final velocity by using Vf=Vi+at using methods.

Solution:

Pseudo Code:

  1. Initialize variable "vi"  (this will hold initial velocity value) 
  2. Initialize variable "t" to (this will hold time value) 
  3. Print message on console to ask user to input Initial velocity.
  4. Read user's input and convert to Double and store that input into variable "vi" that is necessary for velocity formula.
  5. Print message on console to ask user to input Time.
  6. Read user's input and convert to Double and store that input into variable "t" that is necessary for velocity formula.
  7. create a separate function "calculateFinalVelocity" that will calculate velocity on the basis of initial velocity and time values and will return the final velocity, then  call "calculateFinalVelocity(vi,t)" function and pass "vi" and "t".  
  8. Print the return value of  on console to show the final velocity...

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
 {
class myclass
    {
        public double  calculateFinalVelocity(double  vi,double t)
        {
            double vf =  vi+t*9.98;
            return vf;
        }
        static void Main(string[] args)
        {
            double vi,t;
            Console.WriteLine("plz enter the initial velocity");
            vi=Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("plz enter the time ");
            t= Convert.ToDouble(Console.ReadLine());
            myclass m = new myclass();
         
          Console.WriteLine("the the final velocity is {0}",m.calculateFinalVelocity(vi,t));
        }
        
    }

}

Output:


Write a program that Calculate areas of rectangle using methods.

INPUT:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
{
class myclass
    {
        public double  method(double h,double w)
    {
        double Ar = h * w;
        return Ar;
    }
        static void Main(string[] args)
        {
            double h,w;
            Console.WriteLine("plz enter the height");
            h=Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("plz enter the wdth");
            w= Convert.ToDouble(Console.ReadLine());
            myclass m = new myclass();
         
          Console.WriteLine("the Area of the circle is {0}",m.method(h,w));
        }
        
    }
}


OUTPUT:


Write a program that Calculates areas of circle by using methods.

INPUT:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
{
class myclass
    {
        public double  method(double  r)
    {
        double  A = 3.14 * r * r;
        return A;
    }
        static void Main(string[] args)
        {
            double radius;
            Console.WriteLine("plz enter the radius");
            radius=Convert.ToDouble(Console.ReadLine());
            myclass m = new myclass();
         
          Console.WriteLine("the Area of the circle is {0}",m.method(radius));
        }
        
    }
}


OUTPUT:


E A PROGRAMME TO FND THE VALUE OF X BY QUARDIC FORMULA USING METHODS:

INPUT:

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

namespace a
{
    class quadraticformula
    {
        double squareofb(double b)
        {
            double value = b * b;
            return value;
        }
        double x1(double a, double b, double c)
        {
            double ac4=4*a*c;
            double b1 =Math.Sqrt(squareofb(b)-ac4);
            double x = ((-b+b1 )/(2*a));
            return x;
        }
        double x2(double a, double b, double c)
        {
            double ac4=4*a*c;
            double b1= Math.Sqrt(squareofb(b)-ac4);
            double x =((-b-b1)/(2*a));
            return x;
        }
        static void Main(string[] args)
        {
            double a, b, c;
            Console.WriteLine("plz input the value of a");
            a = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("plz input the value of b");
            b = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("plz input the value of c");
            c = Convert.ToDouble(Console.ReadLine());
            quadraticformula q = new quadraticformula();
            Console.WriteLine("x1={0}", q.x1(a,b,c));
            Console.WriteLine("x2={0}", q.x2(a, b, c));
        }
    }
}

OUTPUT:


MAKE A PROGRAMME TO FIND THE SiDES LENGTH OF TRIANGLE BY METHODS

INPUT:

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

namespace a
{
    class hypotenous
    {
        double square1(double a1)
        {
            double a2 = a1 * a1;
            return a2;
        }
        double square2(double b1)
        {
            double a2 = b1*b1;
            return a2;
        }
        double hyp(double a, double b)
        {
            double a1=square1(a);
           double b1= square2(b);
            double c =Math.Sqrt( a1 + b1);
            return c;
        }
        double perpendicular(double a, double b)
        {
            double a1 = square1(a);
            double b1 = square2(b);
            double c = Math.Sqrt(a1 - b1);
            return c;
        }
        double bas(double a, double b)
        {
            double a1 = square1(a);
            double b1 = square2(b);
            double c = Math.Sqrt(a1 - b1);
            return c;
        }
        static void Main(string[] args)
        {
            double a, b;
            Console.WriteLine("plz type the option base, perpendicular, hypotenouos");
            string option = Console.ReadLine();
            hypotenous h = new hypotenous();
            if (option == "base")
            {
                Console.WriteLine("plz enter the hypotenous ");
                a = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("plz enter the perpendicular");
                b = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("B={0}", h.bas(a, b));
            }
            else if (option == "perpendicular")
            {
                Console.WriteLine("plz enter the hypotenous ");
                a = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("plz enter the base");
                b = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("P={0}", h.perpendicular(a, b));
            }
            else if (option == "hypotenouos")
            {
                Console.WriteLine("plz enter the perpendicular");
                a = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("plz enter the base");
                b = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("H={0}", h.hyp(a, b));
            }
        }
    }
}

OUTPUT:


Write a program that find value from "pythagoras theorem" by using Methods

INPUT:

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("~~~~~PYTHAGORAS THEOREM~~~~~");
            int p, b;
            Console.WriteLine("Please enter Perpendicular");
            p = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Please enter Base");
            b = Convert.ToInt32(Console.ReadLine());
            double BSQR = bsqr(b);
            double PSQR = psqr(p);
            double SUMSQR = sumsqr(b, p);
            Console.WriteLine("Hyp {0}", SUMSQR);

        }
        public static double bsqr(int b)
        {
            double s;
            s = b * b;
            return s;
        }

        public static double psqr(int p)
        {
            double s;
            s = p * p;
            return s;
        }

        public static double sumsqr(int b, int p)
        {
            double s;
            s = b + p;
            s = Math.Sqrt(s);
            return s;
        }
    }

}
OUTPUT:


Write A c# program that input user phone num and user name and find the details of user by input Name (Linear Search)

INPUT:

  
       
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
{     
    class Program
    {
        static void Main(string[] args)
        {
            char option;
            string find;
            string[,] phone_book = new string[5, 2];
            for (int i = 0; i <= 4; i++)
            {
                for (int j = 0; j <= 1; j++)
                {
                    if (i == 0 && j == 0)
                    {
                        phone_book[i, j] = "Name";
                    }
                    else if (i == 0)
                    {
                        phone_book[i, j] = "Contact";
                    }
                    else if (j == 0)
                    {
                        Console.WriteLine("plz enter the {0} Contact Name", i);
                        phone_book[i, j] = Console.ReadLine();
                    }
                    else if (j == 1)
                    {
                        Console.WriteLine("plz enter the  Contact Number of {0}", phone_book[i,0]);
                        phone_book[i, j] = Console.ReadLine();
                    }
                }
            }
           
            do
            {
                Console.WriteLine("plz enter the contact number or name to dial");
                find = Console.ReadLine();
                for (int i = 0; i <= 4; i++)
                {
                for (int j = 0; j <= 1; j++)
                {
                        if (find == phone_book[i, j])
                        {
                            Console.WriteLine(" Name {0}  Number {1} ", phone_book[i, 0], phone_book[i, 1]);
                        }
                }
                }
                Console.WriteLine("preess y for search again");
                option = Convert.ToChar(Console.ReadLine());
            }
            while (option != 'n');
                }
            }
        }
    
   


   


OUTPUT: