programming for application development …

45
Department of Information Technology Page 1 PROGRAMMING FOR APPLICATION DEVELOPMENT LABORATORY MANUAL B.TECH (IV YEAR I SEM) (2021-22) DEPARTMENT OF INFORMATION TECHNOLOGY MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY (Autonomous Institution UGC, Govt. of India) Recognized under 2(f) and 12 (B) of UGC ACT 1956 (Affiliated to JNTUH, Hyderabad, Approved by AICTE - Accredited by NBA & NAAC ‘A’ Grade - ISO 9001:2015 Certified) Maisammaguda, Dhulapally (Post Via. Hakimpet), Secunderabad 500100, Telangana State, India

Upload: others

Post on 14-Mar-2022

0 views

Category:

Documents


0 download

TRANSCRIPT

Department of Information Technology Page 1

PROGRAMMING FOR APPLICATION DEVELOPMENT

LABORATORY MANUAL

B.TECH (IV YEAR – I SEM)

(2021-22)

DEPARTMENT OF INFORMATION TECHNOLOGY

MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY

(Autonomous Institution – UGC, Govt. of India) Recognized under 2(f) and 12 (B) of UGC ACT 1956

(Affiliated to JNTUH, Hyderabad, Approved by AICTE - Accredited by NBA & NAAC – ‘A’ Grade - ISO 9001:2015 Certified)

Maisammaguda, Dhulapally (Post Via. Hakimpet), Secunderabad – 500100, Telangana State, India

Department of Information Technology Page 2

DEPARTMENT OF INFORMATION TECHNOLOGY

VISION

To achieve high quality in technical education that provides the skills and attitude to adapt

to the global needs of the Information Technology sector, through academic and research

excellence.

MISSION

To equip the students with the cognizance for problem solving and to improve the teaching

learning pedagogy by using innovative techniques.

To strengthen the knowledge base of the faculty and students with motivation towards

possession of effective academic skills and relevant research experience.

To promote the necessary moral and ethical values among the engineers, for the betterment

of the society.

Department of Information Technology Page 3

PROGRAMME EDUCATIONAL OBJECTIVES (PEOs)

PEO1: PROFESSIONALISM & CITIZENSHIP

To create and sustain a community of learning in which students acquire knowledge and

learn to apply it professionally with due consideration for ethical, ecological and economic

issues.

PEO2: TECHNICAL ACCOMPLISHMENTS

To provide knowledge based services to satisfy the needs of society and the industry by

providing hands on experience in various technologies in core field.

PEO3: INVENTION, INNOVATION AND CREATIVITY

To make the students to design, experiment, analyze, interpret in the core field with the

help of other multi disciplinary concepts wherever applicable.

PEO4: PROFESSIONAL DEVELOPMENT

To educate the students to disseminate research findings with good soft skills and become a

successful entrepreneur

PEO5: HUMAN RESOURCE DEVELOPMENT

To graduate the students in building national capabilities in technology, education and

research.

Department of Information Technology Page 4

PROGRAM SPECIFIC OUTCOMES (PSOs)

After the completion of the course, B. Tech Information Technology, the graduates will have the

following Program Specific Outcomes:

1. Fundamentals and critical knowledge of the Computer System:- Able to Understand the

working principles of the computer System and its components , Apply the knowledge to

build, asses, and analyze the software and hardware aspects of it .

2. The comprehensive and Applicative knowledge of Software Development:

Comprehensive skills of Programming Languages, Software process models,

methodologies, and able to plan, develop, test, analyze, and manage the software and

hardware intensive systems in heterogeneous platforms individually or working in teams.

3. Applications of Computing Domain & Research: Able to use the professional, managerial,

interdisciplinary skill set, and domain specific tools in development processes, identify the

research gaps, and provide innovative solutions to them.

Department of Information Technology Page 5

PROGRAM OUTCOMES (POs)

Engineering Graduates should possess the following: 1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering

fundamentals, and an engineering specialization to the solution of complex engineering problems.

2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and engineering sciences.

3. Design / development of solutions: Design solutions for complex engineering problems and design system components or processes that meet the specified needs with appropriate consideration for the public health and safety, and the cultural, societal, and environmental considerations.

4. Conduct investigations of complex problems: Use research-based knowledge and research methods including design of experiments, analysis and interpretation of data, and synthesis of the information to provide valid conclusions.

5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering and IT tools including prediction and modeling to complex engineering activities with an understanding of the limitations.

6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineering practice.

7. Environment and sustainability: Understand the impact of the professional engineering solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable development.

8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the engineering practice.

9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse teams, and in multidisciplinary settings.

10. Communication: Communicate effectively on complex engineering activities with the engineering community and with society at large, such as, being able to comprehend and write effective reports and design documentation, make effective presentations, and give and receive clear instructions.

11. Project management and finance: Demonstrate knowledge and understanding of the engineering and management principles and apply these to one’s own work, as a member and leader in a team, to manage projects and in multi disciplinary environments.

12. Life- long learning: Recognize the need for, and have the preparation and ability to engage in independent and life-long learning in the broadest context of technological change.

