Académique Documents
Professionnel Documents
Culture Documents
TYIT D 7410
PRACTICAL NO – 1
WORKING WITH BASIC C# AND ASP.NET:
a. Create an application that obtains four int values from the user and displays the
product.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Enter 1st value: ");
int a = int.Parse(Console.ReadLine());
Console.WriteLine("Enter 2nd value: ");
int b = int.Parse(Console.ReadLine());
Console.WriteLine("Enter 3rd value: ");
int c = int.Parse(Console.ReadLine());
Console.WriteLine("Enter 4th value: ");
int d = int.Parse(Console.ReadLine());
int e = a * b * c * d;
Console.WriteLine("Product is: " + e);
Console.ReadLine();
}
}
}
Nandan Tiwari
TYIT D 7410
c. Create an application that receives the (Student Id, Student Name, Course Name,
Date of Birth) information from a set of students. The application should also display
the information of all the students once the data entered.
using System;
using System.Collections.Generic;
Nandan Tiwari
TYIT D 7410
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication14
{
public struct student
{
public string sid;
public string sname;
public string cname;
public string dob;
}
class Class14
{
public static void Main(string [] arr)
{
student[] s=new student[2];
Console.WriteLine("Enter student data: ");
for(int i=0;i<s.Length;i++)
{
Console.WriteLine();
Console.Write("Enter id: ");
s[i].sid=Console.ReadLine();
Console.Write("Enter name: ");
s[i].sname=Console.ReadLine();
Console.Write("Enter course name: ");
s[i].cname=Console.ReadLine();
Console.Write("Enter date of birth: ");
s[i].dob=Console.ReadLine();
}
Console.WriteLine("Student details: ");
for(int i=0;i<s.Length;i++)
{
Console.WriteLine();
Console.WriteLine("Id is: "+s[i].sid);
Console.WriteLine("Name is: "+s[i].sname);
Console.WriteLine("Course name is: "+s[i].cname);
Console.WriteLine("Date of birth is: "+s[i].dob);
}
Console.ReadLine();
}
}
}
Nandan Tiwari
TYIT D 7410
namespace ConsoleApplication14
{
class Class12
{
public static void Main(string [] arr)
{
int a = 0;
int b = 1;
int c;
Console.WriteLine("Enter a number: ");
int num = int.Parse(Console.ReadLine());
Console.WriteLine("Fibonacci series is: ");
Console.WriteLine(a);
Console.WriteLine(b);
for(int i=3;i<num;i++)
{
c = a + b;
Console.WriteLine(c);
a = b;
b = c;
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication14
{
Nandan Tiwari
TYIT D 7410
class Class9
{
public static void Main(string [] arr)
{
Console.WriteLine("Enter a number: ");
int num = int.Parse(Console.ReadLine());
int flag = 0;
for(int i=2;i<num;i++)
{
if(num%i==0)
{
flag = 1;
break;
}
}
if(flag==0)
{
Console.WriteLine("Number is prime");
}
else
{
Console.WriteLine("Number is not prime");
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication14
{
class Class13
Nandan Tiwari
TYIT D 7410
{
public static void Main(string [] arr)
{
char ch = 'A';
switch(ch)
{
case 'A':
case 'a':
case 'E':
case 'e':
case 'I':
case 'i':
case 'O':
case 'o':
case 'U':
case 'u':
Console.WriteLine("It is a vowel");
break;
default:
Console.WriteLine("It is not a vowel");
break;
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication14
{
class Class15
{
Nandan Tiwari
TYIT D 7410
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
public static void Main(string[] args)
Nandan Tiwari
TYIT D 7410
{
int n, m, rev = 0, sum = 0, rem, x;
Console.Write("Enter a number: ");
n = int.Parse(Console.ReadLine());
while (n != 0)
{
rem = n % 10;
rev = rev * 10 + rem;
n /= 10;
}
Console.WriteLine("Reversed Number: " + rev);
PRACTICAL NO – 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Nandan Tiwari
TYIT D 7410
namespace ConsoleApplication3
{
class Class9
{
public static void Main(string[] arr)
{
int fact = 1;
Console.Write("Enter a number: ");
int a = int.Parse(Console.ReadLine());
for (int i = 1; i <= a; i++)
{
fact = fact * i;
}
Console.WriteLine("Factorial is: " + fact);
Console.ReadLine();
}
}
}
i.Function overloading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Class2
{
void add(int a)
Nandan Tiwari
TYIT D 7410
{
Console.WriteLine("Addition is: " + (a + a));
}
void add(int a, int b)
{
Console.WriteLine("Addition of two integers is: " + (a + b));
}
void add(float x, float y)
{
Console.WriteLine("Addition of two floating point numbers is: " + (x + y));
}
public static void Main(string[] arr)
{
Class2 c = new Class2();
c.add(3);
c.add(4, 8);
c.add(8.2f, 6.4f);
Console.ReadLine();
}
}
}
SINGLE HERITANCE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Class3
{
int a = 10;
public void show()
Nandan Tiwari
TYIT D 7410
{
Console.WriteLine("Value of a is: " + a);
}
}
class derived:Class3
{
public void show1()
{
Console.WriteLine("DONE!!!!");
}
public static void Main(string[] arr)
{
derived d = new derived();
d.show();
d.show1();
Console.ReadLine();
}
}
}
MULTILEVEL INHERITANCE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Class4
{
public int id = 101;
}
class A : Class4
{
public string name = "Nandan";
}
class B : A
{
Nandan Tiwari
TYIT D 7410
HIERARCHICAL INHERITANCE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Class5
{
public int a = 5;
public int b = 15;
}
class derived1 : Class5
{
int sum;
public void add()
{
sum = a + b;
Console.WriteLine("Addition is: " + sum);
}
}
class derived2 : Class5
{
int c;
public void mul()
{
Nandan Tiwari
TYIT D 7410
c = a * b;
Console.WriteLine("Multiplication is: " + c);
}
public static void Main(string[] arr)
{
derived1 d1 = new derived1();
d1.add();
derived2 d2 = new derived2();
d2.mul();
Console.ReadLine();
}
}
}
HYBRID INHERITANCE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Class6
{
public int id = 01;
public string city = "MUMBAI";
}
class X : Class6
{
public string name = "Nandan";
}
class Y : X
{
public void show()
{
Console.WriteLine("Id is: " + id);
Console.WriteLine("Name is: " + name);
}
}
class C : Class6
{
public void display()
Nandan Tiwari
TYIT D 7410
{
Console.WriteLine("City is: " + city);
}
public static void Main(string[] arr)
{
Y obj = new Y();
obj.show();
C obj1 = new C();
obj1.display();
Console.ReadLine();
}
}
}
MULTIPLE INHERITANCE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
interface I1
{
void show();
}
interface I2
{
void display();
}
class Class7 : I1, I2
{
public void show()
{
Console.WriteLine("Interface 1");
}
public void display()
{
Console.WriteLine("Interface 2");
}
public static void Main(string[] arr)
{
Class7 obj = new Class7();
Nandan Tiwari
TYIT D 7410
obj.show();
obj.display();
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Class8
{
int a;
int b;
Class8()
{
Console.WriteLine("HELLO!!!!");
}
Class8(int x, int y)
{
a = x;
b = y;
Console.WriteLine("Value of a is: " + a);
Console.WriteLine("Value of b is: " + b);
}
public static void Main(string[] arr)
{
Class8 c1 = new Class8();
Class8 c2 = new Class8(4, 9);
Console.ReadLine();
}
}
Nandan Tiwari
TYIT D 7410
iv. Interfaces
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
interface I1
{
void show();
}
interface I2
{
void display();
}
class Class7 : I1, I2
{
public void show()
{
Console.WriteLine("Interface 1");
}
public void display()
{
Console.WriteLine("Interface 2");
}
public static void Main(string[] arr)
{
Class7 obj = new Class7();
obj.show();
obj.display();
Nandan Tiwari
TYIT D 7410
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication14
{
class Class7
{
public delegate void mydel();
event mydel click;
static void display()
{
Console.WriteLine("Nandan");
}
public static void Main(string [] arr)
{
mydel d = new mydel(display);
Class7 c = new Class7();
c.click += d;
c.click();
Console.ReadKey();
}
}
}
Nandan Tiwari
TYIT D 7410