qwefqwefefqwfeqwefwqefqwef, Degree thesis for Computing. Acharya Nagarjuna University

qwefqwefefqwfeqwefwqefqwef, Degree thesis for Computing. Acharya Nagarjuna University

PDF (521 KB)
40 pages
1Number of download
64Number of visits
Description
qwefqwefqwwefqwefwqefwqefdfesadfasdfasdfasdfasdf
20 points
Download points needed to download
this document
Download the document
Preview3 pages / 40

This is only a preview

3 shown on 40 pages

Download the document

This is only a preview

3 shown on 40 pages

Download the document

This is only a preview

3 shown on 40 pages

Download the document

This is only a preview

3 shown on 40 pages

Download the document

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

1.Demonstrate Use of Virtual and override key words in C# with a

simple program

using System;

using System.Collections.Generic;

namespace ConsoleApplication1

{

public class Customer

{

public virtual void CustomerType()

{

Console.WriteLine(“I am customer”);

}

}

public class CorporateCustomer:Customer

{

public override void CustomerType()

{

Console.WriteLine(“I am Corporate Customer”);

}

}

public class PersonalCustomer:Customer

{

public override void CustomerType()

{

Console.WriteLine(“I am personal customer”);

}

}

class Program

{

static void Main(string[] args)

{

Customer[] c=new Customer[3];

c[0]=new CorporateCustomer();

c[1]=new PersonalCustomer();

c[2]=new Customer();

foreach(Customer customerobject in c)

{

customerobject.CustomerType();

}

Console.ReadLine();

}

}

}

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

OUTPUT

I am Corporate Customer

I am personal customer

I am customer

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

2.Write a Program in C# to build a class which implements an interface

which already exists.

using System;

usingSystem.Collections.Generic;

usingSystem.Text;

namespace InterfaceClass

{

interface Addition

{

int Add();

}

interface Multiplication

{

int Multiply();

}

class Compute : Addition, Multiplication

{

int x, y;

public Compute(int a, int b)

{

this.x = a;

this.y = b;

}

Public int Add()

{

return (x + y);

}

Public int Multiply()

{

return (x * y);

}

}

Class InterfaceClass

{

static void Main(string[] args)

{

int a, b;

Console.Write("Enter 2 nos:");

a = Convert.ToInt32(Console.ReadLine());

b = Convert.ToInt32(Console.ReadLine());

Compute ob1 = new Compute(a, b);

Console.WriteLine("Addition is:" + ob1.Add());

Console.WriteLine("Multiplication is:" + ob1.Multiply());

Console.ReadLine();

}

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

}

}

OUTPUT

Enter 2 nos :

2

6

Addition is: 8

Multiplication is: 12

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

3. Program to implement delegate

Using System;

Using System.IO;

delegate void delegatewriter(string message);

class delgwriter

{

StreamWriter w;

Public delgwriter(string path)

{

w =File.CreateText(path);

}

Public void display(string msg)

{

w.WriteLine(msg);

}

Public void Flush()

{

w.Flush();

}

Public void Close()

{

w.Close();

}

}

class Test

{

Static delegatewriter delgwri;

Static void display(string s)

{

Console.WriteLine(s);

}

Static void Main(string[]arg)

{

delgwriter x =newdelgwriter("log.txt");

delgwri +=newdelegatewriter(display);

delgwri +=newdelegatewriter(x.display);

delgwri("C");

delgwri("C++");

delgwri("Java");

x.Flush();

x.Close();

Console.Read();

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

}

}

OUTPUT

C

C++

Java

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

4. Program to demonstrate multiple exceptions

Using System;

class Exercise

{

Static void Main()

{

double Num1, Num2;

double Result =0.00;

char op;

try

{

Console.Write("Enter your First Number : ");

Num1 =double.Parse(Console.ReadLine());

Console.Write("Enter an Operator (+, -, * or /): ");

op=char.Parse(Console.ReadLine());

if(op !='+'&& op !='-'&&

op !='*'&& op !='/')

throw new Exception(op.ToString());

Console.Write("Enter your Second Number :");

Num2 =double.Parse(Console.ReadLine());

if(op =='/')

if(Num2 ==0)

throw new DivideByZeroException("Division by zero is not allowed");

Result =Calculator(Num1, Num2, op);

Console.WriteLine("\n{0} {1} {2} = {3}", Num1, op, Num2, Result);

}

catch(FormatException)

{

Console.WriteLine("The number you typed is not valid");

}

catch(DivideByZeroException ex)

{

Console.WriteLine(ex.Message);

}

catch(Exception ex)

{

Console.WriteLine("Operation Error: {0} is not a valid op", ex.Message);

}

Console.Read();

}

Static double Calculator(double v1, double v2, char op)

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

{

double Result =0.00;

switch(op)

{

case'+':

Result = v1 + v2;

break;

case'-':

Result = v1 - v2;

break;

case'*':

Result = v1 * v2;

break;

case'/':

Result = v1 / v2;

break;

}

return Result;

}

}