Department of Information Technology Page 6

MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY Maisammaguda, Dhulapally Post, Via Hakimpet, Secunderabad – 500100

DEPARTMENT OF INFORMATION TECHNOLOGY

GENERAL LABORATORY INSTRUCTIONS

1. Students are advised to come to the laboratory at least 5 minutes before (to the starting time),

those who come after 5 minutes will not be allowed into the lab.

2. Plan your task properly much before to the commencement, come prepared to the lab with the

synopsis / program / experiment details.

3. Student should enter into the laboratory with:

a. Laboratory observation notes with all the details (Problem statement, Aim, Algorithm,

Procedure, Program, Expected Output, etc.,) filled in for the lab session.

b. Laboratory Record updated up to the last session experiments and other utensils (if any) needed

in the lab.

c. Proper Dress code and Identity card.

4. Sign in the laboratory login register, write the TIME-IN, and occupy the computer system

allotted to you by the faculty.

5. Execute your task in the laboratory, and record the results / output in the lab observation note

book, and get certified by the concerned faculty.

6. All the students should be polite and cooperative with the laboratory staff, must maintain the

discipline and decency in the laboratory.

7. Computer labs are established with sophisticated and high end branded systems, which should

be utilized properly.

8. Students / Faculty must keep their mobile phones in SWITCHED OFF mode during the lab

sessions. Misuse of the equipment, misbehaviors with the staff and systems etc., will attract

severe punishment.

9. Students must take the permission of the faculty in case of any urgency to go out; if anybody

found loitering outside the lab / class without permission during working hours will be treated

seriously and punished appropriately.

10. Students should LOG OFF/ SHUT DOWN the computer system before he/she leaves the lab

after completing the task (experiment) in all aspects. He/she must ensure the system / seat is

kept properly.

HEAD OF THE DEPARTMENT PRINCIPAL

Department of Information Technology Page 7

INDEX

S.No Name of the program Page no

1. a) Learning to use Visual Studio 2019 IDE Building Console

Application Project 9

2.

a) Write a Program to generate the factorial of a given number

by using command line argument

18

b) Write a Program to generate Fibonacci series 19

c) Write a program to generate the temperature conversion 20

3.

a) Write a program to generate Pascal Triangle . 21

b) Write a program which asks for a symbol and a width, and

displays a triangle of that width, using that number for the

inner symbol

22

4.

a) Write a program to find the second highest value in an array 23

b) Write a program that at accept an array and a number to be

searched in an array if found display proper message and its

position in a array

25

5. a)Write a console program to develop tic-tac toe game 26

b)Create a function named "Change Char" to modify a letter in

a certain position (0 based) of a

string,replacingitwithadifferentletterex:ChangeChar(―crush‖,2

,‗a‗)

29

6. a)Create a base class, Telephone, and derive a class Electronic

Phone from it. In Telephone, create a protected string member

phone type, and a public method Ring( ) that outputs a text

message like this: "Ringing the ." In Electronic Phone, the

constructor should set the phone type to "Digital." In the Run( )

method, call Ring( ) on the Electronic Phone to test the

inheritance.

30

b) Extend above Exercise to illustrate a polymorphic method.

Have the derived class override the Ring( ) method to display a

different message

31

c) Change the Telephone class to abstract, and make Ring( ) an

abstract method. Derive two new classes from Telephone:

Digital Phone and Talking Phone. Each derived class should

set the phone type, and override the Ring( )method.

31

7. a) Write a program to create interface named test. In this

interface the member function is square. Implement this

interface in arithmetic class. Create one new class called To

Test Int in this class use the object of arithmetic class.

32

b) Create an outer class with a function display, again create

another class inside the outer class named inner with a function

called display and call the two functions in the main class.

33

8. a)Write a program for example of try and catch block. In this

check whether the given array size is negative or not.

34

b) Write a program to illustrate usage of try multiple catch with

finally clause

35

c) Write a program for creation of user defined exception to

show whether candidate is eligible to caste vote.

36

Department of Information Technology Page 8

9. a) Create a console application that displays current date a time

for 10 times with the time interval of 2 seconds(use

sleep()method

37

b) Write a program that demonstrates a high-priority thread

using Sleep to give lower priority threads a chance to run.

38

10. a) Create a console application to implement delegate. Create a

delegate called strMyDel that takes one string parameter and

returns a string. create a class named Test Delegate that

contains two non-static methods space() and reverse() having

following signature: String Space(String str); space between

input characters String Reverse(String str); - reverse the given

string

39

b) Create a console application to get two integer numbers

from user and perform addition and multiplication on the input

numbers. use the concept of Multi Cast Event

40

11. a) Create a console application to deploy on global assemble

cache(usinggacutil)

41

b) Create a bank namespace with various classes (Saving ,

Current) and implement the namespace in another application

42

12. a) Create a program to ask the user for data about books (title,

author, gender and summary) and store them in a

SQLSERVER database

43

b) Write a program to update books details using sql

procedures

44

Department of Information Technology Page 9

PAD LAB 2021-2022

