0% found this document useful (0 votes)
38 views

Dot Net Print

The program implements operator overloading by overloading the + operator. It defines a Calculator class with an integer property number. It overloads the + operator to add the number properties of two Calculator objects and return a new Calculator object. It then demonstrates adding two Calculator objects and displaying the results.

Uploaded by

Satish Gautam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Dot Net Print

The program implements operator overloading by overloading the + operator. It defines a Calculator class with an integer property number. It overloads the + operator to add the number properties of two Calculator objects and return a new Calculator object. It then demonstrates adding two Calculator objects and displaying the results.

Uploaded by

Satish Gautam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

JANAMAITRI MULTIPLE CAMPUS

Kuleshwor Height, Kathmandu


www.janamaitri.edu.np

Practical Lab Book


Of
Dot Net

Required to fulfillment of for the study of


BCA
A TU affiliated “Bachelor degree in
Computer Application”

NAME: Satish Gautam


LEVEL: Bachelors SEMESTER: Fifth
TU REDG NO: 6-2-263-409-2020
SUBJECT: Dot Net
FACULTY’S NAME: Humanities and social science
Self-Declaration

I Satish Gautam, candidate of fifth semester, hereby declare that the


contents included in the Practical Lab Book is entirely done by myself as
a part of study, None of the portion on the Lab Book in duplicated or
copied from any other source.

I am liable and obliged to all the corrections and suggestions given by


the faculty members, Internal Examiner as well as External Examiner
during the evaluation.

Name: Satish Gautam

PHOTO TU Redg No: 6-2-263-409-2020


Level: Bachelors Semester: Fifth

Internal External
Examiner Examiner
Name: Name:

Signature: Signature:

Date: Date:

1
Rules and Regulation for
Digital / Computer Lab User

All the students must bring a lab book, practical manual


and log file along with them while accessing lab.

Students should not bring their bags or any sort of carriages


while accessing lab.

The entire student must fill the lab log sheet before
accessing lab.

Eating snacks and chewing are restricted during accessing


lab.

Unnecessary talking and gossiping with friends are strictly


restricted with in lab.

All the students must take permission from authorized


person to access Flash Disk / Pen Drives.

JMC Lab Authority

2
Table of Contents

Lab Report Lab Report Contents


Number
1 Write a program to demonstrate the differences between Console
ReadLine() and Console.Read(), Console.Write() and
Console.WriteLine() in C#.
2 Concept on Polymorphism
Write a program to add numbers x, y and z. One function to add x and
y another function to add all three numbers. Print on screen as given
output.
Sum of 5 and 6 = 11
Sum of 5, 6 and 7 = 18
3 Write a program to implement the concept of default constructor,
parameterized constructorand private constructor in C#.
4 Write a program to implement the concept of operatot (+) overloading.
5 Write a concept of multilevel inheritance and multiple inheritance in
C#.
6 Write a program on Method overloading and Method Overriding in C#.

3
Lab 1
Write a program to demonstrate the differences between Console ReadLine()
and Console.Read(), Console.Write() and Console.WriteLine() in C#.

❖ Console.ReadLine()

Source Code:

using System;

namespace Lab1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Input: ");
string input = Console.ReadLine();
Console.WriteLine($"Output: {input}");
Console.ReadKey();
}
}
}

Output:

4
❖ Console.Read()

Source Code:

using System;
namespace lab1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Input: ");
Console.Write("Output: " + Convert.ToChar(Console.Read()));
Console.ReadKey();
}
}
}

Output:

❖ Console.Write()

Source Code:

using System;
namespace lab1
{
class Program
{
static void Main(string[] args)
{
Console.Write("I am students ");
Console.Write("of ");
Console.Write("JMC COllege");
Console.ReadKey();
}
}
}

Output:

5
❖ Console.WriteLine()

Source Code:

using System;
namespace lab1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("I am Students ");
Console.WriteLine("of ");
Console.WriteLine("JMC College");
Console.ReadKey();
Console.ReadKey();
}
}
}

Output:

6
Lab 2
Write a program to add numbers x, y and z. One function to add x and y another
function to add all three numbers. Print on screen as given output.
Sum of 5 and 6 = 11
Sum of 5, 6 and 7 = 18

Source Code:

using System;
namespace lab2
{
class Program
{
public void Add(int x, int y)
{
Console.WriteLine("Sum of {0} and {1} = {2}", x, y, (x + y));
}

public void Add(int x, int y, int z)


{
Console.WriteLine("Sum of {0}, {1} and {2} = {3}", x, y, z, (x + y + z));
}

static void Main(string[] args)


{
Program ob = new Program();
ob.Add(5, 6);
ob.Add(5, 6, 7);
Console.ReadKey();
Console.ReadKey();
}
}
}

Output:

7
Lab 3
Write a program to implement the concept of default constructor, parameterized
constructorand private constructor in C#.

❖ Default Constructor in C#

Source Code:

using System;
namespace DefaultConstractor
{
class addition
{
int a, b;

public addition() {
a = 100;
b = 175;
}

public static void Main()


{
addition obj = new addition();
Console.WriteLine(obj.a);
Console.WriteLine(obj.b);
Console.Read();
}
}
}

