Professional Documents
Culture Documents
AIM
TO Write a C# Program for the Following in Console Application Inheritance ,Interface and
Polymorphism
ALGORITHM:
INHERITANCE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
public class Tutorial
{
protected int TutorialID;
protected string TutorialName;
pTutor.RenameTutorial(".Net by Guru99");
Console.WriteLine(pTutor.GetTutorial());
Console.ReadKey();
}
}
}
OUTPUT
POLYMORPHISM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
class Tutorial
{
public int TutorialID;
public string TutorialName;
public void SetTutorial(int pID,string pName)
{
TutorialID=pID;
TutorialName=pName;
}
public void SetTutorial(string pName)
{
TutorialName=pName;
}
public String GetTutorial()
{
return TutorialName;
}
pTutor.SetTutorial(1,"First Tutorial");
Console.WriteLine(pTutor.GetTutorial());
pTutor.SetTutorial("Second Tutorial");
Console.WriteLine(pTutor.GetTutorial());
Console.ReadKey();
}
}
}
OUTPUT
INTERFACE
using System;
namespace CsharpInterface {
interface IPolygon {
// method without body
void calculateArea(int l, int b);
}
class Rectangle : IPolygon {
// implementation of methods inside interface
public void calculateArea(int l, int b) {
int area = l * b;
Console.WriteLine("Area of Rectangle: " + area);
}
}
class Program {
static void Main (string [] args) {
Rectangle r1 = new Rectangle();
r1.calculateArea(100, 200);
}
}
}
OUTPUT
OUTPUT:
ogbeeca
● g b e e c a
c) String Formatting
public class FormatSpecApp
{
public static void Main(string[] args)
{
int x = 16;
decimal y = 3.57m;
string h = String.Format(
"item {0} sells at {1:C}", x, y);
Console.WriteLine(h);
}
}
OUTPUT:
item 12 sells at £3.45
public class FormatSpecApp1
{
public static void Main(string[] args)
{
int i = 123456;
Console.WriteLine("{0:C}", i); // £123,456.00
Console.WriteLine("{0:D}", i); // 123456
Console.WriteLine("{0:E}", i); // 1.234560E+005
Console.WriteLine("{0:F}", i); // 123456.00
Console.WriteLine("{0:G}", i); // 123456
Console.WriteLine("{0:N}", i); // 123,456.00
Console.WriteLine("{0:P}", i); // 12,345,600.00 %
Console.WriteLine("{0:X}", i); // 1E240
}
}
objectType.Thing
objectType.Thing
objectType.Thing
e) Strings and DateTime
using System.Globalization;
OUTPUT:
23/06/2001 17:55:10
date = 23/06/2001 00:00:00, time = 17:55:10.3839296
03/01/2002
03/01/2002
03 January 2002
03 January 2002 12:55
03 January 2002 12:55:47
03/01/2002 12:55
03/01/2002 12:55:47
03 January
Thu, 03 Jan 2002 12:55:47 GMT
2002-01-03T12:55:47
12:55
12:55:47
2002-01-03 12:55:47Z
03 January 2002 12:55:47
03/01/2002
January 2002
03-Jan-02
f) StringBuilder class
class UseSBApp
{
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder("Pineapple");
sb.Replace('e', 'X');
sb.Insert(4, "Banana");
sb.Append("Kiwi");
sb.AppendFormat(", {0}:{1}", 123, 45.6789);
sb.Remove(sb.Length - 3, 3);
Console.WriteLine(sb);
}
}
OutPut:
PinXBananaapplXKiwi, 123:45.6
g) Spliting Strings
class SplitStringApp
{
static void Main(string[] args)
{
string s = "Once Upon A Time In America";
char[] seps = new char[]{' '};
foreach (string ss in s.Split(seps))
Console.WriteLine(ss);
}
}
OutPut:
Once
Upon
A
Time
In
America
3. Implement a C# Program to Find Volume of Cube
and Cuboid Using Delegates.
CUBE:
using System;
public class VolumeOfCube
{
public static void Main()
{
Console.Write("Enter Side: ");
decimal Side = Convert.ToDecimal(Console.ReadLine());
decimal Volume = Side * Side * Side;
Console.WriteLine("Volume of cube=" + Volume);
Console.ReadKey();
}
}
OUTPUT
CUBOID:
using System;
class VolumeaOfCuboid
{
static void Main()
{
float length, width, height;
length = 5;
width = 3;
height = 4;
float volume = height * width * length;
Console.WriteLine("Volume of Cuboid is:" + volume);
Console.ReadKey();
}
}
OUTPUT
Volume of Cuboid is:60
4.Write a Program in C# to demonstrate Operator
overloading.
PROGERAM
// C# program to illustrate the
// unary operator overloading
using System;
namespace Calculator {
class Calculator {
public int number1 , number2;
public Calculator(int num1 , int num2)
{
number1 = num1;
number2 = num2;
}
// Function to perform operation
// By changing sign of integers
public static Calculator operator -(Calculator c1)
{
c1.number1 = -c1.number1;
c1.number2 = -c1.number2;
return c1;
}
// Function to print the numbers
public void Print()
{
Console.WriteLine ("Number1 = " + number1);
Console.WriteLine ("Number2 = " + number2);
}
}
class EntryPoint
{
// Driver Code
static void Main(String []args)
{ // using overloaded - operator
// with the class object
Calculator calc = new Calculator(15, -25);
calc = -calc;
// To display the result
calc.Print();
}
}
}
OUTPUT
Number1 = -15
Number2 = 25
5. Write a program in C# to demonstrate the usage of
object and class.
PROGRAM
using System;
public class Student
{
int id;//data member (also instance variable)
String name;//data member(also instance variable)
public static void Main(string[] args)
{
Student s1 = new Student();//creating an object of Student
s1.id = 101;
s1.name = "Sonoo Jaiswal";
Console.WriteLine(s1.id);
Console.WriteLine(s1.name);
}
}
OUTPUT:
101
Sonoo Jaiswal
It can most commonly be used when you need to confirm password entered by the user at the
registration time. The data is always case sensitive.
REGULAREXPRESSIONVALIDATOR CONTROL
A regular expression is a powerful pattern matching language that can be used to identify
simple and complex characters sequence that would otherwise require writing code to
perform.
Default.aspx Design
CUSTOMVALIDATOR CONTROL
You can solve your purpose with ASP.NET validation control. But if you still don't find
solution you can create your own custom validator control.
The CustomValidator Control can be used on client side and server side. JavaScript is used to
do client validation and you can use any .NET language to do server side validation
.
Source Code
VALIDATION SUMMARY
ASP.NET has provided an additional control that complements the validator controls.
The Validation Summary control is reporting control, which is used by the other validation
controls on a page. You can use this validation control to consolidate errors reporting for all
the validation errors that occur on a page instead of leaving this up to each and every
individual validation control.The validation summary control will collect all the error
messages of all the non-valid controls and put them in a tidy list.
Default.aspx Design
7.Program with ASP.Net by Connecting With SQL.
a.Create Login Form to Enter Into Website.
b. Building Web Form that Displays Data from a
Database.
8. Create a Website Using Master Page Concept in
ASP.Net
PROGRAM
Step 1
Step 2
Project name-> Add-> Add New Item->Visual C#-> Master Page->Write Master Page
Name-> Add.
HomePage.master master page is created.
Note
Go to the design mode and you will see the image, as shown below.
Step 3
Output
9. Create a Webpage to implement Application and
Session States in ASP.Net.
PROGRAM
Using System;
using System.collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
if(Session["user"] != null){
Response.Redirect("~/Welcome.aspx");
}
{
SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionString["connect"].ToString());
con.Open();
string query = "select count(*) from tblUsers where user_name = '"+txtUser.Text+"' and
user_pass = '"+txtPass.Text+"'";
if(output == "1")
{
Session["user"] = txtUser.Text; // Creating a Session | Naming a session | Adding
Value in session variable
Response.Redirect("~/Welcome.aspx");
}
else
{
Response.Write("Login Failed");
}
}
}
10. Create a Website for Online Movie Ticket
Reservation System Using Session Concept.
PROGRAM
// booking system.
Enums :
SEAT_BOOKED,
SEAT_NOT_BOOKED;
Movie_Available,
Movie_NotAvailable;
ENGLISH,
HINDI;
NORMAL,
EXECUTIVE,
PREMIUM,
VIP;
PAID,
UNPAID;
}
class User {
int userId;
String name;
Date dateOfBirth;
String mobNo;
String emailId;
String sex;
class Movie {
int movieId;
int theaterId;
MovieType movieType;
MovieStatus movieStatus;
class Theater {
int theaterId;
String theaterName;
Address address;
List<Movie> movies;
float rating;
class Booking {
int bookingId;
int userId;
int movieId;
List<Movie> bookedSeats;
int amount;
PaymentStatus status_of_payment;
Date booked_date;
Time movie_timing;
class Address {
String city;
String pinCode;
String state;
String streetNo;
String landmark;