WEEK-1: DATE:

a) Learning to use Visual Studio 2019 IDE Building Console Application Project

Step 1 - Make sure your computer is ready for Visual Studio

Before you begin installing Visual Studio:

1. Check the system requirements. These requirements help you know whether your

computer supports Visual Studio 2019.

2. Apply the latest Windows updates. These updates ensure that your computer has both

the latest security updates and the required system components for Visual Studio.

3. Reboot. The reboot ensures that any pending installs or updates don't hinder the Visual

Studio install.

4. Free up space. Remove unneeded files and applications from your %SystemDrive% by,

for example, running the Disk Cleanup app.

Step 2 - Download Visual Studio

Next, download the Visual Studio bootstrapper file.

To do so, choose the following button, choose the edition of Visual Studio that you want,

choose Save, and then choose Open folder.

Step 3 - Install the Visual Studio installer

Run the bootstrapper file to install the Visual Studio Installer. This new lightweight installer

includes everything you need to both install and customize Visual Studio.

1. From your Downloads folder, double-click the bootstrapper that matches or is similar

to one of the following files:

o vs_community.exe for Visual Studio Community

o vs_professional.exe for Visual Studio Professional

o vs_enterprise.exe for Visual Studio Enterprise

If you receive a User Account Control notice, choose Yes.

2. We'll ask you to acknowledge the Microsoft License Terms and the Microsoft Privacy

Statement. Choose Continue.

Department of Information Technology Page 10

PAD LAB 2021-2022

Step 4 - Choose workloads

After the installer is installed, you can use it to customize your installation by selecting the

feature sets—or workloads—that you want. Here's how.

1. Find the workload you want in the Visual Studio Installer.

For example, choose the "ASP.NET and web development" workload. It comes with

the default core editor, which includes basic code editing support for over 20

languages, the ability to open and edit code from any folder without requiring a project,

and integrated source code control.

2. After you choose the workload(s) you want, choose Install.

Next, status screens appear that show the progress of your Visual Studio installation.

Department of Information Technology Page 11

PAD LAB 2021-2022

Tip

At any time after installation, you can install workloads or components that you didn't install

initially. If you have Visual Studio open, go to Tools > Get Tools and Features... which

opens the Visual Studio Installer. Or, open Visual Studio Installer from the Start menu.

From there, you can choose the workloads or components that you wish to install. Then,

choose Modify.

Step 5 - Choose individual components (Optional)

If you don't want to use the Workloads feature to customize your Visual Studio installation,

or you want to add more components than a workload installs, you can do so by installing or

adding individual components from the Individual components tab. Choose what you want,

and then follow the prompts.

Step 6 - Install language packs (Optional)

By default, the installer program tries to match the language of the operating system when it

runs for the first time. To install Visual Studio in a language of your choosing, choose

the Language packs tab from the Visual Studio Installer, and then follow the prompts.

Department of Information Technology Page 12

PAD LAB 2021-2022

Change the installer language from the command line

Another way that you can change the default language is by running the installer from the

command line. For example, you can force the installer to run in English by using the

following command: vs_installer.exe --locale en-US. The installer will remember this setting

when it is run the next time. The installer supports the following language tokens: zh-cn, zh-

tw, cs-cz, en-us, es-es, fr-fr, de-de, it-it, ja-jp, ko-kr, pl-pl, pt-br, ru-ru, and tr-tr.

Step 7 - Select the installation location (Optional)

You can reduce the installation footprint of Visual Studio on your system drive. You can

choose to move the download cache, shared components, SDKs, and tools to different drives,

and keep Visual Studio on the drive that runs it the fastest.

Important

You can select a different drive only when you first install Visual Studio. If you've already

installed it and want to change drives, you must uninstall Visual Studio and then reinstall it.

Step 8 - Start developing

1. After Visual Studio installation is complete, choose the Launch button to get started

developing with Visual Studio.

2. On the start window, choose Create a new project.

3. In the search box, enter the type of app you want to create to see a list of available

templates. The list of templates depends on the workload(s) that you chose during

installation. To see different templates, choose different workloads.

Department of Information Technology Page 13

PAD LAB 2021-2022

You can also filter your search for a specific programming language by using

the Language drop-down list. You can filter by using the Platform list and the Project

type list, too.

4. Visual Studio opens your new project, and you're ready to code!

Welcome to the Visual Studio IDE

The Visual Studio integrated development environment is a creative launching pad that you

can use to edit, debug, and build code, and then publish an app. An integrated development

environment (IDE) is a feature-rich program that can be used for many aspects of software

development. Over and above the standard editor and debugger that most IDEs provide,

Visual Studio includes compilers, code completion tools, graphical designers, and many more

features to ease the software development process.

Visual Studio to create your first C# console app

Create a project

First, you'll create a C# application project. The project type comes with all the template files

you'll need, before you've even added anything!

1. Open Visual Studio.

2. On the start window, choose Create a new project.

Department of Information Technology Page 14

PAD LAB 2021-2022

3. On the Create a new project window, enter or type console in the search box. Next,