OUTPUT

1.Enter your First Number : 6

Enter an Operator (+, -, * or /): +

Enter your Second Number :8

6 + 8 = 14

2. Enter your First Number : 6

Enter an Operator (+, -, * or /): *

Enter your Second Number :2

6 * 2 = 12

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

5. Program to implement IComparable interface

Using System;

class Fraction :IComparable

{

int z, n;

public Fraction(int z, int n)

{

this.z= z;this.n= n;

}

public static Fraction operator+(Fraction a, Fraction b)

{

return new Fraction(a.z*b.n+a.n*b.z, a.n*b.n);

}

public static Fraction operator*(Fraction a, Fraction b)

{

return new Fraction(a.z*b.z, a.n*b.n);

}

public int CompareTo(object obj)

{

Fraction f =(Fraction)obj;

if((float)z / n <(float)f.z/f.n)

return -1;

else if((float)z / n >(float)f.z/f.n)

return 1;

else return 0;

}

Public override string ToString()

{

return z +"/"+ n;

}

}

class Test

{

Static void Main(string[] arg)

{

Fraction[] a ={

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

new Fraction(5,2),

new Fraction(29,6),

new Fraction(4,5),

new Fraction(10,8),

new Fraction(34,7)

}

Array.Sort(a);

Console.WriteLine("Implementing the IComparable Interface in Displaying Fractions

: ");

foreach(Fraction f in a)Console.WriteLine(f +" ");

Console.WriteLine();

Console.ReadLine();

}

}

OUTPUT

Implementing the IComparable Interface in Displaying Fractions :

4/5

10/8

5/2

29/6

34/7

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

6. Program to demonstrate Multilevel inheritance

Using System;

Using System.Collections.Generic;

Using System.Linq;

Using System.Text;

namespace Inherit

{

Class inheri: vehicle

{

Public void Noise()

{

Console.WriteLine("All Vehicles Creates Noise !! ");

}

Static void Main(string[] args)

{

Inheri obj=new inheri();

obj.mode();

obj.feature();

obj.Noise();

Console.Read();

}

}

class Mode

{

Public void mode()

{

Console.WriteLine("There are Many Modes of Transport !!");

}

}

class vehicle : Mode

{

Public void feature()

{

Console.WriteLine("They Mainly Help in Travelling !!");

}

}

}

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

OUTPUT

There are Many Modes of Transport !!

They Mainly Help in Travelling !!

All Vehicles Creates Noise !!

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

7. Program to implement Inheritance

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

class Shape

{

public double Width;

public double Height;

public void ShowDim()

{

Console.WriteLine("Width and height are " + Width + " and " + Height);

}

}

class Triangle : Shape

{

public string Style;

public double Area()

{

return Width * Height / 2;

}

public void ShowStyle()

{

Console.WriteLine("Triangle is " + Style);

}

}

class Driver

{

static void Main()

{

Triangle t1=new Triangle();

Triangle t2=new Triangle();

t1.Width =4.0;

t1.Height =4.0;

t1.Style ="isosceles";

t2.Width =8.0;

t2.Height =12.0;

t2.Style ="right";

Console.WriteLine("Info for t1: ");

t1.ShowStyle();

t1.ShowDim();

Console.WriteLine("Area is " + t1.Area());

Console.WriteLine();

Console.WriteLine("Info for t2: ");

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

t2.ShowStyle();

t2.ShowDim();

Console.WriteLine("Area is " + t2.Area());

Console.Readline();

}

}

OUTPUT

Info for t1:

Triangle is isosceles

Width and height are 4 and 4

Area is 8

Info for t2:

Triangle is right

Width and height are 8 and 12

Area is 48

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

8. Practical example of Method Overloading (Compile Time

Polymorphism)

using System;

namespace method_overloading

{

class Program

{

public class Print

{

public void display(string name)

{

Console.WriteLine("Your name is : " + name);

}

public void display(int age, float marks)

{

Console.WriteLine("Your age is : " + age);

Console.WriteLine("Your marks are :" + marks);

}

}

static void Main(string[] args)

{

Print obj = new Print();

obj.display("George");

obj.display(34, 76.50f);

Console.ReadLine();

}

}

}

OUTPUT

Your name is : George

Your age is : 34

Your marks are :76.5

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

9. Using Try, Catch and Finally blocks write a program in C# to

demonstrate error handling.

using System;

usingSystem.Collections.Generic;

usingSystem.Text;

namespaceErrorHandling

{

classErrorHandling

{

staticint m = 10;

staticint n = 0;

static void Division()

{

try

{

int k = m / n;

}

catch (ArgumentException e)

{

Console.WriteLine("Exception caught:" + e.Message);

}

finally

{

Console.WriteLine("Inside division method");

Console.ReadLine();

}

}

static void Main(string[] args)

{

try

{

Division();

}

catch (DivideByZeroException e)

{

Console.WriteLine("Exception caught:" + e.Message);

}

finally

{

Console.WriteLine("inside main method");

Console.ReadLine();

}

}

}

}

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

OUTPUT

Inside division method

Exception caught:Attempted to divide by zero.

inside main method

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

10.Write a Program to illustrate the use of different Properties in C#.

using System;

using System.Collections.Generic;

using System.Text;

namespace properties

{

public class Student

{

Private int usn;

private string percentile;

private string fullName;

public int ID

{

get { return usn; }

set

{

usn = value;

}

}

public string Name

{

get { return fullName; }

set { fullName = value; }

}

public string marks

{

get { return percentile; }

set { percentile = value; }

}

}

class Properties

{

static void Main(string[] args)

{

Student e = new Student();

e.ID = 81;

e.Name = "ABC";

e.marks = "58%";

Console.WriteLine("ID= {0},NAME={1},marks percentile={2}", e.ID, e.Name,

e.marks);

Console.ReadLine();

}

}

}

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

OUTPUT:

ID= 81,NAME=ABC ,marks percentile=58%

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

11. Demonstrate arrays of interface types with a C# program.

using System;

usingSystem.Collections.Generic;

usingSystem.Text;

namespace InterfaceType

{

public interface IShape

{

void Calculate();

void Display();

}

public class Rectangle : IShape

{

private double Area;

private double Length;

private double Breadth;

public Rectangle()

{

this.Length = 0;

this.Breadth = 0;

}

public Rectangle(double l, double b)

{

this.Length = l;

this.Breadth = b;

}

public void Calculate()

{

this.Area = this.Length * this.Breadth;

}

public void Display()

{

Console.WriteLine("Area of Rectangle is : " + this.Area);

}

}

public class Square : IShape

{

private double Area;

private double Side;

public Square()

{

this.Side = 0;

}

public Square(double s)

{

this.Side = s;

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

}

public void Calculate(){

this.Area = this.Side * this.Side;

}

public void Display()

{

Console.WriteLine("Area of Square is : " + this.Area);

}

}

public class Circle : IShape

{

private double Area;

private double Radius;

public Circle()

{

this.Radius = 0;

}

public Circle(double s)

{

this.Radius = s;

}

public void Calculate()

{

this.Area = 3.1416 * this.Radius * this.Radius;

}

public void Display()

{

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

}

}

public class InterfaceType

{

public static void Main(string[] args)

{

IShape[] s = { new Rectangle(10, 20), new Square(30), new Circle(40) };

for (int i = 0; i <s.Length; i++)

{

s[i].Calculate();

s[i].Display();

}

Console.ReadLine();

}

}

}

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

OUTPUT:

Area of Rectangle is : 200

Area of Square is : 900

Area of Circle is : 5026.56

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

12. C# programme to find weather the given number is odd or even

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace check1

{

class Program

{

static void Main(string[] args)

{

int i;

Console.Write("Enter a Number : ");

i = int.Parse(Console.ReadLine());

if (i % 2 == 0)

{

Console.Write("Entered Number is an Even Number");

Console.Read();

}

else

{

Console.Write("Entered Number is an Odd Number");

Console.Read();

}

}

}

}

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

OUTPUT:

Enter a Number : 5

Entered Number is an Odd Number

Enter a Number : 2

Entered Number is an Even Number

BCA VI Sem

VIJAYANAGARA SRI KRISHNADEVARAYA UNIVERSITY, BELLARY

VIJAYANAGAR COLLEGE, HOSPET

PROGRAM NO :

PAGE NO :

13. C# programme to find the simple interest

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace check1

{

class simpleInterest

{

public static void Main(String[] args)

{

double p, r, si,total;

int n;

Console.Write("Enter Principle Amount : ");

p = Convert.ToDouble(Console.ReadLine());

Console.Write("Enter Nmuber of years : ");

n = Convert.ToInt32(Console.ReadLine());

Console.Write("Enter the rate of interest : ");

r = Convert.ToDouble(Console.ReadLine());

si = (p * n * r) / 100;

total = si + p;

Console.WriteLine("Simple Interest : {0}", si);

Console.WriteLine("total amount : {0}", total);

Console.ReadLine();

}

}

}

OUTPUT:

Enter Principle Amount : 1000

Enter Nmuber of years : 3

Enter the rate of interest : 2

Simple Interest : 60

total amount : 1060

comments (0)

no comments were posted

be the one to write the first!

This is only a preview

3 shown on 40 pages

Download the document