Output:

8
❖ Parameterized Constructor in C#

Source Code:

using System;
namespace Constructor
{
class paraconstrctor
{
public int a, b;

public paraconstrctor(int x, int y) {


a = x;
b = y;
}
}

class MainClass
{
static void Main()
{
paraconstrctor v = new paraconstrctor(100, 175);
Console.WriteLine("-----------parameterized constructor example by
vithal wadje---------------");
Console.WriteLine("\t");
Console.WriteLine("value of a=" + v.a);
Console.WriteLine("value of b=" + v.b);
Console.Read();
}
}
}

Output:

9
❖ Private Constructor in C#

Source Code:

using System;
namespace defaultConstractor
{
public class Counter
{
private Counter() {
}

public static int currentview;

public static int visitedCount()


{
return ++currentview;
}
}

class viewCountedetails
{
static void Main()
{
Console.WriteLine("-------Private constructor example by vithal
wadje----------");
Console.WriteLine();
Counter.currentview = 500;
Counter.visitedCount();
Console.WriteLine("Now the view count is: {0}",
Counter.currentview);
Console.ReadLine();
}
}
}

Output:

10
Lab 4
Write a program to implement the concept of operatot (+) overloading.

Source Code:

using System;
namespace lab4
{
namespace BinaryOverload
{
class Calculator
{
public int number = 0;

public Calculator() { }

public Calculator(int n)
{
number = n;
}

public static Calculator operator +(Calculator Calc1, Calculator Calc2)


{
Calculator Calc3 = new Calculator(0);
Calc3.number = Calc2.number + Calc1.number;
return Calc3;
}

public void display()


{
Console.WriteLine("{0}", number);
}

static void Main(string[] args)


{
Calculator num1 = new Calculator(200);
Calculator num2 = new Calculator(40);
Calculator num3 = new Calculator(); Output:
num3 = num1 + num2;
num1.display(); // Displays 200
num2.display(); // Displays 40
num3.display(); // Displays 240
Console.ReadKey();
}
}
}
}

11
Lab 5
Write a concept of multilevel inheritance and multiple inheritance in C#.

[Note: Multiple inheritance doesnot support in Class but use in interface]

❖ Multiple Inheritance

Source Code:

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

namespace MultipleInheritApplication
{
interface calc1
{
int add(int a, int b);
}

interface calc2
{
int sub(int x, int y);
}

interface calc3
{
int mul(int r, int s);
}

interface calc4
{
int div(int c, int d);
}

class Calculation : calc1, calc2, calc3, calc4


{
public int result1;
public int add(int a, int b)
{
return result1 = a + b;
}

public int result2;


public int sub(int x, int y)
{
return result2 = x - y;

12
}

public int result3;


public int mul(int r, int s)
{
return result3 = r * s;
}

public int result4;


public int div(int c, int d)
{
return result4 = c / d;
}
}

class Program
{
static void Main(string[] args)
{
Calculation c = new Calculation();
c.add(8, 2);
c.sub(20, 10);
c.mul(5, 2);
c.div(20, 10);

Console.WriteLine("Multiple Inheritance concept Using Interfaces :\n ");


Console.WriteLine("Addition: " + c.result1);
Console.WriteLine("Subtraction: " + c.result2);
Console.WriteLine("Multiplication :" + c.result3);
Console.WriteLine("Division: " + c.result4);
Console.ReadKey();
}
}
}

Output:

13
❖ Multilevel Inheritance

Source Code:

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

namespace Demo
{
class Son : Father
{
public void DisplayTwo()
{
Console.WriteLine("Son.. ");
}

static void Main(string[] args)


{
Son s = new Son();
s.Display();
s.DisplayOne();
s.DisplayTwo();
Console.Read();
}
}

class Grandfather
{
public void Display()
{
Console.WriteLine("Grandfather...");
}
}

class Father : Grandfather


{
public void DisplayOne() Output:
{
Console.WriteLine("Father...");
}
}
}

14
Lab 6
Write a program on Method overloading and Method Overriding in C#.

❖ Overiding

Source Code:

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

namespace OverridingExample
{
class Subject // Base class
{
public virtual void study() // Base class method
{
Console.WriteLine("Study all the subjects");
}
}

class Mathematics : Subject // Derived class


{
public override void study() // Derived class method
{
base.study(); // Calls the base class method
Console.WriteLine("Study Mathematics");
}
}

class Program
{
// Main method
static void Main(string[] args)
{
Mathematics m = new Mathematics();
m.study();
Console.ReadLine();
}
}
} Output:

15
❖ Overloading

Source Code:

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

namespace OverloadingExample
{
class Demo
{
public int Sum(int x, int y)
{
int value = x + y;
return value;
}

public int Sum(int x, int y, int z)


{
int value = x + y + z;
return value;
}

public static void Main(string[] args) // Main method


{
Demo d = new Demo();
int sum1 = d.Sum(24, 28);
Console.WriteLine("Sum of the two integer values: " + sum1);

int sum2 = d.Sum(10, 20, 30);


Console.WriteLine("Sum of the three integer values: " + sum2);

Console.ReadLine();
}
}
}

Output:

16

You might also like