choose C# from the Language list, and then choose Windows from the Platform list.

After you apply the language and platform filters, choose the Console App (.NET

Core) template, and then choose Next.

Department of Information Technology Page 15

PAD LAB 2021-2022

4. In the Configure your new project window, type or enter HelloWorld in the Project

name box. Then, choose Create.

Visual Studio opens your new project.

Create the application

Visual Studio includes default "Hello World" code in your project.

(To do so, it calls the WriteLine method to display the literal string "Hello World!" in the

console window.)

Department of Information Technology Page 16

PAD LAB 2021-2022

If you press F5, you can run the program in Debug mode. However, the console window is

visible only for a moment before it closes.

(This behavior happens because the Main method terminates after its single statement

executes, and so the application ends.)

Add some code

Let's add some code to pause the application so that the console window doesn't close until

you press ENTER.

1. Add the following code immediately after the call to the WriteLine method:

C#Copy

Console.ReadLine();

2. Verify that it looks like this in the code editor:

Run the application 1. Choose the HelloWorld button on the toolbar to run the application in Debug mode.

(Or, you can press F5.)

2. View your app in the console window.

Department of Information Technology Page 17

PAD LAB 2021-2022

Close the application

1. Press ENTER to close the console window.

2. Close the Output pane in Visual Studio.

3. Close Visual Studio.

Signature of the Faculty

Department of Information Technology Page 18

PAD LAB 2021-2022

WEEK-2: DATE:

a) Write a Program to generate the factorial of a given number by using command line

argument

using System;

namespace labprograms

