c# console

13
VB.NET Console Application: Write a program for string manipulation (Split, Concat, Compare, Equal, Padding, Copy, Duplicate, Replace, IndexOf, SubString) Write a program for calculating age with the help of DateTime Write a program for recursion (Fibonacci & Factorial) Write a program for finding area of different shapes using polymorphism Write a program for function overriding Write a program for Employee Information using Class Write a program for illustrate Inheritance Windows Forms: 1. Design form to create Calculator Application 2. Design a Logon Form and Validate it 3. Design a form for Digital Clock 4. Design form to select image name from list and display in picture box 5. Design a form to use menus 6. Design a form to connect with database using ADO.NET (List, Insert, update, Delete) C# programs Console Application: 1. Write a program for recursion (Fibonacci & Factorial) Factorial : using System; using System.Collections.Generic; using System.Linq;

Upload: abhi-andhariya

Post on 28-Nov-2014

88 views

Category:

Documents


6 download

TRANSCRIPT

VB.NET

Console Application:

Write a program for string manipulation (Split, Concat, Compare, Equal, Padding, Copy, Duplicate, Replace, IndexOf, SubString)

Write a program for calculating age with the help of DateTime Write a program for recursion (Fibonacci & Factorial) Write a program for finding area of different shapes using polymorphism Write a program for function overriding Write a program for Employee Information using Class Write a program for illustrate Inheritance

Windows Forms:

1. Design form to create Calculator Application2. Design a Logon Form and Validate it3. Design a form for Digital Clock4. Design form to select image name from list and display in picture box5. Design a form to use menus6. Design a form to connect with database using ADO.NET (List, Insert, update, Delete)

C# programs

Console Application:

1. Write a program for recursion (Fibonacci & Factorial)Factorial :

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

namespace ConsoleApplication2{ class Factorial { static void Main(string[] args) { int i;

Console.Write("Enter a number to get factorial : "); i = Convert.ToInt32(Console.ReadLine()); Console.Write("Factorial of {0} is {1}", i, fact(i)); Console.ReadLine(); } static int fact(int i) { if (i == 1) return 1; else return i * fact(i - 1); } }}

Fibonacci

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

namespace ConsoleApplication2

{ class Factorial { static void Main(string[] args) { int i; Console.Write("Enter a number to get fibonacci serias : "); i = Convert.ToInt32(Console.ReadLine()); Console.Write("Fibonacci serail \n"); fib(i); Console.ReadLine(); } static void fib(int i) { int j = 0, n = 0; int k = 1; int temp;

Console.Write("{0} {1} ", j, k); while (n <= i) { temp = j + k; Console.Write("{0} ", temp); j = k; k = temp; n++;

}

} }}

2. Write a program for finding area of different shapes using polymorphism

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

namespace ConsoleApplication2{ class Shape { public void Area(int length) { int Area = length * length; Console.WriteLine("Area of Square is : " + Area); }

public void Area(int length,int breadth) { int Area = length * breadth; Console.WriteLine("Area of Rectangle is : " + Area); }

public void Area(double radius) { double Area = 3.14 * radius * radius; Console.WriteLine("Area of Circle is : " + Area); } } public class DerivedClass { static void Main(string[] args) { Shape s=new Shape(); s.Area(15); s.Area(10,20); s.Area(10.5); Console.ReadLine(); } }}

3. Write a program for function overriding

using System;

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

namespace ConsoleApplication2{ class BaseClass { public void display() { Console.WriteLine("Method from Base Class"); } } class DerivedClass : BaseClass { public void display() { Console.WriteLine("Method from Derived class"); } } public class MainClass { static void Main(string[] args) { DerivedClass d = new DerivedClass(); BaseClass b = new BaseClass(); d.display(); b.display(); Console.ReadLine(); } }}

4. Write a program for illustrate Inheritance

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

namespace ConsoleApplication2{ class BaseClass { public void display() { Console.WriteLine("Method from Base Class"); } public void Area() { int radius; Console.WriteLine("Enter radius of circle : "); radius = Convert.ToInt32(Console.ReadLine()); double Area = 3.14 * radius * radius;

Console.WriteLine("Area of Circle is : " + Area); }

} class DerivedClass : BaseClass { public void AreaofRect() { int length, breadth; Console.WriteLine("Enter length and breadth of rectangle : "); length = Convert.ToInt32(Console.ReadLine()); breadth = Convert.ToInt32(Console.ReadLine()); int Area = length * breadth; Console.WriteLine("Area of Rectangle is : " + Area); }

}

class MainClass { static void Main(string[] args) { DerivedClass d = new DerivedClass(); d.display(); d.Area(); d.AreaofRect(); Console.ReadLine(); } }}

5. Demonstrate the use of Delegates.

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace dn047{ public delegate void binaldelegate(int n); class Event1 { public event binaldelegate status; public void implement(int n) { if (status != null) { status(n); } } } class Response { public void eventcatch(int n)

{ Console.WriteLine("\nMultiple Of 4:= " + n);

Console.WriteLine("\nsquare of That Multiple:= " + n * n);

Console.WriteLine("******"); } } class Test { public static int i; public static void Main(string[] args) { //DEFINATION::::: //Event class,Response class,Test class //in test class numbers moves from 1 to 40 //when 4 or its multiple comes event is triggered //when event is triggered the number and its square is printed int b = 41; int[] a = new int[b]; Response ob = new Response(); Event1 ob2 = new Event1(); ob2.status += new binaldelegate(ob.eventcatch); //Anonymous method ob2.status += delegate (int n) { Console.WriteLine("\nMultiple Of 4:= " + n); Console.WriteLine("\nsquare of That Multiple:= " + n * n);

Console.WriteLine("******"); };

for (i = 1; i < b; i++) { a[i] = i; if (a[i] % 4 == 0) {

ob2.implement(a[i]); } } Console.ReadLine(); } }}

6. Demonstrate the use of Indexer.

using System;

class Layout{ string[] _values = new string[100]; // Backing store

public string this[int number] {

get{ // This is invoked when accessing Layout instances with the [ ]. if (number >= 0 && number < _values.Length) {

// Bounds were in range, so return the stored value.return _values[number];

} // Return an error string. return "Error";}set

{ // This is invoked when assigning to Layout instances with the

[ ]. if (number >= 0 && number < _values.Length) {

// Assign to this element slot in the internal array._values[number] = value;

}}

}}

class Program{ static void Main() {

// Create new instance and assign elements in the array through the indexer.

Layout layout = new Layout();layout[1] = "Frank Gehry";layout[3] = "I. M. Pei";layout[10] = "Frank Lloyd Wright";layout[11] = "Apollodorus";layout[-1] = "Error";layout[1000] = "Error";

// Read elements through the indexer.string value1 = layout[1];string value2 = layout[3];string value3 = layout[10];string value4 = layout[11];string value5 = layout[50];string value6 = layout[-1];

// Write the results.Console.WriteLine(value1);Console.WriteLine(value2);Console.WriteLine(value3);Console.WriteLine(value4);Console.WriteLine(value5); // Is nullConsole.WriteLine(value6);

}}

Output

Frank GehryI. M. PeiFrank Lloyd WrightApollodorus(null)Error

Windows Form:

1. Design a Logon Form and Validate it2. Design a form to connect with database using ADO.NET (List, Insert, update, Delete)