{

class factorial

{

static void Main (String [] args)

{

int n = Convert.ToInt32(args[0]);

int n1 = n;

int fact=1;

for(int i=n;n>0;n--)

{

fact = fact * n;

}

Console.WriteLine("the factorial of " + n1 + ":" + fact);

Console.ReadLine();

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 19

PAD LAB 2021-2022

b) Write a Program to generate Fibonacci series

using System;

namespace labprogarms

{

class fib

{

static void Main()

{

int n1 = 0, n2 = 1, n3, i;

Console.WriteLine("enter the number");

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

Console.Write(n1 + " " + n2 + " "); //printing 0 and 1

for (i = 2; i < n; ++i) //loop starts from 2 because 0 and 1 are already printed

{

n3 = n1 + n2;

Console.Write(n3 + " ");

n1 = n2;

n2 = n3;

}

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 20

PAD LAB 2021-2022

c) Implement a program to generate the temperature conversion

using System;

using System.Collections.Generic;

using System.Text;

namespace labprograms

{

class Temp

{

static void Main()

{

int celsius, faren;

Console.WriteLine("Enter the Temperature in Celsius(°C) : ");

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

faren = (celsius * 9) / 5 + 32;

Console.WriteLine("0Temperature in Fahrenheit is(°F) : " + faren);

Console.ReadLine();

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 21

PAD LAB 2021-2022

WEEK-3: DATE:

a) Write a program to generate Pascal Triangle

using System;

using System.Collections.Generic;

using System.Text;

namespace PAD_lab_programs

{

class week3a

{

static void Main(string[] args)

{

System.Console.WriteLine("Pascal Triangle Program");

System.Console.Write("Enter the number of rows: ");

string input = System.Console.ReadLine();

int n = Convert.ToInt32(input);

for (int y = 0; y < n; y++)

{

int c = 1;

for (int q = 0; q < n - y; q++)

{

System.Console.Write(" ");

}

for (int x = 0; x <= y; x++)

{

System.Console.Write(" {0} ", c);

c = c * (y - x) / (x + 1);

}

System.Console.WriteLine();

System.Console.WriteLine();

}

System.Console.WriteLine();

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 22

PAD LAB 2021-2022

b) Write a program which asks for a symbol and a width, and displays a triangle of that

width, using that number for the inner symbol

using System;

using System.Collections.Generic;

using System.Text;

namespace PAD_lab_programs

{

class Week3b

{

public static void Main()

{

Console.Write("Input a number: ");

int num = Convert.ToInt32(Console.ReadLine());

Console.Write("Input the desired width: ");

int width = Convert.ToInt32(Console.ReadLine());

int height = width;

for (int row = 0; row < height; row++)

{

for (int column = 0; column < width; column++)

{

Console.Write(num);

}

Console.WriteLine();

width--;

}

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 23

PAD LAB 2021-2022

WEEK-4: DATE:

a) Write a program to find the second highest value in an array

using System;

using System.Collections.Generic;

using System.Text;

namespace PAD_lab_programs

{

class Week4a

{

public static void Main()

{

int n, i, j = 0, lrg, lrg2nd;

int[] arr1 = new int[50];

Console.Write("\n\nFind the second largest element in an array :\n");

Console.Write("-----------------------------------------\n");

Console.Write("Input the size of array : ");

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

/* Stored values into the array*/

Console.Write("Input {0} elements in the array :\n", n);

for (i = 0; i < n; i++)

{

Console.Write("element - {0} : ", i);

arr1[i] = Convert.ToInt32(Console.ReadLine());

}

/* find location of the largest element in the array */

lrg = 0;

for (i = 0; i < n; i++)

{

if (lrg < arr1[i])

{

lrg = arr1[i];

j = i;

}

}

/* ignore the largest element and find the 2nd largest element in the array */

lrg2nd = 0;

for (i = 0; i < n; i++)

{

Department of Information Technology Page 24

PAD LAB 2021-2022

if (i == j)

{

i++; /* ignoring the largest element */

// i--;

}

else

{

if (lrg2nd < arr1[i])

{

lrg2nd = arr1[i];

}

}

}

Console.Write("The Second largest element in the array is : {0} \n\n", lrg2nd);

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 25

PAD LAB 2021-2022

b) Implement a program that at accept an array and a number to be searched in an array

if found display proper message and its position in a array

using System;

using System.Collections.Generic;

using System.Text;

namespace PAD_lab_programs

{

class week4b

{

public static void Main()

{

int[] arr1 = new int[20];

int n, i,flag=0;

Console.WriteLine("enter the size of the array");

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

Console.Write("Input {0} elements in the array :\n", n);

for (i = 0; i < n; i++)

{

Console.Write("element - {0} : ", i);

arr1[i] = Convert.ToInt32(Console.ReadLine());

}

Console.WriteLine("enter the number to be searched");

int key = Convert.ToInt32(Console.ReadLine());

for (i=0;i<n;i++)

{

if(arr1[i]==key)

{

flag = 1;

break;

}

}

if (flag == 1)

Console.WriteLine("element is found at location" + (i+1));

else

Console.WriteLine("element not found");

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 26

PAD LAB 2021-2022

WEEK-5: DATE:

a) Write a console program to develop tic-tac toe game

using System;

using System.Collections.Generic;

using System.Text;

namespace lab_programs

{

classTTT

{

char[] square = { 'o', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

int checkwin()

{

if (square[1] == square[2] && square[2] == square[3])

return 1;

elseif (square[4] == square[5] && square[5] == square[6])

return 1;

elseif (square[7] == square[8] && square[8] == square[9])

return 1;

elseif (square[1] == square[4] && square[4] == square[7])

return 1;

elseif (square[2] == square[5] && square[5] == square[8])

return 1;

elseif (square[3] == square[6] && square[6] == square[9])

return 1;

elseif (square[1] == square[5] && square[5] == square[9])

return 1;

elseif (square[3] == square[5] && square[5] == square[7])

return 1;

elseif (square[1] != '1'&& square[2] != '2'&& square[3] != '3'&&

square[4] != '4'&& square[5] != '5'&& square[6] != '6'&& square[7]

!= '7'&& square[8] != '8'&& square[9] != '9')

return 0;

else

return -1;

}

void board()

{

Console.WriteLine("\n\n\tTic Tac Toe\n\n");

Console.WriteLine("Player 1 (X) - Player 2 (O)\n\n\n");

Console.WriteLine(" | | \n");

Console.WriteLine(" {0} | {1} | {2} \n", square[1], square[2], square[3]);

Console.WriteLine("_____|_____|_____\n");

Console.WriteLine(" | | \n");

Console.WriteLine(" {0} | {1} | {2} \n", square[4], square[5], square[6]);

Console.WriteLine("_____|_____|_____\n");

Department of Information Technology Page 27

PAD LAB 2021-2022

Console.WriteLine(" | | \n");

Console.WriteLine(" {0} | {1} | {2} \n", square[7], square[8], square[9]);

Console.WriteLine(" | | \n\n");

}

int player = 1,choice;

char mark;

staticvoid Main()

{

int i;

TTT t = new TTT();

do

{

t.board();

if (t.player % 2 == 1)

t.player = 1;

else

t.player = 2;

Console.WriteLine("Player {0}, enter a number ", t.player);

t.choice = Int32.Parse(Console.ReadLine());

if (t.player == 1)

t.mark = 'X';

else

t.mark = 'O';

if (t.choice == 1 && t.square[1] == '1')

t.square[1] = t.mark;

elseif (t.choice == 2 && t.square[2] == '2')

t.square[2] = t.mark;

elseif (t.choice == 3 && t.square[3] == '3')

t.square[3] = t.mark;

elseif (t.choice == 4 && t.square[4] == '4')

t.square[4] = t.mark;

elseif (t.choice == 5 && t.square[5] == '5')

t.square[5] = t.mark;

elseif (t.choice == 6 && t.square[6] == '6')

t.square[6] = t.mark;

elseif (t.choice == 7 && t.square[7] == '7')

t.square[7] = t.mark;

elseif (t.choice == 8 && t.square[8] == '8')

t.square[8] = t.mark;

elseif (t.choice == 9 && t.square[9] == '9')

t.square[9] = t.mark;

else

{

Console.WriteLine("Invalid move ");

t.player--;

}

i = t.checkwin();

t.player++;

} while (i == -1);

Department of Information Technology Page 28

PAD LAB 2021-2022

t. board();

if (i == 1)

Console.WriteLine("==> player {0} win", --t.player);

else

Console.WriteLine("==>\aGame draw");

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 29

PAD LAB 2021-2022

b) Create a function named "ChangeChar" to modify a letter in a certain position (0

based) of a string, replacing it with a different letter ex: ChangeChar(―crush‖,2,‘a‘)

using System;

using System.Collections.Generic;

using System.Text;

namespace lab_programs

{

class ChangChar

{

public static void ChangeChar(ref string text, int position, char letter)

{

text = text.Remove(position, 1);

text = text.Insert(position, letter.ToString());

}

public static void Main()

{

string sentence = "Tomato";

Console.WriteLine("The string is {0}", sentence);

ChangeChar(ref sentence, 5, 'a');

Console.WriteLine("The modified string is {0}", sentence);

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 30

PAD LAB 2021-2022

WEEK-6: DATE:

a) Create a base class, Telephone, and derive a class ElectronicPhone from it. In

Telephone, create a protected string member phonetype, and a public method Ring( )

that outputs a text message like this: "Ringing the ." In ElectronicPhone, the

constructor should set the phonetype to "Digital." In the Run( ) method, call Ring( )

on the ElectronicPhone to test the inheritance.

using System;

using System.Collections.Generic;

using System.Text;

namespace PAD_lab_programs

{

class telephone

{

protected string phonetype;

public void ring()

{

Console.WriteLine("ringing the {0} phone ...", phonetype);

}

}

class electronicphone : telephone

{

public electronicphone()

{

phonetype = "digital";

}

public void run()

{

ring();

}

}

class Test

{

static void Main()

{

electronicphone ep = new electronicphone();

ep.run();

Console.ReadKey();

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 31

PAD LAB 2021-2022

b) Extend above Exercise to illustrate a polymorphic method. Have the derived class

override the Ring( ) method to display a different message

using System;

using System.Collections.Generic;

using System.Text;

namespace PAD_lab_programs

{

class telephone1

{

protected string phonetype;

public virtual void ring()

{

Console.WriteLine("ringing the {0} ...", phonetype);

}

}

class electronicphone1 : telephone1

{

public electronicphone1()

{

phonetype = "digital";

}

public void run()

{

ring();

}

public override void ring()

{

Console.WriteLine("the {0} phone is using a different ring-tone ...", phonetype);

}

}

class Test1

{

static void Main()

{

electronicphone1 ep = new electronicphone1();

ep.run();

Console.ReadKey();

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 32

PAD LAB 2021-2022

WEEK-7: DATE:

a) Write a program to create interface named test. In this interface the member function

is square. Implement this interface in arithmetic class. Create one new class called To

Test Int in this class use the object of arithmetic class.

namespace PAD_lab_programs

{

public interface Test

{

public int square(int a);

}

class arithmetic implements Test

{

int s = 0;

public int square(int b)

{

Console.WriteLine (―Inside arithmetic class – implemented method square‖);

Console.WriteLine (―Square of ― + ― is ―+s);

return s;

}

void armeth()

{

Console.WriteLine (―Inside method of class Arithmetic‖);

}

}

class ToTestInt

{

public static void Main(String a[])

{

Console.WriteLine (―calling from ToTestInt class main method‖);

Test t = new arithmetic();

Console.WriteLine (―==============================‖);

Console.WriteLine (―created object of test interface – reference Arithmetic class ―);

Console.WriteLine (―Hence Arithmetic class method square called‖);

Console.WriteLine (―This object cannot call armeth method of Arithmetic class‖);

Console.WriteLine (―=================================‖);

t.square(10);

Console.WriteLine (―=================================‖);

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 33

PAD LAB 2021-2022

b) Create an outer class with a function display, again create another class inside the

outer class named inner with a function called display and call the two functions in

the main class.

class Outer{

String so = (―This is Outer Class‖);

void display()

{

Console.WriteLine (so);

}

void test(){

Inner inner = new Inner();

inner.display();

}

//this is an inner class

class Inner{

String si =(―This is inner Class‖);

void display(){

Console.WriteLine (si);

}

}

}

class InnerClassDemo{

public static void Main(String args[]){

Outer outer = new Outer();

outer.display();

outer.test();

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 34

PAD LAB 2021-2022

WEEK-8: DATE:

a) Write a program for example of try and catch block. In this check whether the given

array size is negative or not.

namespace PAD_lab_programs

{

classClass7a

{

public static void Main(String[] args)

{

int asize; ;

try

{

Console.WriteLine("enter array size-positive / negative");

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

if (asize < 0)

thrownew ArgumentOutOfRangeException(" negative array size exception");

else

Console.WriteLine(" array sixe is positive number");

}

catch (Exception e)

{

Console.WriteLine(e.Message);

}

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 35

PAD LAB 2021-2022

b) Write a program to illustrate usage of try multiple catch with finally clause

using System;

using System.Collections.Generic;

using System.Text;

namespace PAD_lab_programs

{

class Class7b

{

static void Main()

{

int[] number = { 8, 17, 24, 5, 25 };

int[] divisor = { 2, 0, 0, 5 };

// --------- try block ---------

for (int j = 0; j < number.Length; j++)

// Here this block raises two different types of exception, i.e. divideByZeroException

// and IndexOutOfRangeException

try

{

Console.WriteLine("Number: " + number[j]);

Console.WriteLine("Divisor: " + divisor[j]);

Console.WriteLine("Quotient: " + number[j] / divisor[j]);

}

// Catch block 1 This Catch block is for handling DivideByZeroException

catch (DivideByZeroException)

{

Console.WriteLine("Not possible to Divide by zero");

}

// Catch block 2 This Catch block is for handling IndexOutOfRangeException

catch (IndexOutOfRangeException)

{

Console.WriteLine("Index is Out of Range");

}

finally

{

Console.WriteLine("finally block");

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 36

PAD LAB 2021-2022

c) Write a program for creation of user defined exception to show whether candidate is

eligible to caste vote.

using System;

using System.Collections.Generic;

using System.Text;

namespace PAD_lab_programs

{

publicclassInvalidAgeException : Exception

{

publicInvalidAgeException(String message)

: base(message)

{

}

}

publicclassTestUserDefinedException

{

staticvoid validate(int age)

{

if (age < 18)

{

thrownew InvalidAgeException("Sorry, Age must be greater than 18");

}

}

publicstaticvoid Main(string[] args)

{

try

{

validate(12);

}

catch (InvalidAgeException e) { Console.WriteLine(e.Message); }

finally

{

Console.ReadLine();

}

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 37

PAD LAB 2021-2022

WEEK-9: DATE:

a) Create a console application that displays current date a time for 10 times with the

time interval of 2 seconds use sleep() method

using System;

using System.Threading;

namespace PAD_lab_programs

{

class MyThread

{

public void Thread1()

{

for (int i = 0; i < 10; i++)

{

Console.WriteLine(i);

Thread.Sleep(200);

}

}

}

public class ThreadExample

{

public static void Main()

{

MyThread mt = new MyThread();

Thread t1 = new Thread(new ThreadStart(mt.Thread1));

Thread t2 = new Thread(new ThreadStart(mt.Thread1));

t1.Start();

t2.Start();

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 38

PAD LAB 2021-2022

b) Write a program that demonstrates a high-priority thread using Sleep to give lower

priority threads a chance to run.

using System;

using System.Threading;

namespace PAD_lab_programs

{

classClass8b

{

staticpublicvoid Main()

{

// Creating and initializing threads

Thread T1 = new Thread(work);

Thread T2 = new Thread(work);

Thread T3 = new Thread(work);

// Set the priority of threads

T2.Priority = ThreadPriority.Highest;

T3.Priority = ThreadPriority.BelowNormal;

T1.Start();

T2.Start();

T3.Start();

// Display the priority of threads

Console.WriteLine("The priority of T1 is: {0}", T1.Priority);

Console.WriteLine("The priority of T2 is: {0}", T2.Priority);

Console.WriteLine("The priority of T3 is: {0}", T3.Priority);

}

publicstaticvoid work()

{

// Sleep for 1 second

Thread.Sleep(1000);

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 39

PAD LAB 2021-2022

WEEK-10: DATE:

a) Create a console application to implement delegate.Create a delegate called strMyDel

that takes one string parameter and returns a string.create a class named TestDelegate

that contains two non-static methods space() and reverse() having following

signature:String Space(String str); space between input characters String

Reverse(String str); - reverse the given string

using System;

namespace lab_programs

{

public delegate string strmydel(string mystr);

//public delegate void strmydel1(string mystr);

class Testdelegate

{

public string space(string mystr)

{

mystr = mystr + "";

return mystr;

}

public string reverse(string mystr)

{

string rev = "";

rev = "";

Console.WriteLine("String is {0}", mystr);

int len;

len = mystr.Length - 1;

while (len >= 0)

{

rev = rev + mystr[len];

len--;

}

return rev;

}

static void Main()

{

string str, str1;

Console.WriteLine("enter a string");

str = Console.ReadLine();

Testdelegate t = new Testdelegate();

strmydel s = t.space;

str1 = s.Invoke(str);

Console.WriteLine("string after padding a space at the end" + str1);

strmydel s1 = t.reverse;

str1 = s1.Invoke(str);

Console.WriteLine(" after reversing the string" + str1);

}

} }

Department of Information Technology Page 40

PAD LAB 2021-2022

b) Implement a console application to get two integer numbers from user and perform

addition and multiplication on the input numbers. use the concept of MultiCastdelegates

using System;

using System.Collections.Generic;

using System.Text;

namespace lab_programs

{

delegate void dele(int a, int b);

public class Oper

{

public static void Add(int a, int b)

{

Console.WriteLine("{0} + {1} = {2}", a, b, a + b);

}

public static void Sub(int a, int b)

{

Console.WriteLine("{0} - {1} = {2}", a, b, a - b);

}

}

public class program

{

static void Main()

{

dele del = new dele(Oper.Add);

del += new dele(Oper.Sub);

del(4, 2);

del -= new dele(Oper.Sub);

del(1, 9);

Console.Read();

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 41

PAD LAB 2021-2022

WEEK-11: DATE:

a) Create a console application to deploy on global assemble cache(using gacutil)

Steps for creating a multifile assembly:

Open visualstudio->create a new project-> select class library->next->give some

name(mydll)->create some method under a class without main->project tab-> projectname

properties->signing->sign the assembly->choose a strong name key file->new->give some

file name->ok->build

Now goto developer command prompt(signin as administrator)->

C:\ cd (give the path where the .dll file is present )\gacutil -i mydll.dll

Open visualstudio->create a new project-> select console application->next->give some

name(mydll)-> right click solution->add->project reference>browse->c:->windows-

>Microsoft .net->assembly->GAC_MSIL->select mydll->mydll.dll

Now, we can use the method declared in .dll file

namespace ClassLibrary

{

public class myClass

{

public string myFunction(string name)

{

return "Hello : " + name;

}

}

Using System

using ClassLibrary;

namespace ConsoleAPP

{

class Program

{

static void Main(string[] args)

{

myClass obj = new myClass();

Console.WriteLine(obj.myFunction("Sourav"));

Console.ReadLine();

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 42

PAD LAB 2021-2022

b) Create a bank namespace with various classes (Saving , Current) and implement the

namespace in another application.

using System;

namespace first_space

{

class namespace_cl

{

public void Savings()

{

Console.WriteLine("Inside savings account in first_space");

}

}

}

namespace second_space

{

class namespace_cl

{

public void current ()

{

Console.WriteLine("Inside current account in second_space");

}

}

}

class TestClass

{

static void Main(string[] args)

{

first_space.namespace_cl fc = new first_space.namespace_cl();

second_space.namespace_cl sc = new second_space.namespace_cl();

fc.Savings();

sc.current();

Console.ReadKey();

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 43

PAD LAB 2021-2022

WEEK-12: DATE:

a) Create a program to ask the user for data about books (title, author, gender and

summary) and store them in a SQLSERVER database

using System;

using System.Data;

using System.Data.SqlClient;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace SqlTest_CSharp

{

class Program

{

static void Main(string[] args)

{

using (SqlConnection conn = new SqlConnection())

{

conn.ConnectionString = "Server=[server_name];

Database=[database_name];

Trusted_Connection=true";

conn.Open();

SqlCommand command = new SqlCommand("SELECT * FROM TableName WHERE

FirstColumn = @0", conn);

command.Parameters.Add(new SqlParameter("0", 1));

using (SqlDataReader reader = command.ExecuteReader())

{

Console.WriteLine("FirstColumn\tSecond Column\t\tThird Column\t\tForth Column\t");

while (reader.Read())

{

Console.WriteLine(String.Format("{0} \t | {1} \t | {2} \t | {3}", reader[0], reader[1],

reader[2], reader[3]));

}

}

Console.WriteLine("Data displayed! Now press enter to move to the next section!");

Console.ReadLine();

Console.Clear();

Console.WriteLine("INSERT INTO command");

SqlCommand insertCommand = new SqlCommand("INSERT INTO TableName

(FirstColumn, SecondColumn, ThirdColumn, ForthColumn) VALUES (@0, @1, @2, @3)",

conn);

insertCommand.Parameters.Add(new SqlParameter("0", 10));

insertCommand.Parameters.Add(new SqlParameter("1", "Test Column"));

insertCommand.Parameters.Add(new SqlParameter("2", DateTime.Now));

insertCommand.Parameters.Add(new SqlParameter("3", false));

Department of Information Technology Page 44

PAD LAB 2021-2022

Console.WriteLine("Commands executed! Total rows affected are " +

insertCommand.ExecuteNonQuery());

Console.WriteLine("Done! Press enter to move to the next step");

Console.ReadLine();

Console.Clear();

Console.WriteLine("Now the error trial!");

Try

{

SqlCommand errorCommand = new SqlCommand("SELECT * FROM someErrorColumn",

conn); errorCommand.ExecuteNonQuery();

}

catch (SqlException er)

{

Console.WriteLine("There was an error reported by SQL Server, " + er.Message);

}

}

Console.ReadLine();

}

}

}

Three test outputs:

Signature of the Faculty

Department of Information Technology Page 45

PAD LAB 2021-2022

b) Write a program to update books details using sql procedures

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;

public partial class _Default: System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void Button1_Click(object sender, EventArgs e)

{

SqlConnection con = new SqlConnection(@

"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integ

rated Security=True;User Instance=True");

SqlCommand cmd = new SqlCommand("sp_insert", con);

cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue("Book Name", TextBox1.Text);

cmd.Parameters.AddWithValue("Author Name", TextBox2.Text);

cmd.Parameters.AddWithValue("Publication", TextBox3.Text);

con.Open();

int k = cmd.ExecuteNonQuery();

if (k != 0) {

lblmsg.Text = "Record Inserted Succesfully into the Database";

lblmsg.ForeColor = System.Drawing.Color.CornflowerBlue;

}

con.Close();

}

}

Three test outputs:

Signature of the Faculty