You are on page 1of 99

PMAS Arid Agricultural University Rawalpindi

University Institute of Information Technology

Visual Programming Assignment No. 1

Class: MCs-3 (Eve)

Name: Muhammad Afraz


Reg# No: 16-Arid-1345

Submitted To:
Sir Saif Ur Rehman

Last Date is: Before or on the Day of Mid Visual


Programming Paper
Question# 1 Define the following terms

a. .Net Framework

Answer: .NET Framework (pronounced dot net) is a software framework developed


by Microsoft that runs primarily on Microsoft Windows. It includes a large class
librarynamed Framework Class Library (FCL) and provides language interoperability (each language
can use code written in other languages) across several programming languages. Programs written
for .NET Framework execute in a software environment (in contrast to a hardware environment)
named Common Language Runtime(CLR), an application virtual machine that provides services
such as security, memory management, and exception handling. (As such, computer code written
using .NET Framework is called "managed code".) FCL and CLR together constitute .NET
Framework.

b. Framework Class Library

Answrer: The .NET Framework class library is a library of classes, interfaces, and value types that provide
access to system functionality. It is the foundation on which .NET Framework applications, components,
and controls are built. The namespaces and namespace categories in the class library are listed in the
following table and documented in detail in this reference. The namespaces and categories are listed by
usage, with the most frequently used namespaces appearing first.

c. .Net Common Language Runtime

Answer: The Common Language Runtime (CLR), the virtual machine component
of Microsoft's .NET framework, manages the execution of .NET programs. A process known as just-
in-time compilation converts compiled code into machine instructions which the
computer's CPU then executes.[1] The CLR provides additional services including memory
management, type safety, exception handling, garbage collection, security and thread management.
All programs written for the .NET framework, regardless of programming language, are executed by
the CLR. All versions of the .NET framework include CLR.

d. namespaces in .Net

Answer: NameSpace is the Logical group of types or we can say namespace is a container (e.g
Class, Structures, Interfaces, Enumerations, Delegates etc.), example System.IO logically
groups input output related features , System.Data.SqlClient is the logical group of
ado.net Connectivity with Sql server related features.

e. Assembly
Answer:An assembly (or assembler) language, often abbreviated asm, is a low-level
programming language for a computer, or other programmable device, in which there is a very
strong (but often not one-to-one) correspondence between the language and the architecture's
machine code instructions.

f. Common Language Specification

Answer: A Common Language Specification (CLS) is a document that says how computer
programs can be turned into MSIL code. When several languages use the same bytecode, different
parts of a program can be written in different languages. Microsoft uses a Common Language
Specification for their .NET Framework. To fully interact with other objects regardless of the
language they were used in, objects must expose to callers only those features that are common to
all the languages they must exchange information with. It was always a dream of Microsoft to unite
all different languages into one umbrella and CLS is one step towards that. Microsoft has defined
CLS which are nothing but guidelines for languages to follow so that it can communicate with other
.NET languages in a seamless manner.

g. Common Intermediate Language

Answer: Common Intermediate Language (CIL, pronounced either "sil" or "kil"), formerly
called Microsoft Intermediate Language or MSIL, is the lowest-level human-
readable programming language defined by the Common Language Infrastructure (CLI) specification
and is used by the .NET Framework and Mono. Languages which target a CLI-compatible runtime
environment compile to CIL, which is assembled into an object code that has a bytecode-style
format. CIL is an object-oriented assembly language, and is entirely stack-based. Its bytecode is
translated into native code ormost commonlyexecuted by a virtual machine.

h. Visual Programming

Answert: visual programming language (VPL) is any programming language that lets users
create programs by manipulating program elements graphically rather than by specifying them
textually. A VPL allows programming with visual expressions, spatial arrangements of text and
graphic symbols, used either as elements of syntax or secondary notation. For example, many VPLs
(known as dataflow or diagrammatic programming) are based on the idea of "boxes and arrows",
where boxes or other screen objects are treated as entities, connected by arrows, lines or arcs
which represent relations.

i. Use of keyword new in C-Sharp

In C#, the new keyword can be used as an operator, a modifier, or a constraint.Used to hide
an inherited member from a base class member. Used to restrict types that might be used as
arguments for a type parameter in a generic declaration.

j. Structured Programming, Object Oriented Programming, Procedural Programming, Visual Programming,


Event Driven Programming Languages

Answer: Imperative programming defines computation as statements that change a


program state.
Procedural programming, structured programming specifies the steps a program must take to
reach a desired state.
Declarative programming defines program logic, but not detailed control flow.
Functional programming treats programs as evaluating mathematical functions and
avoids state and mutable data
Object-oriented programming (OOP) organizes programs as objects: data
structures consisting of datafields and methods together with their interactions.
Event-driven programming program control flow is determined by events, such
as sensor inputs or user actions (mouse clicks, key presses) or messages from other programs
or threads.
Automata-based programming a program, or part, is treated as a model of a finite state
machine or any other formal automaton.

k. List down five languages in each of the language categories given in Q#1 Part-j.
Answer:

l. Why static is used with Main() method in Program.cs file?

Answer:The Main method is the entry point of a C# application. (Libraries and services
do not require a Main method as an entry point.) When the application is started,
the Main method is the first method that is invoked.+
There can only be one entry point in a C# program. If you have more than one class that
has a Main method, you must compile your program with the /main compiler option to
specify which Main method to use as the entry point.

m. How C# differs from Java

Answer: C# vs. Javawhich general purpose, object-oriented programming language is


best for you? Both have extensive libraries that can be used to build applications for the
desktop, web, mobile devices, and other platforms. Both have large communities of
enthusiastic fans, and plenty of online support.

With so much in common, selecting the right language requires a more nuanced
approach. Lets take a closer look at the similarities and differences between C# and
Java

n. When was .Net Framework first launched?

Answer: Microsoft began developing .NET Framework in the late 1990s, originally under the name
of Next Generation Windows Services (NGWS). By late 2000, the first beta versions of .NET 1.0
were released.
In August 2000, Microsoft, Hewlett-Packard, and Intel worked to standardize Common Language
Infrastructure (CLI) and C#. By December 2001, both were ratified Ecma International (ECMA)
standards. International Organisation for Standardisation (ISO) followed in April 2003. The current
version of ISO standards are ISO-IEC 23271:2012 and ISO/IEC 23270:2006.
o. What .Net Framework is currently in the Market?

Answer: .NET Framework 4.7.1

p. What is event?

Answer:Events enable a class or object to notify other classes or objects when something of
interest occurs. The class that sends (or raises) the event is called the publisher and the
classes that receive (or handle) the event are called subscribers.

q. What is property?

A property, in some object-oriented programming languages, is a special sort of class


member, intermediate in functionality between a field (or data member) and a method.

r. Why namespace is used in C#?

Answer: Namespaces are used to provide a "named space" in which your application resides.
They're used especially to provide the C# compiler a context for all the named information in your
program, such as variable names. Without namespaces, for example, you wouldn't be able to make
a class named Console, as .NET already uses one in its System namespace. The purpose of
namespaces is to solve this problem, and release thousands of names defined in the .NET
Framework for your applications to use, along with making it so your application doesn't occupy
names for other applications, if your application is intended to be used in conjunction with another.
So namespaces exist to resolve ambiguities a compiler wouldn't otherwise be able to do.

s. Why the System Class library is used in C#

The .NET Framework class library is a library of classes, interfaces, and value types that provide access to
system functionality. It is the foundation on which .NET Framework applications, components, and
controls are built. The namespaces and namespace categories in the class library are listed in the
following table and documented in detail in this reference. The namespaces and categories are listed by
usage, with the most frequently used namespaces appearing first.

Question# 2 why the following files are used in .Net applications (window and web application)

Also, discuss the contents which can be added to each of these files.

a. app.config

Answer: At its simplest, the app.config is an XML file with many predefined configuration
sections available and support for custom configuration sections. A "configuration section"
is a snippet of XML with a schema meant to store some type of information.

Overview (MSDN)
Connection String Configuration (MSDN)
Settings can be configured using built-in configuration sections such
as connectionStrings or appSettings. You can add your own custom configuration sections;
this is an advanced topic, but very powerful for building strongly-typed configuration files.
Web applications typically have a web.config, while Windows GUI/service applications have
an app.config file.Application-level config files inherit settings from global configuration files.

b. web.config

Answer: The Configuration API provides a way of configuring an app based on a list of
name-value pairs. Configuration is read at runtime from multiple sources. The name-
value pairs can be grouped into a multi-level hierarchy. There are configuration
providers for:+

File formats (INI, JSON, and XML)


Command-line arguments
Environment variables
In-memory .NET objects
An encrypted user store
Azure Key Vault
Custom providers, which you install or create

Each configuration value maps to a string key. There's built-in binding support to
deserialize settings into a custom POCOobject (a simple .NET class with properties).

c. Program.cs

Answer: The starting point for your program (the Main() ) is in Program.cs. It sets some
environment parameters and calls for the creation of Form1. The code for Form1 is divided between
the Form1.cs file and the Form1.Designer.cs file. (I believe this division is new for this version of
VS.) Essentially, Form1.Designer.cs contains all of the code about the form that is automatically
generated for you when you drag components to the form from the toolbox. Form1.cs is where you
write your code related to the form.In general, you should only write code in Form1.cs. Let the IDE
write the code in Form1.Designer.cs. There may be some rare occasions in which you would want to
touch Program.cs.

Question# 3 what are the difference between windows and web applications?

Answer:

Windows Application
Windows Application is a user build application that can run on a Windows
platform. The windows application has a graphical user interface that is provided
by Windows Forms. Windows forms provide a variety of controls including
Button, TextBox, Radio Button, CheckBox, and other data and connection
controls. You can easily design a web application using an IDE Microsoft Visual
Studio using a variety of languages including C#, Visual Basic, C++, J# and many
more.

Web Application
It is a type of application that runs on a browser using a Web server configured
with Microsoft Internet Information Services (IIS). In .NET, all web applications
are built around ASP.NET, which is nothing but a part of .NET platform and
includes design-time objects and controls and a run-time execution context.
ASP.NET helps in building wide variety of web application from a traditional
website that serves HTML pages to a high-end business application that runs on
Internet

Question# 4 what are the differences between JAVA and C-Sharp language?
Answer:

C# and java both were derived from C++, and therefore they have similar roots, both are widely
used for web programming. We discuss the difference between C# and java these are as
follows:

C# has more primitive datatypes

Java uses static final to declare a class constant while C# uses const.

Java does not provide for operator overloading.

C# supports the struct type and java does not.

Unlike java, all C# datatypes are object.

C# provides static constructors for initialization.

In java, parameters are always passed by value, c# allows parameters to be passed by


reference by Ref keyword.

C# includes native support for properties, java does not.

Java does not directly support enumerations.

In java, the switch statement can have only integer expression, in C# supports integer
and string both.

Question# 5 what are the qualities of good project (Window or Web based)?

Answer: There is a tendency for IT infrastructure projects to shortchange the


planning process, with an emphasis on jumping right in and beginning the
work. This is a mistake. The time spent properly planning the project will result
in reduced cost and duration and increased quality over the life of the project.
The project definition is the primary deliverable from the planning process and
describes all aspects of the project at a high level. Once approved by the
customer and relevant stakeholders, it becomes the basis for the work to be
performed. For example, in planning an Exchange migration, the project
definition should include the following:

Project overview: Why is the Exchange migration taking place? What are
the business drivers? What are the business benefits?
Objectives: What will be accomplished by the migration? What do you
hope to achieve?
Scope: What features of Exchange will be implemented? Which
departments will be converted? What is specifically out of scope?
Assumptions and risks: What events are you taking for granted
(assumptions), and what events are you concerned about? Will the right
hardware and infrastructure be in place? Do you have enough storage and
network capacity?
Approach: How will the migration project unfold and proceed?
Organization: Show the significant roles on the project. Identifying the
project manager is easy, but who is the sponsor? It might be the CIO for a
project like this. Who is on the project team? Are any of the stakeholders
represented?
Signature page: Ask the sponsor and key stakeholders to approve this
document, signifying that they agree on what is planned.
Initial effort, cost, and duration estimates: These should start as best-
guess estimates and then be revised, if necessary, when the workplan is
completed.

Question# 6 What is the function of using MSIL.

Answer: Microsoft Intermediate Language (MSIL) is a CPU independent set of instructions


that can be converted to the native code. Metadata also created in the course of compile
time with Microsoft Intermediate Language (MSIL) and stored it with the compiled code .

Question# 7 Differentiate between Console.Read() and Console.ReadLine()

Answer: Console.Readline() accepts the string and returns the string.

Console.Read() accepts the first character of the string and returns ASCII Code(Integer Value) of that first
character

Console.ReadKey accepts the Character entered in the command prompt and returns the key info
pressed with the modifiers(cntrl,shift,Alt) used while pressing the key.Info like which key pressed,ASCII
Code of the Key and Modifiers used and the type of the key which will always be char.

Apart from this Console.ReadLine() and Console.Read() will return to the code only when we press Enter
Key, whereas in Console.ReadKey() we will return to the Code when we press any key with modifiers or
without modifiers.

Question# 8 What is a Console Application?

Answer: A console application is a computer program designed to be used via a text-only


computer interface, such as a text terminal, the command line interface of some operating
systems (Unix, DOS, etc.) or the text-based interface included with most Graphical User
Interface (GUI) operating systems, such as the Win32 console in Microsoft Windows,
the Terminal in Mac OS X, and xterm in Unix. A user typically interacts with a console application
using only a keyboard and display screen, as opposed to GUI applications, which normally require
the use of a mouse or other pointing device. Many console applications such as command line
interpreters are command line tools, but numerous text-based user interface (TUI) programs also
exist.

Question# 9 Differentiate between Console.Write() and Console.WriteLine()


Write Method
Write method resides inside the Console class which itself resides inside the
System namespace. The Console class provides basic support for applications
that read and write characters to and from the console. The write() method
outputs one or more values on the screen without a new line character. This
means any subsequent output will be printed in the same line.
Example of Console.Write
1 Console.Write("Afraz");

2 Console.Write(" ");

3 Console.Write("Jutt");

Output:
Afraz Jutt

WriteLine Method
WriteLine method also resides inside the Console class of the System
namespace. The WriteLine method prints one or more object on a single line with
a new line character inserted at the end. This means any subsequent output will
be printed on a new line.

Example of Consol.WriteLine();

1 Console.WriteLine("Afraz");

2 Console.WriteLine("Jutt");

3 Console.WriteLine("MCs-3");

Output:
Afraz
Jutt
MCs-3

Question# 10 Define the syntax of using

a. if statement

Answer: The if statement is a conditional branch statement. The syntax of the if


statement is either one of these two:
if (booleanExpression) {
MessageBox.show("AFRAZ JUTT");
}

b. nested if-statement

Answer: if( boolean_expression 1) {

/* Executes when the boolean expression 1 is true */


if(boolean_expression 2) {
/* Executes when the boolean expression 2 is true */
}
}

c. if-else statement

Answer: if(boolean_expression) {
/* statement(s) will execute if the boolean expression is true */
}
else {
/* statement(s) will execute if the boolean expression is false */
}

d. nested if-else statement

Answer: if ( condition1 )
statement1 ;
else if ( condition2 )
statement2 ;
...
else if ( condition-n )
statement-n ;
else
statement-e ;

e. switch statement

Answer: The switch statement provides a convenient alternative to the if when


dealing with a multi-way branch. Suppose we have some integer value called test
and want to do different operations depending on whether it has the value 1, 5 or
any other value, then the switch statement could be employed:-
switch ( test ) {
case 1 :
// Process for test = 1
...
break;

case 5 :
// Process for test = 5
...
break;

default :
// Process for all other cases.
...

f. for loop

Answer: for ( variable initialization; condition; variable update ) {


Code to execute while the condition is true
}

g. while loop

Answer: while (true)


{
take_turn(player1);
take_turn(player2);
}

h. do-while loop

Answer: do {
statement(s);
} while( condition );

i. declaring and initializing one dimensional array

Answer: type array-name[size] = { list of values };

j. declaring and initializing two dimensional array

Answere: type arrayName [ x ][ y ];


int disp[2][4] = {
{10, 11, 12, 13},
{14, 15, 16, 17}
};

k. Design a class in C#, named ArrayHandlingInCSharp. Add the following


methods in the class and uses one dimensional Array:

a. readArrayItems() ------------------To read Values in the Array

b. showArrayItems() -------------------To display the Values stored in the


Array

c. sortArrayItems() -------------------To sort the contents of Array using


Bubble Sort

d. findMaximuminArray() ------------------To find maximum in Array

e. returnArrayItemsSum() ------------------To find and return the sum of Array


Contents which are Odd indexed

Overload the constructors in the above class. Finally, instantiate the class in Main
() and test the newly created class.

Answer:

Question# 11 Give programming example of break and conditional operators in C-Sharp

Answer: class BreakInNestedLoops


{
static void Main(string[] args)
{

int[] numbers = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
char[] letters = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };

// Outer loop
for (int x = 0; x < numbers.Length; x++)
{
Console.WriteLine("num = {0}", numbers[x]);

// Inner loop
for (int y = 0; y < letters.Length; y++)
{
if (y == x)
{
// Return control to outer loop
break;
}
Console.Write(" {0} ", letters[y]);
}
Console.WriteLine();
}

// Keep the console open in debug mode.


Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}

/*
* Output:
num = 0

num = 1
a
num = 2
a b
num = 3
a b c
num = 4
a b c d
num = 5
a b c d e
num = 6
a b c d e f
num = 7
a b c d e f g
num = 8
a b c d e f g h
num = 9
a b c d e f g h i
*/

Question# 12 What are command line arguments? How command line


arguments are used.
Answer: The parameter of the Main method is a String array that represents the command-
line arguments. Usually you determine whether arguments exist by testing the Length property,
for example:

if (args.Length == 0)
{
System.Console.WriteLine("Please enter a numeric argument.");
return 1;
}

Question# 13 What are Strings? How String Variables are declared in C-Sharp.
Suppose following text is stored in String Variable named intrToVisualCSharp.
Answer: In C#, the string keyword is an alias for String. Therefore, String and string are
equivalent, and you can use whichever naming convention you prefer. The String class
provides many methods for safely creating, manipulating, and comparing strings. In addition,
the C# language overloads some operators to simplify common string operations. For more
information about the keyword, see string. For more information about the type and its
methods, see String.

// Declare without initializing.


string message1;

// Initialize to null.
string message2 = null;

// Initialize as an empty string.


// Use the Empty constant instead of the literal "".
string message3 = System.String.Empty;

//Initialize with a regular string literal.


string oldPath = "c:\\Program Files\\Microsoft Visual Studio 8.0";

// Initialize with a verbatim string literal.


string newPath = @"c:\Program Files\Microsoft Visual Studio 9.0";

// Use System.String if you prefer.


System.String greeting = "Hello World!";

// In local variables (i.e. within a method body)


// you can use implicit typing.
var temp = "I'm still a strongly-typed System.String!";

// Use a const string to prevent 'message4' from


// being used to store another string value.
const string message4 = "You can't get rid of me!";

// Use the String constructor only when creating


// a string from a char*, char[], or sbyte*. See
// System.String documentation for details.
char[] letters = { 'A', 'B', 'C' };
string alphabet = new string(letters);

Question# 14 How String array is declared? Declare an Array of size 50. Read the name of all your class
fellows in this array. Then using the built-in String class function. Write the C-Sharp code to

a. Display all the names of the students which starts with letter S

b. Count all those names in the array which contains Khan in their name
c. Display all those Student Names which are having Rehman in their names

d. Find how many words are there in each name of the student

Answer:
using System;

class Program
{
static void Main(string[]
args)
{
// ... Loop over
arguments passed to this
program.
foreach(string value in
args)
{

Console.WriteLine("Argument:
{0}", value);
}
Console.ReadLine();
}
}

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

namespace strings
{
class Program
{

static void Main(string[] args)


{

string[] str = new string[1];


for (int i = 0; i < 1; i++)
{
Console.WriteLine("Enter the names of students");
str[i]=Console.ReadLine();

}
int count = 0;
for (int i = 0; i < 1; i++)
{
if (str[i].StartsWith("s"))
{
Console.WriteLine(str[i]);
}
if (str[i].Contains("khan"))
{
Console.WriteLine(str[i]);
}

if (str[i].Contains("rehman"))
{
count++;
Console.WriteLine("The count of names contains Rehman "+count);
}
int wordcount=0;

wordcount = str[i].Count(char.IsWhiteSpace);
wordcount += 1;
Console.WriteLine(str[i] + "The Number of words are = " + wordcount);

}
Console.ReadKey();
}

}
}

Question# 15

1. what is class?

Answer: The class is one of the defining ideas of object-oriented programming.


Among the important ideas about classes are:

A class can have subclasses that can inherit all or some of the
characteristics of the class. In relation to each subclass, the class becomes
the superclass.

Subclasses can also define their own methods and variables that are not
part of their superclass.

The structure of a class and its subclasses is called the class hierarchy.
2. How class is declared in C-Sharp?

Answer: <access specifier> class class_name {


// member variables
<access specifier> <data type> variable1;
<access specifier> <data type> variable2;
...
<access specifier> <data type> variableN;
// member methods
<access specifier> <return type> method1(parameter_list) {
// method body
}
<access specifier> <return type> method2(parameter_list) {
// method body
}
...
<access specifier> <return type> methodN(parameter_list) {
// method body
}
}
3. How methods are overloaded in C-Sharp?

Answer: A lot of programming languages supports a technique called default/optional parameters. It allows the
programmer to make one or several parameters optional, by giving them a default value. It's especially
practical when adding functionality to existing code.

For instance, you may wish to add functionality to an existing function, which requires one or more parameters
to be added. By doing so, you would break existing code calling this function, since they would now not be
passing the required amount of parameters. To work around this, you could define the newly added parameters
as optional, and give them a default value that corresponds to how the code would work before adding the
parameters.

Default parameters were introduced in C# version 4.0, but up until that, C# coders have been using a different
technique, which basically does the same, called method overloading. It allows the programmer do define
several methods with the same name, as long as they take a different set of parameters. When you use the
classes of the .NET framework, you will soon realize that method overloading is used all over the place. A good
example of this, is the Substring() method of the String class. It is with an extra overload, like this:

string Substring (int startIndex)


string Substring (int startIndex, int length)
You can call it with either one or two parameters. If you only call it with one parameter, the length parameter is
assumed to be the rest of the string, saving us time whenever we simply want to get the last part of a string.

So, by defining several versions of the same function, how do we avoid having the same code several places?
It's actually quite simple: We let the simple versions of the method make the complex version of it do all the
work. Consider the following example:
class SillyMath
{
public static int Plus(int number1, int number2)
{
return Plus(number1, number2, 0);
}

public static int Plus(int number1, int number2, int number3)


{
return number1 + number2 + number3;
}
}
4. Design a class for Patient with Patient_Number, Patient_Name, Disease_Type instance variables. Add
methods for reading, displaying and searching data. Finally, instantiate the class and test the class
methods.

Answer: using System;


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

namespace Patient
{
class Patient
{
string patient_name;
string patient_number;
string disease_type;
public void reading()
{
Console.Clear();
Console.WriteLine("Enter the name of Patient");
patient_name = Console.ReadLine();
Console.WriteLine("Enter the Patient Number");
patient_number = Console.ReadLine();
Console.WriteLine("Enter the Disease type");
disease_type = Console.ReadLine();
}
public void display()
{
Console.Write("Patient Number : ");
Console.WriteLine(patient_number);
Console.Write("Patient Name : ");
Console.WriteLine(patient_name);
Console.Write("Patient Disease : ");
Console.WriteLine(disease_type);

}
public void searching(string n)
{
if (patient_name.Contains(n))
{
Console.Write("Patient Number : ");
Console.WriteLine(patient_number);
Console.Write("Patient Name : ");
Console.WriteLine(patient_name);
Console.Write("Patient Disease : ");
Console.WriteLine(disease_type);
}
}
}
class program
{
static void Main(string[] args)
{
Patient[] p = new Patient[50];
int i = 0;
while (true)
{

Console.WriteLine("1. Add Patient");


Console.WriteLine("2. Display All Patient");
Console.WriteLine("3. Search Patient");
int op;
op = Convert.ToInt16(Console.ReadLine());
switch (op)
{
case 1:
p[i] = new Patient();
p[i].reading();
i++;
break;
case 2:
for (int j = 0; j < i; j++)
p[j].display();
break;
case 3:
Console.WriteLine("Search by name e.g[Afraz Jutt]");
string name;
name = Console.ReadLine();
for (int j = 0; j < i; j++)
p[j].searching(name);
break;
default:
Console.WriteLine("Invalid Option");
break;

}
}
}

Question# 16

1. what is inheritance in C-Sharp?

2. Define the base and sub class?

Answer: 1,2

Inheritance enables you to create new classes that reuse, extend, and modify the behavior that is defined
in other classes.

The class whose members are inherited is called the base class,

and the class that inherits those members is called the derived class.

3. How Inheritance is done in C#


Answer: Single level

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

namespace Inheritance
{
class parent
{

string parent_name;
string address;
public void getdata()
{
Console.WriteLine("Enter the Parent Name");
parent_name = Console.ReadLine();
Console.WriteLine("Enter the Address");
address = Console.ReadLine();
}
public void putdata()
{
Console.WriteLine("Parent Name " + parent_name);
Console.WriteLine("Address " + address);

}
class child : parent
{
string child_name;
public void getdata()
{
base.getdata();
Console.WriteLine("Enter Child Name");
child_name= Console.ReadLine();
}
public void putdata()
{

base.putdata();
Console.WriteLine("Child Name " + child_name);

}
}

class Program
{
static void Main(string[] args)
{
child c = new child();
c.getdata();
c.putdata();
Console.ReadKey();
}
}
}

4. Differentiate between Single and Multilevel Inheritance?

Answer(see Q6)

5. Does C-Sharp support Multiple Inheritance?

Answer:We use interface to resolve this problem.

6. Design the classes to show the concepts of Single, Multilevel and Multiple
Inheritance in C-Sharp?

Answer: multilevel

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

namespace Inheritance
{
class parent
{

string parent_name;
string address;
public void getdata()
{
Console.WriteLine("Enter the Parent Name");
parent_name = Console.ReadLine();
Console.WriteLine("Enter the Address");
address = Console.ReadLine();
}
public void putdata()
{
Console.WriteLine("Parent Name " + parent_name);
Console.WriteLine("Address " + address);

}
class child : parent
{
string child_name;
public void getdata()
{
base.getdata();
Console.WriteLine("Enter Child Name");
child_name = Console.ReadLine();
}
public void putdata()
{

base.putdata();
Console.WriteLine("Child Name " + child_name);

}
}
class grand_child : child
{
string grand_child_name;
public void getdata()
{
base.getdata();
Console.WriteLine("Enter Grand Child Name");
grand_child_name = Console.ReadLine();
}
public void putdata()
{

base.putdata();
Console.WriteLine("Grand Child Name " + grand_child_name);

}
class Program
{
static void Main(string[] args)
{
grand_child c= new grand_child();
c.getdata();
c.putdata();
Console.ReadKey();

}
}
}

Multiple Inheritance

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

namespace InterfaceApplication
{
public interface ITransactions
{
// interface members
void showTransaction();
double getAmount();
}

public class Transaction : ITransactions


{
private string tCode;
private string date;
private double amount;
public Transaction()
{
tCode = " ";
date = " ";
amount = 0.0;
}

public Transaction(string c, string d, double a)


{
tCode = c;
date = d;
amount = a;
}

public double getAmount()


{
return amount;
}

public void showTransaction()


{
Console.WriteLine("Transaction: {0}", tCode);
Console.WriteLine("Date: {0}", date);
Console.WriteLine("Amount: {0}", getAmount());
}
}
class Tester
{
static void Main(string[] args)
{
Transaction t1 = new Transaction("001", "8/10/2012", 78900.00);
Transaction t2 = new Transaction("002", "9/10/2012", 451900.00);
t1.showTransaction();
t2.showTransaction();
Console.ReadKey();
}
}
}

Question# 17 define the following terms with suitable programming examples

i. private, protected and public

Answer:
public
The type or member can be accessed by any other code in the same assembly or another
assembly that references it.
private
The type or member can only be accessed by code in the same class or struct.
protected
The type or member can only be accessed by code in the same class or struct, or in a
derived class.

ii. finalize

Answer: Allows an object to try to free resources and perform other cleanup operations before it is
reclaimed by garbage collection.

iii. partial class


Answer: It is possible to split the definition of a class or a struct, an interface or a method over
two or more source files. Each source file contains a section of the type or method definition,
and all parts are combined when the application is compiled.

iv. foreach loop in c-sharp

Answer: A foreach-loop. This is the easiest, least error-prone loop.


It is preferred in many program contexts. But we lose some
flexibility with it.

Index:Foreach uses no integer index. Instead, it is used on a


collectionit returns each element in order.
Tip:This is called enumeration. We eliminate errors caused by
incorrect index handling.
Strings:We use foreach, on a string array, to loop through the
elements in the array.

using System;
using System.Linq;

class Program
{
static void Main()
{
// An unsorted string
array.
string[] letters = {
"a", "f", "r", "a","z" };
// Use LINQ query syntax
to sort the array
alphabetically.
var sorted = from letter
in letters
orderby
letter
select
letter;
// Loop with the foreach
keyword.
foreach (string value in
sorted)
{

Console.WriteLine(value);
}
}
}

Output

a
f
r
a
z

v. while and do-while loop

Answer:

while Loop
using System;

namespace Loop
{
class WhileLoop
{
public static void Main(string[] args)
{
int i=1;
while (i<=5)
{
Console.WriteLine("AFRAZ JUTT", i);
i++;
}
}
}
}
do...while loop :The do and while keyword is used to create a do...while
loop. It is similar to a while loop, however there is a major difference between
them.

In while loop, the condition is checked before the body is executed. It is the exact
opposite in do...while loop, i.e. condition is checked after the body is executed.

This is why, the body of do...while loop will execute at least once irrespective to
the test-expression.

using System;

namespace Loop
{
class DoWhileLoop
{
public static void Main(string[] args)
{
int i = 1, n = 5, product;

do
{
product = n * i;
Console.WriteLine("{0} * {1} = {2}", n, i,
product);
i++;
} while (i <= 10);
}
}
}

Question# 18 Explore the differences between .Net Framework 2.0, .Net Framework 2.5, .Net
Framework 3.0, .Net Framework 4.0 and .Net Framework 4.5.
Answer:
.Net Framework 2.0 Features

ADO.NET

New features in ADO.NET include support for user-defined types (UDT), asynchronous database
operations, XML data types, large value types, snapshot isolation, and new attributes that allow
applications to support multiple active result sets (MARS) with SQL Server 2005.

ASP.NET

The Microsoft .NET Framework 2.0 includes significant enhancements to all areas of ASP.NET. For Web
page development, new controls make it easier to add commonly used functionality to dynamic Web
pages. New data controls make it possible to display and edit data on an ASP.NET Web page without
writing code. An improved code-behind model makes developing ASP.NET pages easier and more robust.
Caching features provide several new ways to cache pages, including the ability to build cache
dependency on tables in a SQL Server database.

ASP.NET accommodates a wide variety of browsers and devices. By default, controls render output that is
compatible with XHTML 1.1 standards. You can use device filtering to specify different property values on
the same control for different browsers.

.NET Remoting

.NET Framework Remoting now supports IPv6 addresses and the exchange of generic types. The classes in
the System.Runtime.Remoting.Channels.Tcp namespace support authentication and encryption using the
Security Support Provider Interface (SSPI). Classes in the new System.Runtime.Remoting.Channels.Ipc
namespace allow applications on the same computer to communicate quickly without using the network.
Finally, you can now configure the connection cache time-out and the number of method retries, which
can improve the performance of network load-balanced remote clusters.

XML

The new System.Xml.XmlReaderSettings class allows specification of the type of verifications to be done
when using a subclass of XmlReader to read XML data.

It is now possible to partially validate a DOM tree loaded within an instance of XmlDocument.

It is now possible to modify a DOM tree stored in an XmlDocument instance through the XPathNavigator
cursor API.

.Net Framework 3.0/3.5 Features

Windows Presentation Foundation (WPF)


Windows Presentation Foundation (WPF) is a next-generation presentation system for building Windows
client applications. The core of WPF is a resolution-independent and vector-based rendering engine that
is built to take advantage of modern graphics hardware.

WPF extends the core with a comprehensive set of application-development features that include
Extensible Application Markup Language (XAML), controls, data binding, layout, 2-D and 3-Dgraphics,
animation, styles, templates, documents, media, text, and typography. WPF is included in the Microsoft
.NET Framework, so you can build applications that incorporate other elements of the .NET Framework
class library.

To support some of the more powerful WPF capabilities and to simplify the programming experience,
WPF includes additional programming constructs that enhance properties and events: dependency
properties and routed events.

Windows Communication Foundation (WCF)

Windows Communication Foundation (WCF) is Microsoft's unified programming model for building
service-oriented applications. WCF allows you to build many kinds of distributed applications including
"traditional" Web Services so that your services support SOAP and will therefore be compatible with older
.NET (and other) technologies. WCF is not just about pure SOAP over the wire - you can work with an Info
set, and create a binary representation of your SOAP message that can then be sent along with your
choice of protocol. This is for those who are particularly concerned about performance and have
traditionally turned to .NET remoting.

Windows Workflow Foundation (WWF)

Windows Workflow Foundation, a core component of .NET Framework 3.0, provides a programming
model, run-time engine, and tools for building workflow applications.

A workflow is created and maintained by the workflow run-time engine. There can be several workflow
engines within an application domain, and each workflow engine can support multiple workflows running
concurrently. The run-time enables idle workflows to be unloaded from memory, persisted to a store, and
reloaded whenever input is received.

Workflows can be authored in code, XAML markup, or a combination of both, known as code-separation,
which is similar to the ASP.NET mode.

Windows CardSpace (WCS)

Windows CardSpace (InfoCard) is a Digital Identity to online services. Digital Identity is how a user will be
electronically represented. Such as for a debit/credit card, each card has a digital identity and password. If
any user uses the site on internet then he enters their username and password, for identity, but this is not
secure. WCS reduces these types of problems.

WCS (originally called Info Card) helps people keep track of their digital identities as distinct information
cards. If a Web site accepts WCS logins, users attempting to log in to that site will see a WCS selection. By
choosing a card, users also choose a digital identity that will be used to access this site. CardSpace and
the new supporting technologies will change how you authenticate into an application, whether it sits on
the Web, your phone, or your desktop.

Core New Features and Improvements

Some core new features and improvements are implemented in .Net 3.0/3.5; they are:

1. Auto Implemented Property


2. Implicit Typed local variable
3. Implicitly Typed Arrays
4. Anonymous Types
5. Extension Methods (3.5 new feature)
6. Object and Collection Initializers
7. Lambda Expressions

.Net Framework 4.0 Features

Application Compatibility and Deployment

The .NET Framework 4 is highly compatible with applications that are built with earlier .NET Framework
versions, except for some changes that were made to improve security, standards compliance,
correctness, reliability, and performance.

The .NET Framework 4 does not automatically use its version of the common language runtime to run
applications that are built with earlier versions of the .NET Framework. To run older applications with .NET
Framework 4, you must compile your application with the target .NET Framework version specified in the
properties for your project in Visual Studio, or you can specify the supported runtime with the
<supportedRuntime> Element in an application configuration file.

Core New Features and Improvements

Some new features are introduced in .Net framework 4.0.

The following sections describe new features and improvements provided by the common language
runtime and the base class libraries.

1. BigInteger and Complex Numbers


2. Tuples
3. Covariance and Contravariance
4. Dynamic Language Runtime

Managed Extensibility Framework

The Managed Extensibility Framework (MEF) is a new library in the .NET Framework 4 that helps you build
extensible and composable applications. MEF enables you to specify points where an application can be
extended, to expose services to offer to other extensible applications and to create parts for consumption
by extensible applications.

It also enables easy discoverability of available parts based on metadata, without the need to load the
assemblies for the parts.

Parallel Computing

The .NET Framework 4 introduces a new programming model for writing multithreaded and asynchronous
code that greatly simplifies the work of application and library developers. The new model enables
developers to write efficient, fine-grained, and scalable parallel code in a natural idiom without having to
work directly with threads or the thread pool. The new System.Threading.Tasks namespace and other
related types support this new model.

Web

ASP.NET version 4 introduces new features in the following areas:

Core services, including a new API that lets you extend caching, support for compression for
session-state data, and a new application preload manager (autostart feature).
Web Forms, including more integrated support for ASP.NET routing, enhanced support for Web
standards, updated browser support, new features for data controls, and new features for view
state management.
Web Forms controls, including a new Chart control.
MVC, including new helper methods for views, support for partitioned MVC applications, and
asynchronous controllers.
Dynamic Data, including support for existing Web applications, support for many-to-many
relationships and inheritance, new field templates and attributes, and enhanced data filtering.
Microsoft Ajax, including additional support for client-based Ajax applications in the Microsoft
Ajax Library.
Visual Web Developer, including improved IntelliSense for JScript, new auto-complete snippets
for HTML and ASP.NET markup, and enhanced CSS compatibility.
Deployment, including new tools for automating typical deployment tasks.
Multi-targeting, including better filtering for features that are not available in the target version of
the .NET Framework

Windows Presentation Foundation (WPF) Features in 4.0

Windows Presentation Foundation (WPF) version 4 contains changes and improvements in the following
areas:

New controls, including Calendar, Data Grid, and Date Picker.


VisualStateManager supports changing states of controls.
Touch and Manipulation enables you to create applications that receive input from multiple
touches simultaneously on Windows 7.
Graphics and animation supports layout rounding, Pixel Shader version 3.0, cached composition,
and easing functions.
Text has improved text rendering and supports customizing the caret color and selection color in
text boxes.
Binding is supported on the Command property of an InputBinding, dynamic objects, and the
Text property.
XAML browser applications (XBAPs) support communication with the Web page and support full-
trust deployment.
New types in the System.Windows.Shell namespace enable you to communicate with the
Windows 7 taskbar and pass data to the Windows shell.
The WPF and Silverlight Designer in Visual Studio 2010 has various designer improvements to
help create WPF or Silverlight applications.

Windows Communication Foundation Features in 4.0

Windows Communication Foundation (WCF) provides the following improvements:

Configuration-based activation: Removes the requirement for having an .svc file.


System.Web.Routing integration: Gives you more control over your service's URL by allowing the
use of extensionless URLs.
Multiple IIS site bindings support: Allows you to have multiple base addresses with the same
protocol on the same Web site.
Routing Service: Allows you to route messages based on content.
Support for WS-Discovery: Allows you to create and search for discoverable services.
Standard endpoints: Predefined endpoints that allow you to specify only certain properties.
Workflow services: Integrates WCF and WF by providing activities to send and receive messages,
the ability to correlate messages based on content, and a workflow service host.

Windows Workflow Foundation Features in 4.0

Windows Workflow Foundation (WF) provides improvements in the following areas:

Improved workflow activity model: The Activity class provides the base abstraction of workflow
behavior.
Rich composite activity options: Workflows benefit from new flow-control activities that model
traditional flow-control structures, such as Flowchart, TryCatch, and Switch<T>.
Expanded built-in activity library: New features of the activity library include new flow-control
activities, activities for manipulating member data, and activities for controlling transactions.

.Net Framework 4.5 Features

.NET for Windows Store Apps

Windows Store apps are designed for specific form factors and leverage the power of the Windows
operating system. A subset of the .NET Framework 4.5 is available for building Windows Store apps for
Windows by using C# or Visual Basic.

Portable Class Libraries

The Portable Class Library project in Visual Studio 2012 enables you to write and build managed
assemblies that work on multiple .NET Framework platforms. Using a Portable Class Library project, you
choose the platforms (such as Windows Phone and .NET for Windows Store apps) to target.

ASP.NET 4.5
ASP.NET 4.5 includes the following new features:

Support for new HTML5 form types.


Support for model binders in Web Forms. These let you bind data controls directly to data-access
methods, and automatically convert user input to and from .NET Framework data types.
Support for unobtrusive JavaScript in client-side validation scripts.
Improved handling of client script through bundling and minification for improved page
performance.
Integrated encoding routines from the AntiXSS library (previously an external library) to protect
from cross-site scripting attacks.
Support for WebSockets protocol.

Windows Presentation Foundation (WPF) Features in 4.5

In the .NET Framework 4.5, Windows Presentation Foundation (WPF) contains changes and improvements
in the following areas:

The new Ribbon control, which enables you to implement a ribbon user interface that hosts a
Quick Access Toolbar, Application Menu, and tabs.
The new INotifyDataErrorInfo interface, which supports synchronous and asynchronous data
validation.
New features for the VirtualizingPanel and Dispatcher classes.
Improved performance when displaying large sets of grouped data, and by accessing collections
on non-UI threads.
Data binding to static properties, data binding to custom types that implement the
ICustomTypeProvider interface, and retrieval of data binding information from a binding
expression.
Repositioning of data as the values change (live shaping).
Ability to check whether the data context for an item container is disconnected.
Ability to set the amount of time that should elapse between property changes and data source
updates.
Improved support for implementing weak event patterns. Also, events can now accept markup
extensions.

Windows Communication Foundation (WCF) Features in 4.5

In the .NET Framework 4.5, the following features have been added to make it simpler to write and
maintain Windows Communication Foundation (WCF) applications:

Simplification of generated configuration files.


Support for contract-first development.
Ability to configure ASP.NET compatibility mode more easily.
Changes in default transport property values to reduce the likelihood that you will have to set
them.
Updates to the XmlDictionaryReaderQuotas class to reduce the likelihood that you will have to
manually configure quotas for XML dictionary readers.
Validation of WCF configuration files by Visual Studio as part of the build process, so you can
detect configuration errors before you run your application.
New asynchronous streaming support.
New HTTPS protocol mapping to make it easier to expose an endpoint over HTTPS with Internet
Information Services (IIS).
Ability to generate metadata in a single WSDL document by appending ?singleWSDL to the
service URL.
Websockets support to enable true bidirectional communication over ports 80 and 443 with
performance characteristics similar to the TCP transport.
Support for configuring services in code.
XML Editor tooltips.

Windows Workflow Foundation (WF) Features in 4.5

Several new features have been added to Windows Workflow Foundation (WF) in the .NET Framework 4.5.
These new features include:

State machine workflows, which were first introduced as part of the .NET Framework 4.0.1 (.NET
Framework 4 Platform Update 1). This update included several new classes and activities that
enabled developers to create state machine workflows. These classes and activities were updated
for the .NET Framework 4.5 to include:
The ability to set breakpoints on states.
The ability to copy and paste transitions in the workflow designer.
Designer support for shared trigger transition creation.

Question# 19 what are Collection? Define ArrayList? What are various methods available for ArrayList in
C#.

Answer: Collections provide a more flexible way to work with groups of objects. Unlike
arrays, the group of objects you work with can grow and shrink dynamically as the
needs of the application change. For some collections, you can assign a key to any
object that you put into the collection so that you can quickly retrieve the object by
using the key.

A collection is a class, so you must declare an instance of the class before you can add
elements to that collection.

If your collection contains elements of only one data type, you can use one of the
classes in the System.Collections.Generic namespace. A generic collection enforces type
safety so that no other data type can be added to it. When you retrieve an element from
a generic collection, you do not have to determine its data type or convert it
ArrayList. The world of animals is vast. Consider the centipede. It
has many legs. Some centipedes have more legs than othersthe
exact count varies.
An ArrayList too can be found with a various number of elements.
This collection dynamically resizes. It grows in capacity as elements
are added (if space is needed).

Name Description

Creates an ArrayList wrapper for a specific IList.


Adapter(IList)

Add(Object) Adds an object to the end of the ArrayList.

AddRange(ICollection) Adds the elements of an ICollection to the end of


the ArrayList.

BinarySearch(Int32, Int32, Searches a range of elements in the sorted ArrayList for an


Object, IComparer) element using the specified comparer and returns the zero-
based index of the element.

BinarySearch(Object) Searches the entire sorted ArrayList for an element using the
default comparer and returns the zero-based index of the
element.

BinarySearch(Object, Searches the entire sorted ArrayList for an element using the
IComparer) specified comparer and returns the zero-based index of the
element.

Clear() Removes all elements from the ArrayList.

Clone() Creates a shallow copy of the ArrayList.

Contains(Object) Determines whether an element is in the ArrayList.


CopyTo(Array) Copies the entire ArrayList to a compatible one-
dimensional Array, starting at the beginning of the target
array.

CopyTo(Array, Int32) Copies the entire ArrayList to a compatible one-


dimensional Array, starting at the specified index of the target
array.

CopyTo(Int32, Array, Int32, Copies a range of elements from the ArrayList to a compatible
Int32) one-dimensional Array, starting at the specified index of the
target array.

Equals(Object) Determines whether the specified object is equal to the current


object.(Inherited from Object.)

Finalize() Allows an object to try to free resources and perform other


cleanup operations before it is reclaimed by garbage
collection.(Inherited from Object.)

FixedSize(ArrayList) Returns an ArrayList wrapper with a fixed size.

FixedSize(IList) Returns an IList wrapper with a fixed size.

GetEnumerator() Returns an enumerator for the entire ArrayList.

GetEnumerator(Int32, Returns an enumerator for a range of elements in


Int32) the ArrayList.

GetHashCode() Serves as the default hash function. (Inherited from Object.)

GetRange(Int32, Int32) Returns an ArrayList which represents a subset of the


elements in the source ArrayList.

GetType() Gets the Type of the current instance.(Inherited from Object.)

IndexOf(Object) Searches for the specified Object and returns the zero-based
index of the first occurrence within the entire ArrayList.
IndexOf(Object, Int32) Searches for the specified Object and returns the zero-based
index of the first occurrence within the range of elements in
the ArrayList that extends from the specified index to the last
element.

IndexOf(Object, Int32, Searches for the specified Object and returns the zero-based
Int32) index of the first occurrence within the range of elements in
the ArrayList that starts at the specified index and contains the
specified number of elements.

Insert(Int32, Object) Inserts an element into the ArrayList at the specified index.

InsertRange(Int32, Inserts the elements of a collection into the ArrayList at the


ICollection) specified index.

LastIndexOf(Object) Searches for the specified Object and returns the zero-based
index of the last occurrence within the entire ArrayList.

LastIndexOf(Object, Int32) Searches for the specified Object and returns the zero-based
index of the last occurrence within the range of elements in
the ArrayList that extends from the first element to the
specified index.

LastIndexOf(Object, Int32, Searches for the specified Object and returns the zero-based
Int32) index of the last occurrence within the range of elements in
the ArrayList that contains the specified number of elements
and ends at the specified index.

MemberwiseClone() Creates a shallow copy of the current Object.(Inherited


from Object.)

ReadOnly(ArrayList) Returns a read-only ArrayList wrapper.

ReadOnly(IList) Returns a read-only IList wrapper.

Remove(Object) Removes the first occurrence of a specific object from


the ArrayList.

RemoveAt(Int32) Removes the element at the specified index of the ArrayList.


RemoveRange(Int32, Int32) Removes a range of elements from the ArrayList.

Repeat(Object, Int32) Returns an ArrayList whose elements are copies of the


specified value.

Reverse() Reverses the order of the elements in the entire ArrayList.

Reverse(Int32, Int32) Reverses the order of the elements in the specified range.

SetRange(Int32, Copies the elements of a collection over a range of elements


ICollection) in the ArrayList.

Sort() Sorts the elements in the entire ArrayList.

Sort(IComparer) Sorts the elements in the entire ArrayList using the specified
comparer.

Sort(Int32, Int32, Sorts the elements in a range of elements in ArrayList using


IComparer) the specified comparer.

Synchronized(ArrayList) Returns an ArrayList wrapper that is synchronized (thread


safe).

Synchronized(IList) Returns an IList wrapper that is synchronized (thread safe).

ToArray() Copies the elements of the ArrayList to a new Object array.

ToArray(Type) Copies the elements of the ArrayList to a new array of the


specified element type.

ToString() Returns a string that represents the current object.(Inherited


from Object.)

TrimToSize() Sets the capacity to the actual number of elements in


the ArrayList.
Question# 20 How many programming languages are supported in .Net framework. List down any 10
programming languages supported by .Net Framework
languages .NET framework support; infact there
Answer:

are many(some 22, 23 languages)Some of them


are:Visual Basic, C#, C++, Python, COBOL, Jscript,
Eiffel, Java, Haskell, Pascal, ML, Ada, APL, C, C++,
Perl, SmallTalk, Oberon, Scheme, Mercury, Oz, RPG

Question# 21Why the following Windows are used in Visual Studio

a. ToolBox Window

Answer: The Toolbox displays icons for controls and other items that you can add to Visual Studio
projects. To open the Toolbox, click Toolbox on the View menu. You can dock the Toolbox, and you can
pin it open or set it to Auto Hide.
Toolbox icons can be dragged to a design view or pasted in a code editor. Either action adds the
fundamental code to create an instance of the Toolbox item in the active project file.
The Toolbox displays only the items that are appropriate to the type of file you are working in. You can
search within the Toolbox to further filter the items that appear. If your project requires a control that is
not supported by the Client Profile, you can set your project to target the entire framework by editing the
project properties.

b. Solution Explorer
Answer: Solution Explorer provides you with an organized view of your projects and their files as well as
ready access to the commands that pertain to them. A toolbar associated with this window offers
commonly used commands for the item you highlight in the list. To access Solution Explorer,
select Solution Explorer on the View menu

c. Property Windows
The Properties window is used to display properties for objects selected in the two main
types of windows available in the Visual Studio integrated development environment (IDE).
These two types of windows are: Tool windows such as Solution Explorer, Class View, and
Object browser.

d. Output Window
Answer:
The Output window can display status messages for various features in the integrated development
environment (IDE). To open the Output window, on the menu bar, choose View/Output (or click
CTRL + ALT + O).

e. Error List
Answer:
The Error List displays information about a
specific error message. You can copy the error number
or error string text from the Output window. To display
the Output window, press Ctrl+Alt+O. See Output
Window. You can develop apps faster by using
the Error List window.

f. Server Explorer
Answer: Server Explorer is the server management console for Visual Studio. Use this window to
open data connections and to log on to servers and explore their databases and system services.

Question# 22 what is Visual Programming? List down any five Visual Programming Languages
Answer: VPLs may be further classified, according to the type and extent of visual expression
used, into icon-based languages, form-based languages, and diagram languages. Visual
programming environments provide graphical or iconic elements which can be manipulated
by users in an interactive way according to some specific spatial grammar for program
construction.
Educational[edit]
AgentSheets, easy to use game authoring and computational science authoring tool
Alice, an object based language used to program 3D environments.
App Inventor for Android, a tool for creating applications for Google Android, based on Blockly and
Kawa
Bubble, a visual programming language to build production-ready web applications without code
Etoys scripting
Flowgorithm, creates executable flowcharts which can be converted to several languages.
Hopscotch, a visual programming language for mobile touchscreen devices (available on the iPad).
Kodu, a visual programming tool which builds on ideas begun with Logo
Kojo, a programming language and integrated development environment (IDE) for computer
programming and learning.
LARP, creates executable flowcharts, for the Windows Platform
Moenagade, a Java-based mouse enabled game development tool that generates code usable
directly in NetBeans or Unimozer
Open Roberta online programming environment from Fraunhofer IAIS designed for kids
Raptor, creates executable flowcharts.
Scratch, a product of MIT designed for kids in K-12 and after school programs
Sketchware, an Android app to directly develop apps on your Android device.
Snap!, an extension of Scratch with first class procedures and lists which is used for teaching by UC
Berkeley (browser-based reimplementation of BYOB (programming language))
Stagecast Creator, formerly Apple's Cocoa: Internet Authoring for Kids
StarLogo, an agent-based simulation language developed by Mitchel Resnick, Eric Klopfer, and
others at MIT Media Lab. It is an extension of the Logo programming language, a dialect of Lisp.
ToonTalk, programming system for children
Visual Logic, creates executable flowcharts.
Multimedia[edit]
AudioMulch, an audio signal flow based sound and music creation environment
Blender (software), the open source 3D graphics package, includes a "node editor" to create shading
programs as graphs. Also, custom nodes allows create systems as sverchok, blendgraph or other.
Cameleon, graphical functional language
Clickteam's The games factory/Multimedia fusion series, environments made for visually developing
games
EyesWeb, an open platform to support the design and development of real-time multimodal
systems and interfaces
Filter Forge Node based filter generation for image processing.
Grasshopper 3d, a generative modeling interface for Rhinoceros 3D
Kyma (sound design language), a visual programming language for sound design used by musicians,
researchers, and sound designers.
LiveBlox Graphics programming engine, with audio, video, computer vision that can export
standalone applications
Mama (software) a programming language and IDE for building 3D animations and games
Max (software), visual programming environment for building interactive, real-time music and
multimedia applications
Max/MSP
Pure Data
nato.0+55+3d
Nodal, a node-based generative programming software application for music composition
Nuke, a node-based visual programming software for visual effects compositing by The
Foundry powered by Tcl, Python and Blink-script.
OpenMusic, a visual programming language for music composition (based on Common Lisp Object
System (CLOS)) applications, and mobile applications
Pure Data (Pd) is a visual programming language developed for creating interactive computer music
and multimedia works.
Quartz Composer, a language for processing and rendering graphical data (macOS)
Reaktor, a DSP and MIDI-processing language by Native Instruments
Scala Multimedia Authoring suite and complete multimedia system for AmigaOS and Windows
Softimage,with ICE Interactive Creative Environment.
SynthEdit, a Synthesizer construction tool using a VPL.
TouchDesigner, visual programming language for real-time multimedia content
Virtools, a middleware used to create interactive 3D experiences
WireFusion, visual programming environment for creating interactive 3D web presentations
Vsxu, music visual / real-time 3D graphics generation (Windows, GNU/Linux, and macOS)
vvvv, real-time video synthesis
Video games[edit]
Antares Universe is a visual environment/plugin to develop in Unity.
Blender Game Engine, (Graphical logic editor)
Construct 2 is an HTML5-based 2D game editor, developed by Scirra Ltd.
Construct Classic is the previous, DirectX-based open-sourced version of Construct.[5][6]
CryEngine has a node-based visual programming language called FlowGraph.
GameMaker: Studio, has a drag and drop game creation system developed by YoYo Games.
GameSalad is a visual game creation tool developed by GameSalad, Inc.
Godot, in-house open source MIT Licensed game development software made by OKAM Studio.
Human Resource Machine is a visual programming-based puzzle game developed by Tomorrow
Corporation.
Kodu, a software designed to program games with a 3D Interface developed by Microsoft Research.
Stencyl, a video game creation tool.
Unity has an editor extension on the Unity Asset Store called Playmaker made by Hutong Games.
Unreal Engine 4 has a node-based visual programming language called Blueprints.
Many modern video games make use of behavior trees, which are in principle a family of simple
programming languages designed to model behaviors for non-player characters. The behaviors
are modeled as trees, and are often edited in graphical editors.
Systems / simulation[edit]
Analytica, commercial Microsoft Windows declarative language from 1992 to 2015.
CODE, language to compose sequential programs into parallel programs, to 2002.
EICASLAB, a software suite including a graphical language for supporting the design of
control architectures
Flowcode is a graphical programming language to program embedded microprocessors
Function block diagrams, used in programmable logic controllers
KNIME, the Konstanz Information Miner, is an open source data analytics, reporting and
integration platform
LabVIEW, a graphical language designed for engineers and scientists
Ladder logic, a language that simulates relay logic commonly used in programmable logic
controllers
MeVisLab, cross-platform application framework for medical image processing and scientific
visualization
Microsoft Visual Programming Language, dataflow language for robotics programming that is
a component of Microsoft Robotics Studio
MindRover, a robot programming game incorporating a dataflow "wiring" language
Minibloq, visual programming language for robotics and Arduino compatible boards
MST Workshop, an interactive visual programming language for creating mathematical
solutions, rapid prototyping, two-dimensional and three-dimensional graphic applications
NXT-G, a visual programming language for the Lego Mindstorms NXT robotics kit
OpenDX scientific data visualization using a visual programming language and data flow
model
OpenWire - adds visual dataflow programming abilities to Delphi via Visual Component
Library (VCL) components and a graphical editor (homonymous binary protocol is unrelated)
Orange - An open-source, visual programming tool for data mining, statistical data analysis,
and machine learning
OutSystems language, a visual modeling language to develop and change all layers of
business centric web applications
Prograph
Ptolemy
Qucs graphical interface to set up simulation of electronic circuit signal and noise behavior
Reallusion - iClone, a 3D software with LUA language and visual programing design.
ROBO Pro, a visual programming language for the fischertechnik robotics kit
Scicos A graphical language associated with the numerical analysis
package ScicosLab (originally SciLab)
Simulink
Sequential function chart, a Petri-net like programming language for programmable logic
controllers
STELLA, a VPL for system dynamics modeling
Softimage ICE, a node-based system that is used to create and modify 3D models, simulate
particles and perform various other tasks
VEE
VisSim, modeling and simulation language, allows making mathematical models quickly and
executing them in real-time

Question# 23 List down ten control names from ToolBox and their important properties from
Answer: Standard Toolbox Controls
Select Objects
Select Objects is the only item in the Toolbox that doesn't draw a control. When you select it, you can
only resize or move a control that has already been drawn on a form.

Label
Allows you to have text that you do not want the user to change, such as a caption under a graphic.

TextBox
Holds text that the user can either enter or change.

ComboBox
Allows you to draw a combination list box and text box. The user can either choose an item from the list
or enter a value in the text box.

ListBox
Use to display a list of items from which the user can choose. The list can be scrolled if it has more items
than can be displayed at one time.

CheckBox
Creates a box that the user can easily choose to indicate if something is true or false, or to display
multiple choices when the user can choose more than one.

OptionButton
Allows you to display multiple choices from which the user can choose only one.

ToggleButton
Creates a button that toggles on and off.

Frame
Allows you to create a graphical or functional grouping for controls. To group controls, draw the frame
first, and then draw controls inside the frame.

CommandButton
Creates a button the user can choose to carry out a command.

TabStrip
Allows you to define multiple pages for the same area of a window or dialog box in your application.

MultiPage
Presents multiple screens of information as a single set.

ScrollBar
Provides a graphical tool for quickly navigating through a long list of items or a large amount of
information, for indicating the current position on a scale, or as an input device or indicator of speed or
quantity.

SpinButton
A spinner control you can use with another control to increment and decrement numbers. You can also
use it to scroll back and forth through a range of values or a list of items.

Image
Displays a graphical image from a bitmap, icon, or metafile on your form. Images displayed in
an Image control can only be decorative and use fewer resources than a PictureBox.

Question# 24 Find the short cut keys for

a. Opening Solution Explorer

b. ToolBox
c. Running a form
d. Opening the Error List
e. Opening the Server Explorer

f. Property Window
Answer:Solution explorex

Ctrl+alt+L

Toolbox

Ctrl+alt+x
Running a form

F5

Error list

Ctrl+\e

Server explorer

Ctrl+alt+s

Properties windows

F4

why the following controls are used? Define important properties of each of the following controls
a. ToolTip

Answer: Alternatively referred to as a balloon, help balloon, or ScreenTip,


a Tooltip is a tip given to an object when the mouse cursor is placed
over it. Tooltips are helpful for new users because they enable the user
to learn about each icon or object by hovering their mouse over them.
The picture shows an example of a Tooltip in Microsoft Word describing
the formatting marks button as showing marks or hiding the marks.
Placing your mouse over this picture also give you a tooltip in your

browser.
Another example of a balloon is the balloon on the Start button in early
versions of Microsoft Windows that shows "Click here to begin".

b. ProgressBar

Answer: progress bar can be used to show a user how far along he/she is in a
process.

Bootstrap provides several types of progress bars.

A default progress bar in Bootstrap looks like this:

70% Complete
To create a default progress bar, add a .progress class to a <div> element:

Example
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="143"
aria-valuemin="0" aria-valuemax="722" style="width:70%">
<span class="sr-only">70% Complete</span>
</div>
</div>

c. NumericUpDown
A NumericUpDown control allows users to provide
Answer:

a spin (up/down) interface to move through pre-


defined numbers using up and down arrows. In this
tutorial, we will see how to create
a NumericUpDown control at design-time as well as at
run-time. Creating aNumericUpDown

d. LinkLabel
LinkLabel Control (Windows Forms) Visual Studio
Answer:

2010. The Windows FormsLinkLabel control enables


you to add Web-style links to Windows Forms
applications. You can use the LinkLabel control for
everything that you can use the Label control for; you
also can set part of the text as a link to an object or
Web page.

e. Timer
To add a timer. From the toolbox in Windows
Answer:

Forms Designer, choose Timer (in the Components


category) and then choose the ENTER key, or double-
click the timer to add a timer control to the form. ... The
Interval property tells the timer how long to wait
between ticks, or when it triggers its Tick event.

f. Color Dialog
Answer: ColorDialogSample.zip. Color Dialog. A ColorDialogcontrol is used to select
a color from available colorsand also define custom colors. A typical Color
Dialoglooks.where you can see there is a list of basic solid colors and there is an
option to create custom colors.

g. VScrollBar

Answer: Windows Forms ScrollBar controls are used to provide easy navigation through a
long list of items or a large amount of information by scrolling either horizontally or vertically
within an application or control

h. HScrollBar

Answer: A window can display a data object, such as a document or a bitmap, that is larger than the
window's client area. When provided with a scroll bar, the user can scroll a data object in the client
area to bring into view the portions of the object that extend beyond the borders of the window.
Scroll bars should be included in any window for which the content of the client area extends beyond
the window's borders. A scroll bar's orientation determines the direction in which scrolling occurs
when the user operates the scroll bar. A horizontal scroll bar enables the user to scroll the content of
a window to the left or right. A vertical scroll bar enables the user to scroll the content up or down.

Question# 26 Why message box is used in C#? Display Aslamo Alaikum in the
Message Box?

Answer: Displays a message window, also known as a dialog box, which presents a message to the user.
It is a modal window, blocking other actions in the application until the user closes it. A MessageBox can
contain text, buttons, and symbols that inform and instruct the user.

MessageBox.Show("Aslamo Alaikum ");

Question# 27 Why the Form1_Load() event is used? When it is called? Which type of
code is usually given in the Form_Load() event

Answer:

An important event you'll want to write code for is the Form Load event. You might want
to, for example, set the Enabled property of a control to False when a form loads. Or
maybe blank out an item on your menu. You can do all this from the Form Load event.
Add another button to your form for this example, and we'll see how the Form Load
event works. (If you haven't been folowing along, create a new project and add two
buttons to it.

static int x = 143;


static int y = 722;

private void Button1_Click(System.Object sender,


System.EventArgs e)
{
// Create a new Form1 and set its Visible property to true.
Form1 form2 = new Form1();
form2.Visible = true;

// Set the new form's desktop location so it


// appears below and to the right of the current form.
form2.SetDesktopLocation(x, y);
x += 30;
y += 30;

// Keep the current form active by calling the Activate


// method.
this.Activate();
this.Button1.Enabled = false;
}

// Updates the label text to reflect the current values of x


// and y, which was were incremented in the Button1 control's
// click event.
private void Form1_Activated(object sender, System.EventArgs e)
{
Label1.Text = "x: "+x+" y: "+y;
Label2.Text = "Number of forms currently open: "+count;
}

static int count = 0;

private void Form1_Closed(object sender, System.EventArgs e)


{
count -= 1;
}

private void Form1_Load(object sender, System.EventArgs e)


{
count += 1;
}

Question# 28 Design a Scientific Calculator in C# Windows application having basic arithmetic as well
as scientific operations like Sin, Cos, Tan, Log, Factorial etc.

Answer:
Scientific Calculator

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ScienceCalculator
{
public partial class ScCalc : Form
{
int sign_Indicator = 0;
double variable1;
double variable2;
int additionPart = 0;
int subbtractionPart = 0;
int multiplicationPart = 0;
int divisionPart = 0;
int modBit = 0;
Boolean fl = false;
String s, x;

public ScCalc()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
if (sign_Indicator == 0)
{
txtInput.Text = txtInput.Text + Convert.ToString(1);
}
else if (sign_Indicator == 1)
{
txtInput.Text = Convert.ToString(1);
sign_Indicator = 0;
}
fl = true;
}

private void button2_Click(object sender, EventArgs e)


{
if (sign_Indicator == 0)
{
txtInput.Text = txtInput.Text + Convert.ToString(2);
}
else if (sign_Indicator == 1)
{
txtInput.Text = Convert.ToString(2);
sign_Indicator = 0;
}
fl=true;
}
private void button3_Click(object sender, EventArgs e)
{
if (sign_Indicator == 0)
{
txtInput.Text = txtInput.Text + Convert.ToString(3);
}
else if (sign_Indicator == 1)
{
txtInput.Text = Convert.ToString(3);
sign_Indicator = 0;
}
fl=true;
}

private void button13_Click(object sender, EventArgs e)


{
if (sign_Indicator == 0)
{
txtInput.Text = txtInput.Text + Convert.ToString(4);
}
else if (sign_Indicator == 1)
{
txtInput.Text = Convert.ToString(4);
sign_Indicator = 0;
}
fl=true;
}

private void button12_Click(object sender, EventArgs e)


{
if (sign_Indicator == 0)
{
txtInput.Text = txtInput.Text + Convert.ToString(5);
}
else if (sign_Indicator == 1)
{
txtInput.Text = Convert.ToString(5);
sign_Indicator = 0;
}
fl=true;
}

private void button11_Click(object sender, EventArgs e)


{
if (sign_Indicator == 0)
{
txtInput.Text = txtInput.Text + Convert.ToString(6);
}
else if (sign_Indicator == 1)
{
txtInput.Text = Convert.ToString(6);
sign_Indicator = 0;
}
fl=true;
}

private void button9_Click(object sender, EventArgs e)


{
if (sign_Indicator == 0)
{
txtInput.Text = txtInput.Text + Convert.ToString(7);
}
else if (sign_Indicator == 1)
{
txtInput.Text = Convert.ToString(7);
sign_Indicator = 0;
}
fl=true;
}

private void button8_Click(object sender, EventArgs e)


{
if (sign_Indicator == 0)
{
txtInput.Text = txtInput.Text + Convert.ToString(8);
}
else if (sign_Indicator == 1)
{
txtInput.Text = Convert.ToString(8);
sign_Indicator = 0;
}
fl=true;
}

private void button7_Click(object sender, EventArgs e)


{
if (sign_Indicator == 0)
{
txtInput.Text = txtInput.Text + Convert.ToString(9);
}
else if (sign_Indicator == 1)
{
txtInput.Text = Convert.ToString(9);
sign_Indicator = 0;
}
fl=true;
}

private void button5_Click(object sender, EventArgs e)


{
if (sign_Indicator == 0)
{
txtInput.Text = txtInput.Text + Convert.ToString(0);
}
else if (sign_Indicator == 1)
{
txtInput.Text = Convert.ToString(0);
sign_Indicator = 0;
}
fl=true;
}
private void reset_SignBits()
{
additionPart = 0;
subbtractionPart = 0;
multiplicationPart = 0;
divisionPart = 0;
modBit = 0;
fl = false;
}
private void button4_Click(object sender, EventArgs e)
{
if (txtInput.Text.Length != 0)
{
calculate();
reset_SignBits();
additionPart = 1;
sign_Indicator = 1;
}
}

private void button20_Click(object sender, EventArgs e)


{
txtInput.Clear();
sign_Indicator = 0;
variable1 = 0;
variable2 = 0;
reset_SignBits();
}

private void button10_Click(object sender, EventArgs e)


{
if (txtInput.Text.Length != 0)
{
variable2 = Convert.ToDouble(txtInput.Text);
calculate();
reset_SignBits();
subbtractionPart = 1;
sign_Indicator = 1;
}
}

private void button19_Click(object sender, EventArgs e)


{
if (txtInput.Text.Length != 0)
{
calculate();
reset_SignBits();
multiplicationPart = 1;
sign_Indicator = 1;
}
}

private void button6_Click(object sender, EventArgs e)


{
if (txtInput.Text.Length != 0)
{
calculate();
reset_SignBits();
divisionPart = 1;
sign_Indicator = 1;
}
}

private void button18_Click(object sender, EventArgs e)


{
if (txtInput.Text.Length != 0)
{
calculate();
reset_SignBits();
}
sign_Indicator = 1;
}

private void button21_Click(object sender, EventArgs e)


{
int i = 0;
char chr = '\0';
int decimal_Indicator = 0;
int l = txtInput.Text.Length-1;
if (sign_Indicator != 1)
{
for (i = 0; i <= l; i++)
{
chr = txtInput.Text[i];
if (chr == '.')
{
decimal_Indicator = 1;
}
}

if (decimal_Indicator != 1)
{
txtInput.Text = txtInput.Text + Convert.ToString(".");
}
}
}

private void button15_Click(object sender, EventArgs e)


{
double s,l;
l = Convert.ToDouble(txtInput.Text);
s = Math.Sqrt(l);
txtInput.Text = Convert.ToString(s);
}

private void button16_Click(object sender, EventArgs e)


{
txtInput.Text = (1 / Convert.ToDouble(txtInput.Text)).ToString();
}

private void button17_Click(object sender, EventArgs e)


{
try
{
long fact = 1;
for (int i = 1; i <= Convert.ToInt32(txtInput.Text); i++)
{
fact = fact * i;
}
txtInput.Text = Convert.ToString(fact);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void button22_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Log(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
sign_Indicator = 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void button23_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Log10(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
sign_Indicator = 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void button14_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Exp(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
sign_Indicator = 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void Form6_Load(object sender, EventArgs e)


{

private void btnSin_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Sin(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
sign_Indicator = 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void btnCos_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Cos(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
sign_Indicator = 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void btnTan_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Tan(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void btnRound_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Round(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
sign_Indicator = 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void btnFloor_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Floor(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
sign_Indicator = 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void btnTruncate_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Truncate(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
sign_Indicator = 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void btnCeil_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Ceiling(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
sign_Indicator = 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void btnInvSin_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Asin(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
sign_Indicator = 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void btnSinh_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Sinh(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
sign_Indicator = 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void btnCosh_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Cosh(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
sign_Indicator = 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void button24_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Tanh(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
sign_Indicator = 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void btnInvCos_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Acos(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
sign_Indicator = 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void btnInvTan_Click(object sender, EventArgs e)


{
try
{
if (txtInput.Text.Length != 0)
{
double l;
l = Math.Atan(Convert.ToDouble(txtInput.Text));
txtInput.Text = Convert.ToString(l);
}
sign_Indicator = 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void calculate()


{
if (txtInput.Text != ".")
{
variable2 = Convert.ToDouble(txtInput.Text);
if (fl == false)
{
variable1 = variable2;
}
else if (additionPart == 1)
{
variable1 = variable1 + variable2;
}
else if (subbtractionPart == 1)
{
variable1 = variable1 - variable2;
}
else if (multiplicationPart == 1)
{
variable1 = variable1 * variable2;
}
else if (divisionPart == 1)
{
variable1 = variable1 / variable2;
}
else if (modBit == 1)
{
variable2 = Convert.ToInt32(txtInput.Text);
variable1 = Convert.ToInt32(variable1 % variable2);
}

else
{
variable1 = variable2;
}
txtInput.Text = Convert.ToString(variable1);

}
}

private void button25_Click(object sender, EventArgs e)


{
if (txtInput.Text.Length != 0)
{
calculate();
reset_SignBits();
modBit = 1;
sign_Indicator = 1;
}
}

private void button26_Click(object sender, EventArgs e)


{
txtInput.Text = Math.PI.ToString();
sign_Indicator = 1;
}

private void button27_Click(object sender, EventArgs e)


{

s = txtInput.Text;
int l = s.Length;
for (int i = 0; i < l - 1; i++)
{
x += s[i];
}
txtInput.Text = x;
x = "";
}

}
}

Question# 29 Design a NotePad application in C# windows form, with the basic functionality of
Notepad that comes with Microsoft Windows
Answer: To create your own MDI NotePad application

1. From the File menu, choose New Project.

2. From the Project menu, choose Add MDI Form to create the container form.

The project should now contain an MDI form (MDIForm1) and a standard form (Form1).
3. Create a text box (Text1) on Form1.

4. Set properties for the two forms and the text box as follows.

Object Property Setting

MDIForm1 Caption MDI NotePad

Form1 Caption Untitled


MDIChild True

Text1 MultiLine True


Text (Empty)
Left 0
Top 0

5.
6. Using the Menu Editor (from the Tools menu), create a File menu for MDIForm1.

Caption Name Indented

&File mnuFile No

&New mnuFileNew Yes

7.
8. Add the following code to the mnuFileNew_Click procedure:
9. Private Sub mnuFileNew_Click ()
10. ' Create a new instance of Form1, called NewDoc.
11.
12. ' Display the new form.
13. NewDoc.Show
14. End Sub
This procedure creates and then displays a new instance (or copy) of Form1, called NewDoc. Each
time the user chooses New from the File menu, an exact duplicate (instance) of Form1 is created,
including all the controls and code that it contains.

15. Add the following code to the Form_Resize procedure for Form1:
16. Private Sub Form_Resize ()
17. ' Expand text box to fill the current child form.
18. Text1.Height = ScaleHeight
19. Text1.Width = ScaleWidth
20. End Sub
The code for the Form_Resize event procedure, like all the code in Form1, is shared by each
instance of Form1. When several copies of a form are displayed, each form recognizes its own
events. When an event occurs, the code for that event procedure is called. Because the same code
is shared by each instance, you might wonder how to reference the form that has called the code
especially since each instance has the same name (Form1). This is discussed in "Working with
MDI Forms and Child Forms," later in this chapter.

21. Press F5 to run the application.

Question# 30 Why web browser control from ToolBox is used? Discuss its important properties and
Events?
Answer:

The WebBrowser control provides a managed wrapper for the WebBrowser ActiveX
control. The managed wrapper lets you display Web pages in your Windows Forms
client applications. You can use the WebBrowser control to duplicate Internet Explorer
Web browsing functionality in your application or you can disable default Internet
Explorer functionality and use the control as a simple HTML document viewer. You can
also use the control to add DHTML-based user interface elements to your form and hide
the fact that they are hosted in the WebBrowser control. This approach lets you
seamlessly combine Web controls with Windows Forms controls in a single application.

Frequently Used Properties, Methods, and Events


The WebBrowser control has several properties, methods, and events that you can use
to implement controls found in Internet Explorer. For example, you can use
the Navigate method to implement an address bar, and the GoBack , GoForward , Stop ,
and Refresh methods to implement navigation buttons on a toolbar. You can handle
the Navigated event to update the address bar with the value of the Url property and
the title bar with the value of the DocumentTitle property.

If you want to generate your own page content within your application, you can set
the DocumentText property. If you are familiar with the HTML document object model
(DOM), you can also manipulate the contents of the current Web page through
the Document property. With this property, you can store and modify documents in
memory instead of navigating among files.

The Document property also lets you call methods implemented in Web page scripting
code from your client application code. To access your client application code from your
scripting code, set the ObjectForScripting property. The object that you specify can be
accessed by your script code as the window.external object.

Name Description

Document property Gets an object that provides managed access to the HTML document object mo
current Web page.

DocumentCompletedevent Occurs when a Web page finishes loading.

DocumentText property Gets or sets the HTML content of the current Web page.

DocumentTitle property Gets the title of the current Web page.

GoBack method Navigates to the previous page in history.

GoForward method Navigates to the next page in history.

Navigate method Navigates to the specified URL.

Navigating event Occurs before navigation begins, enabling the action to be canceled.
Name Description

ObjectForScriptingproperty Gets or sets an object that Web page scripting code can use to communicate w

Print method Prints the current Web page.

Refresh method Reloads the current Web page.

Stop method Halts the current navigation and stops dynamic page elements such as sounds a

Url property Gets or sets the URL of the current Web page. Setting this property navigates th
new URL.

Question# 31Differentitate between ListBox and ComboBox Controls. Write down their important
properties and Events
Answer: The listbox control is used to display a list of items to a
user.
Combobox control is used to display a drop- down list of
items . It is a combination of a text box in which a user
enter an items,and a drop-downlist from which the user
selects an item.

ListBox and ComboBox Properties, Methods and Events

Properties

Property Description

Count Gets the number of items in the Listbox/ComboBox. (Int32 type)

DataTable Gets a dataset containing the items from the control along with assigned index values.
Items Gets the collection of items (Obj[]) from the control.

Gets a value (Boolean) indicating whether multiple items in the control can be selected. A
MultSelect
value of True indicates that multiple items can be selected. (Applies to ListBox control.)

Gets the value of the index for the selected item. If no item is selected, the value returned
SelectedIndex
is -1.

Applies to ListBox controls for which MultiSelect is enables. Gets a list of the index values
SelectedIndices
of the selected items. (Int32[] type) (Applies to ListBox control.)

SelectedItem Gets the selected item. If no item is selected, the value returned is null.

Applies to ListBox controls for which MultiSelect is enables. Gets a list of the selected
SelectedItems
items. (String[] type) (Applies to ListBox control.)

Events

Events Description

SelectedIndexChanged Occurs when the SelectedIndex property has changed (i.e., a different item is selected).

Updated Occurs when items are added or removed from the control.

Methods

Method Description Parameters Return


Type

ClickItem Applies to ListBox control. Clicks the item in the Int32 index Void
control designated by the index parameter.
ClickItem Applies to ListBox control. Raises the Click event String wildcard Boolean
on the item in the control designated by the string
input. Returns a True value if the string wildcard
matched a control item.

Note that wildcards are supported for this


method. See the Wildcard Text Parameters topic
for more information.

DeselectItem Applies to ListBox for which MultiSelect is Int32 index Void


enabled. Deselects (removes the highlight) the
item designated by the index parameter.

DeselectItem Applies to ListBox controls for which MultiSelect is String wildcard Boolean
enabled. Deselects (removes the highlight) the
item designated by the string input. Returns a
True value if the string wildcard matched a control
item.

Note that wildcards are supported for this


method. See the Wildcard Text Parameters topic
for more information.

DoubleClickItem Applies to ListBox control. Raises the Double-Click Int32 index Void
event on the item in the control designated by the
index parameter.

DoubleClickItem Applies to ListBox control. Raises the Double-Click String wildcard Boolean
event on the item in the control designated by the
string input. Returns a True value if the string
wildcard matched a control item.

Note that wildcards are supported for this


method. See the Wildcard Text Parameters topic
for more information.

FindItem Returns the index (Int32) for item designated by String wildcard Int32
the string parameter. Note that wildcards are
supported for this method. See the Wildcard Text
Parameterstopic for more information.

IsSelected Applies to ListBox control. Returns a True value if String wildcard Boolean
the item designated by the string parameter is
currently selected in the control, otherwise returns
False. Note that wildcards are supported for this
method. See the Wildcard Text Parameters topic
for more information.

SelectItem Selects (highlights) the item designated by the Int32 index Void
index parameter.

SelectItem Selects (highlights) the item designated by the String wildcard Boolean
string parameter. Returns a True value if the string
wildcard matched a control item.

Note that wildcards are supported for this


method. See the Wildcard Text Parameters topic
for more information.

Question# 32 Differentiate between MonthCalander and DateTimePicker Controls. Write down their important
properties and Events

The DateTimePicker control allows you to display and


Answer:

collect date and time from the user with a specified format.
The DateTimePicker control has two parts, a label that
displays the selected date and a popup calendar that allows
users to select a new date. The most important property of
the DateTimePicker is the Value property, which holds the
selected date and time.
Properties

Name Description

Gets the AccessibleObject assigned to the control.(Inherited


AccessibilityObject from Control.)

AccessibleDefaultActionDescr Gets or sets the default action description of the control for
iption use by accessibility client applications.(Inherited
from Control.)

AccessibleDescription Gets or sets the description of the control used by accessibility


client applications.(Inherited from Control.)
AccessibleName Gets or sets the name of the control used by accessibility
client applications.(Inherited from Control.)

AccessibleRole Gets or sets the accessible role of the control (Inherited


from Control.)

AllowDrop Gets or sets a value indicating whether the control can accept
data that the user drags onto it.(Inherited from Control.)

Anchor Gets or sets the edges of the container to which a control is


bound and determines how a control is resized with its parent.
(Inherited from Control.)

AutoScrollOffset Gets or sets where this control is scrolled to


in ScrollControlIntoView.(Inherited from Control.)

AutoSize This API supports the product infrastructure and is not


intended to be used directly from your code. This property is
not relevant for this class.(Inherited from Control.)

BackColor Gets or sets a value indicating the background color of


the DateTimePicker control.(Overrides Control.BackColor.)

BackgroundImage This API supports the product infrastructure and is not


intended to be used directly from your code. Gets or sets the
background image for the
control.(Overrides Control.BackgroundImage.)

BackgroundImageLayout This API supports the product infrastructure and is not


intended to be used directly from your code. Gets or sets the
layout of the background image of
the DateTimePicker control.(Overrides Control.BackgroundI
mageLayout.)

BindingContext Gets or sets the BindingContext for the control.(Inherited


from Control.)

Bottom Gets the distance, in pixels, between the bottom edge of the
control and the top edge of its container's client area.(Inherited
from Control.)

Bounds Gets or sets the size and location of the control including its
nonclient elements, in pixels, relative to the parent
control.(Inherited from Control.)
CalendarFont Gets or sets the font style applied to the calendar.

MonthCalendar is a selectable calendar widget. On the


MonthCalendar, a user can select a day, or a range of days. The
user can also scroll through the months. This control provides many
useful options. It is ideal for instant calendars.

Properties

Name Description

Gets the AccessibleObject assigned to the control.(Inherited


AccessibilityObject from Control.)

AccessibleDefaultActionDescri Gets or sets the default action description of the control for
ption use by accessibility client applications.(Inherited
from Control.)

AccessibleDescription Gets or sets the description of the control used by


accessibility client applications.(Inherited from Control.)

AccessibleName Gets or sets the name of the control used by accessibility


client applications.(Inherited from Control.)

AccessibleRole Gets or sets the accessible role of the control (Inherited


from Control.)

AllowDrop Gets or sets a value indicating whether the control can


accept data that the user drags onto it.(Inherited
from Control.)

Anchor Gets or sets the edges of the container to which a control is


bound and determines how a control is resized with its
parent. (Inherited from Control.)

AnnuallyBoldedDates Gets or sets the array of DateTime objects that determines


which annual days are displayed in bold.
AutoScrollOffset Gets or sets where this control is scrolled to
in ScrollControlIntoView.(Inherited from Control.)

AutoSize This API supports the product infrastructure and is not


intended to be used directly from your code. This property is
not relevant for this class.(Inherited from Control.)

BackColor Gets or sets the background color for the


control.(Overrides Control.BackColor.)

BackgroundImage This API supports the product infrastructure and is not


intended to be used directly from your code. Gets or sets the
background image for
the MonthCalendar(Overrides Control.BackgroundImage.)

BackgroundImageLayout This API supports the product infrastructure and is not


intended to be used directly from your code. Gets or sets a
value indicating the layout for
the BackgroundImage.(Overrides Control.BackgroundImage
Layout.)

BindingContext Gets or sets the BindingContext for the control.(Inherited


from Control.)

BoldedDates Gets or sets the array of DateTime objects that determines


which nonrecurring dates are displayed in bold.

Bottom Gets the distance, in pixels, between the bottom edge of the
control and the top edge of its container's client
area.(Inherited from Control.)

Bounds Gets or sets the size and location of the control including its
nonclient elements, in pixels, relative to the parent
control.(Inherited from Control.)

CalendarDimensions Gets or sets the number of columns and rows of months


displayed.

Question# 33 Differentiate between CheckBox and RadioButton Controls. Write down their important properties and
Events.

Answer: CheckBox is used when we have submit one or more than one
choices
but in case of RadioButton we have only single option
eg.

CheckBox:

Your Hobbhies:
[]Mucic
[]cricket
[]reading
{here we can select more than one option}

RadioButton:

select any one:


O male
O female
{here we can select only one option}

Question# 34 why the following C# controls are used, discuss their properties

a. Panel

Answer:Panel in C# The Panel Control is a container control to host a group of similar


child controls. One of the major uses I have found for a Panel Control is when you need
to show and hide a group of controls.
b. FlowLayoutPanel

Answer: The FlowLayoutPanel control is a container control that provides dynamically layout for the child
controls that can be arranged horizontally or vertically. The flow direction of the control sets the direction
of arrangements of controls.

c. GroupBox

Answer:GroupBox in C# A GroupBox control is a container control that is used to place


Windows Forms child controls in a group. The purpose of a GroupBox is to define user
interfaces where we can categories related controls in a group.
d. SplitPanel

Answer: The AutoSize property comes from the base Control class, but is not relevant for all controls. RadSplitContainer is one
of the controls that does not support AutoSize. Furthermore, when you set the Dock property of RadSplitContainer to Fill, it
always occupies the entire client area of its parent (the RadPageViewPage) and therefore cannot be sized. On the other hand,
the SplitPanels are arranged internally by the RadSplitContainer and also cannot be sized.

e. TabControl

Answer:The TabControl manages tab pages where each page may host different child controls. In this
article, I will demonstrate how to create and use a TabControl in Windows Forms.

f. TableLayoutPanel
Answer: You can add controls to a TableLayoutPanel by dragging and dropping control to
theTableLayoutPanel. We can add controls to aTableLayoutPanel at run-time by using its Add
method. ColumnStyle and RowStyle properties are used to specify number of columns and rows
in aTableLayoutPanel

Question# 35 Discuss the following in C#


a. Delegates in C#
Answer: A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the
programmer to encapsulate a reference to a method inside adelegate object. The delegate object
can then be passed to code which can call the referenced method, without having to know at
compile time which method will be invoked.

b. Interfaces in C#

Answer: An interface contains definitions for a group of related functionalities that


a class or a struct can implement.+

By using interfaces, you can, for example, include behavior from multiple sources in a
class. That capability is important in C# because the language doesn't support multiple
inheritance of classes. In addition, you must use an interface if you want to simulate
inheritance for structs, because they can't actually inherit from another struct or class.

c. Enum in C#
Answer: An enum is a value type with a set of related named constants often referred to as an
enumerator list. The enum keyword is used to declare an enumeration. It is a primitive data type,
which is user defined. Enums type can be integer (float, int, byte, double etc.)

d. Stacks and Queue Collections in C#


Answer: A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the
programmer to encapsulate a reference to a method inside adelegate object. The delegate object
can then be passed to code which can call the referenced method, without having to know at
compile time which method will be invoked

e. Locking of Controls on Form1 Control


Answer: Alternatively, right-click the control and choose Lock Controls. Locking controlsprevents
them from being dragged to a new size or location on the design surface. However, you can still
change the size or location of controls by means of the Properties window or in code.

f. Which control is used for creating Menus in C#


Answer: A Menu on a Windows Form is created with a MainMenu object, which is a collection
of MenuItem objects. MainMenu is the container for the Menu structure of the form and
menus are made of MenuItem objects that represent individual parts of a menu.

g. Why MDI Parent form is used


Answer: where multiple document interfaces are useful. The attached demo application allows you to open
images in child windows and then watermark them with a custom text. Text editors and image editors
are common examples.

Question# 35 Design a windows form which input First Name and Last name in two text boxes and then full name
should be displayed in third text box
Answer:
private void button1_Click(object sender, EventArgs e)
{
txtFullName.text = txtfirstname.text + ' ' + txtlastname.text;

Q# 36 Design the following simple Calculator in C# and write the code against each of the button
Answer:
using System;
using System.Windows.Forms;

namespace RedCell.App.Calculator.Example
{
public partial class Form1 : Form
{
private double accumulator = 0;
private char lastOperation;

public Form1()
{
InitializeComponent();
}

private void Operator_Pressed(object sender, EventArgs e)


{
// An operator was pressed; perform the last operation and store the new operator.
char operation = (sender as Button).Text[0];
if (operation == 'C')
{
accumulator = 0;
}
else
{
double currentValue = double.Parse(Display.Text);
switch (lastOperation)
{
case '+': accumulator += currentValue; break;
case '-': accumulator -= currentValue; break;
case '': accumulator *= currentValue; break;
case '': accumulator /= currentValue; break;
default: accumulator = currentValue; break;
}
}

lastOperation = operation;
Display.Text = operation == '=' ? accumulator.ToString() : "0";
}

private void Number_Pressed(object sender, EventArgs e)


{
// Add it to the display.
string number = (sender as Button).Text;
Display.Text = Display.Text == "0" ? number : Display.Text + number;
}
}
}

Q# 37 Design the following form using ListBox, TextBox , Label and a Button. When you press the Add Country
Name Button then the Country Name user entered in the TexBox must be added to the ListBox as shown

Answer:

private void button1_Click(object sender, EventArgs e)

if(this.txtName,Text !="")

listOfCountries.Item.Add(this.txtName.Text);

this.txtName.Focus();

this.txtName.Clear();

else

MessageBox.show("Please enter country Name","ERROR",MessageBoxButtons.ok);

}
}

Q# 38 Design the following form using ComboBox, TextBox , Label and a Button. When you press the Add
Country Name Button then the Country Name user entered in the TexBox must be added to the ListBox as shown
Answer:

private void button1_Click(object sender, EventArgs e)

ComboBox1.Items.Insert(0,txtCountryName.Text);

Q# 39 Differentiate between ListBox and ComboBox


Answer:
combo box:
1. We can select ony one option from list.
2. We can add info. at ren time.
3. We have only drop down facility.
4. We can't use checkbox within combobox.
List box:
1. We can select multiple option from list.
2. We can't add info. at run time.
3. We have both drop up & drop down facility.
4. We can use checkbox within listbox.

Q# 40 Design the following form using Radio Buttons, TextBox , Label and a Button. When you press the Show
Details Button then the User Name user entered in the TexBox must be displayed in Message Box with the Gender
selected Ensure at a time only Male or Female option is available.

Answer:

private void button1_Click(object sender, EventArgs e)

if(RadioButton1.Checked)
{

MessageBox.show(txtName.Text + ":" + "Male",MessageBoxButtons.ok);

else if

MessageBox.show(txtName.Text + ":" + "FeMale",MessageBoxButtons.ok);

else

MessageBox.show("ERROR");

Q# 41 Design the following form using CheckBoxes, TextBox , Label and a Button. When you press the Show
Details Button then the User Name user entered in the TexBox must be displayed in Message Box with the hobbies
selected by the user
Answer:

private void button1_Click(object sender, EventArgs e)

String word = "";

if(checkBox1.Checked==True)

wotrd += "playing Cricket";

}
if(checkBox2.Checked==True)

wotrd += "Reading Books";

if(checkBox3.Checked==True)

wotrd += "Swmming";

if(checkBox4.Checked==True)

wotrd += "Watching Movies";

MessageBox.show(txtName.Text + Environment.Newline + word,MessageBoxButtons.ok);

Q# 42 Design the following form using DateTimePicker, TextBox , Label and a Button. When you press the Age (In
Years Months and Days) Button then age is displayed in the Textboxes in Years Months and Days
Answer:

1. private void btnCalculateAge_Click(object sender, EventArgs e) {


2. DateTime dateOfBirth;
3. DateTime.TryParse(dateTimePicker1.value, out dateOfBirth);
4. DateTime currentDate = DateTime.Now;
5. TimeSpan difference = currentDate.Subtract(dateOfBirth);
6. DateTime age = DateTime.MinValue + difference;
7. int ageInYears = age.Year - 1;
8. int ageInMonths = age.Month - 1;
9. int ageInDays = age.Day - 1;
10. txtAgeInYear.Text = (ageInYears).ToString();
11. txtAgeInMonth.Text = (ageInMonths).ToString();
12. txtAgeInDays.Text = (ageInDays).ToString();
13. }
14. private void btnCalculateAge_MouseMove(object sender, MouseEventArgs e) {
15. toolTip1.SetToolTip(this.btnCalculateAge, "Enter to Calculate Your Age");
16. }
17. private void txtDOB_MouseHover(object sender, EventArgs e) {
18. toolTip1.SetToolTip(this.txtDOB, "Enter your Birth Date");
19. }
20. private void btnExit_Click(object sender, EventArgs e) {
21. Application.Exit();
22. }
23. private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
24. DialogResult result;
25. result = MessageBox.Show("Do you realy want to close", "Confirmation", MessageBoxBu
ttons.YesNo);
26. if (result == DialogResult.No) {
27. e.Cancel = true;
28. }
29. }

Q# 43 Create a Digital Clock in C# as shown


Answer:

Answer: using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace DigitalClock

public partial class Form1 : Form

{
Timer t = new Timer();

public Form1()

InitializeComponent();

private void Form1_Load(object sender, EventArgs e)

//timer interval

t.Interval = 1000; //in milliseconds

t.Tick += new EventHandler(this.t_Tick);

//start timer when form loads

t.Start(); //this will use t_Tick() method

//timer eventhandler

private void t_Tick(object sender, EventArgs e)

//get current time

int hh = DateTime.Now.Hour;

int mm = DateTime.Now.Minute;
int ss = DateTime.Now.Second;

//time

string time = "";

//padding leading zero

if (hh < 10)

time += "0" + hh;

else

time += hh;

time += ":";

if (mm < 10)

time += "0" + mm;

else

time += mm;

}
time += ":";

if (ss < 10)

time += "0" + ss;

else

time += ss;

//update label

label1.Text = time;

Form1.Designer.cs

namespace DigitalClock

partial class Form1

/// <summary>

/// Required designer variable.


/// </summary>

private System.ComponentModel.IContainer components = null;

/// <summary>

/// Clean up any resources being used.

/// </summary>

/// <param name="disposing">true if managed resources should be disposed;


otherwise, false.</param>

protected override void Dispose(bool disposing)

if (disposing && (components != null))

components.Dispose();

base.Dispose(disposing);

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{
this.label1 = new System.Windows.Forms.Label();

this.SuspendLayout();

//

// label1

//

this.label1.AutoSize = true;

this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F,


System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

this.label1.Location = new System.Drawing.Point(12, 9);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(284, 73);

this.label1.TabIndex = 0;

this.label1.Text = "00:00:00";

//

// Form1

//

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(305, 97);

this.Controls.Add(this.label1);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;

this.MaximizeBox = false;

this.Name = "Form1";

this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

this.Text = "Digital Clock";


this.Load += new System.EventHandler(this.Form1_Load);

this.ResumeLayout(false);

this.PerformLayout();

#endregion

private System.Windows.Forms.Label label1;

Q# 44 Create a Splash Screen in C# using ProgressBar Control and Timer Control


Answer:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace SplashScreen
{

public partial class Form1 : Form

public Form1()

InitializeComponent();

private void Form1_Load(object sender, EventArgs e)

//the timer is now going to start

timeLeft = 10;

timer1.Start();

public int timeLeft { get; set; }

private void timer1_Tick(object sender, EventArgs e)

if (timeLeft > 0)

timeLeft = timeLeft - 1;
}

else

timer1.Stop();

new Form3().Show();

this.Hide();

Q# 45 Q Design a form Such that it look like this and perform the Calculator Operations according to button
being clicked

Answer:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace calculator
{
public partial class Form1 : Form
{
public string no1,constfun;
// public int no2;
public bool inputstatus;

public Form1()
{
InitializeComponent();
no1 = "";
textBox1.ReadOnly = true; //read only mode of textbox
textBox1.RightToLeft = RightToLeft.Yes;
radioButton1.Checked = true;

}
//putting value of button text into text box and a variable inputstatus to textbox
#region putting value
private void button1_Click(object sender, EventArgs e)
{
if (inputstatus == true)
{
textBox1.Text += button1.Text;
}
else
{
textBox1.Text = button1.Text;
inputstatus = true;
}
}
private void button6_Click(object sender, EventArgs e)
{
if (inputstatus == true)
{
textBox1.Text += button6.Text;
}
else
{
textBox1.Text = button6.Text;
inputstatus = true;
}

}
private void button7_Click(object sender, EventArgs e)
{
if (inputstatus == true)
{
textBox1.Text += button7.Text;
}
else
{
textBox1.Text = button7.Text;
inputstatus = true;
}

}
private void button8_Click(object sender, EventArgs e)
{
if (inputstatus == true)
{
textBox1.Text += button8.Text;
}
else
{
textBox1.Text = button8.Text;
inputstatus = true;
}
}
private void button11_Click(object sender, EventArgs e)
{
if (inputstatus == true)
{
textBox1.Text += button11.Text;
}
else
{
textBox1.Text = button11.Text;
inputstatus = true;
}
}
private void button12_Click(object sender, EventArgs e)
{
if (inputstatus == true)
{
textBox1.Text += button12.Text;
}
else
{
textBox1.Text = button12.Text;
inputstatus = true;
}
}
private void button13_Click(object sender, EventArgs e)
{
if (inputstatus == true)
{
textBox1.Text += button13.Text;
}
else
{
textBox1.Text = button13.Text;
inputstatus = true;
}
}
private void button16_Click(object sender, EventArgs e)
{
if (inputstatus == true)
{
textBox1.Text += button16.Text;
}
else
{
textBox1.Text = button16.Text;
inputstatus = true;
}
}
private void button17_Click(object sender, EventArgs e)
{
if (inputstatus == true)
{
textBox1.Text += button17.Text;
}
else
{
textBox1.Text = button17.Text;
inputstatus = true;
}
}
//when 9 is pressed
private void button18_Click(object sender, EventArgs e)
{
if (inputstatus == true)
{
textBox1.Text += button18.Text;
}
else
{
textBox1.Text = button18.Text;
inputstatus = true;
}
}
//. button
private void button2_Click(object sender, EventArgs e)
{
if (inputstatus == true)
{
textBox1.Text += button2.Text;
}
else
{
textBox1.Text = button2.Text;
inputstatus = true;
}
}
#endregion putting vaules
//Add Operator
private void button3_Click(object sender, EventArgs e)
{
no1 = textBox1.Text;
textBox1.Text = "";
constfun = "+"; //used in switch case to check what want to do add

}
//subtract
private void button9_Click(object sender, EventArgs e)
{
no1 = textBox1.Text;
textBox1.Text = "";
constfun = "-"; //want to subtract

}
//multiply
private void button10_Click(object sender, EventArgs e)
{
no1 = textBox1.Text;
textBox1.Text = "";
constfun = "*"; //want to multiply
}
//divide
private void button15_Click(object sender, EventArgs e)
{
no1 = textBox1.Text;
textBox1.Text = "";
constfun = "/";

}
//a user defined fun
private void funcal()
{
switch (constfun)
{
case "+":
textBox1.Text=Convert.ToString( Convert.ToInt32(no1) + Convert.ToInt32(textBox1.Text)); //ading
values of textbox

break;
case "-":
textBox1.Text = Convert.ToString(Convert.ToInt32(no1) - Convert.ToInt32(textBox1.Text));

break;
case "*":
textBox1.Text = Convert.ToString(Convert.ToInt32(no1) * Convert.ToInt32(textBox1.Text));
break;
case "/":
if (textBox1.Text == "0")
{
textBox1.Text = "infinity";
}
else
{
textBox1.Text = Convert.ToString(Convert.ToInt32(no1) / Convert.ToInt32(textBox1.Text));
}
break;
case "x^y":
textBox1.Text
= Convert.ToString(System.Math.Pow(Convert.ToDouble(no1),Convert.ToDouble(textBox1.Text)));
break;
case "mod": textBox1.Text = Convert.ToString(Convert.ToDouble(no1)
% Convert.ToDouble(textBox1.Text));
break;
case "nPr": int varn, var2,var3; //variable declaration
varn = factorial(Convert.ToInt32(no1)); //calling factorial function
var2=factorial(Convert.ToInt32(no1)-Convert.ToInt32(textBox1.Text));
textBox1.Text=Convert.ToString(varn/var2); //storing or showing result of factorial variables
break;
case "nCr":
varn = factorial(Convert.ToInt32(no1));
var2=factorial(Convert.ToInt32(no1)-Convert.ToInt32(textBox1.Text));
var3 = factorial(Convert.ToInt32(textBox1.Text));
textBox1.Text=Convert.ToString(varn/(var3*var2));
break;

}
}

//a user defined function to calculate factorial


private int factorial(int x)
{
int i = 1; //initialization values of i to 1
for (int s = 1; s <= x; s++)
{
i = i * s;
}
return i;
}

//when = button is pressed


private void button5_Click(object sender, EventArgs e)
{

funcal(); //calling of function


inputstatus = false;
}

//when AC is pressed to power on


private void button14_Click(object sender, EventArgs e)
{
textBox1.Enabled = true;
textBox1.Text = "0";

//calculating x raise to power 2


private void button19_Click(object sender, EventArgs e)
{
textBox1.Text = Convert.ToString(Convert.ToInt32(textBox1.Text)
* Convert.ToInt32(textBox1.Text));
inputstatus = false;
}
//calculating x raise to power 3
private void button20_Click(object sender, EventArgs e)
{
textBox1.Text = Convert.ToString(Convert.ToInt32(textBox1.Text)
* Convert.ToInt32(textBox1.Text) *Convert.ToInt32(textBox1.Text));
inputstatus = false;
}
//calculating squareroot
private void button21_Click(object sender, EventArgs e)
{
textBox1.Text = Convert.ToString(System.Math.Sqrt(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}

//x raise to power y


private void button22_Click(object sender, EventArgs e)
{
no1 = textBox1.Text;
textBox1.Text = "";
constfun = "x^y";
}

//when CE button is pressed


private void button23_Click(object sender, EventArgs e)
{
textBox1.Text = String.Empty;
inputstatus = true;
}
//To set Pi value
private void button4_Click(object sender, EventArgs e)
{
textBox1.Text = "3.141592654";
}
//sin function
private void button24_Click(object sender, EventArgs e)
{
//if radian is selected
if (radioButton3.Checked==true)
{
textBox1.Text = Convert.ToString(System.Math.Sin(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}
//if degree is selected
else
{
textBox1.Text
= Convert.ToString(System.Math.Sin((Convert.ToDouble(System.Math.PI)/180)*(Convert.ToDouble(
textBox1.Text))));
inputstatus = false;
}
}

//cos function
private void button25_Click(object sender, EventArgs e)
{
//radian selected
if (radioButton3.Checked==true)
{
textBox1.Text = Convert.ToString(System.Math.Cos(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}
//degree selected
else
{
textBox1.Text
= Convert.ToString(System.Math.Cos((Convert.ToDouble(System.Math.PI)/180)*(Convert.ToDouble
(textBox1.Text))));
inputstatus = false;
}
}

//tan function
private void button26_Click(object sender, EventArgs e)
{

//radian selected
if (radioButton3.Checked==true)
{
textBox1.Text = Convert.ToString(System.Math.Tan(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}
//degree selected
else
{
textBox1.Text
= Convert.ToString(System.Math.Tan((Convert.ToDouble(System.Math.PI)/180)*(Convert.ToDouble
(textBox1.Text))));
inputstatus = false;
}

//calculationg 1/x
private void button27_Click(object sender, EventArgs e)
{
textBox1.Text = Convert.ToString(Convert.ToDouble(1.0 / Convert.ToDouble(textBox1.Text)));
inputstatus = false;

//calculting x!
private void button28_Click(object sender, EventArgs e)
{
int var1=1;
for (int i = 1; i <= Convert.ToInt16(textBox1.Text); i++)
{
var1 = var1 * i;
}
textBox1.Text = Convert.ToString(var1);
inputstatus = false;
}
//calculationg log10
private void button29_Click(object sender, EventArgs e)
{
textBox1.Text=Convert.ToString(System.Math.Log10(Convert.ToDouble(textBox1.Text)));
inputstatus=false;
}

//calculation natural log


private void button30_Click(object sender, EventArgs e)
{
textBox1.Text=Convert.ToString(System.Math.Log(Convert.ToDouble(textBox1.Text)));
inputstatus=false;
}

//backspace key is presseed


private void button31_Click(object sender, EventArgs e)
{
no1= textBox1.Text;
int n=no1.Length;
textBox1.Text=(no1.Substring(0,n-1)); //removing values one by one onclick of backspace button
}
//when mod operator(%) is presseed
private void button32_Click(object sender, EventArgs e)
{
no1 = textBox1.Text;
textBox1.Text = "";
constfun = "mod"; //explaned earlier to calculate mod in fncalc()
}
//coding for +/- key
private void button33_Click(object sender, EventArgs e)
{
textBox1.Text = Convert.ToString(-Convert.ToInt32(textBox1.Text));
inputstatus = false;
}

//Sin inverese fun


private void button35_Click(object sender, EventArgs e)
{
if (radioButton3.Checked==true)
{
textBox1.Text = Convert.ToString(System.Math.Asin(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}
else
{
textBox1.Text
= Convert.ToString(System.Math.Asin((Convert.ToDouble(System.Math.PI)/180)*(Convert.ToDoubl
e(textBox1.Text))));
inputstatus = false;
}
}
//cos inverese fun
private void button34_Click(object sender, EventArgs e)
{
if (radioButton3.Checked==true)
{
textBox1.Text = Convert.ToString(System.Math.Acos(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}
else
{
textBox1.Text
= Convert.ToString(System.Math.Acos((Convert.ToDouble(System.Math.PI)/180)*(Convert.ToDoubl
e(textBox1.Text))));
inputstatus = false;
}
}
//tan inverese fun
private void button36_Click(object sender, EventArgs e)
{
if (radioButton3.Checked == true)
{
textBox1.Text = Convert.ToString(System.Math.Atan(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}
else
{
textBox1.Text = Convert.ToString(System.Math.Atan((Convert.ToDouble(System.Math.PI)/180) *
(Convert.ToDouble(textBox1.Text))));
inputstatus = false;
}
}

private void radioButton3_CheckedChanged(object sender, EventArgs e)


{

//permutation
private void button37_Click(object sender, EventArgs e)
{
no1 = textBox1.Text;
textBox1.Text = "";
constfun = "nPr";
}
//combination
private void button38_Click(object sender, EventArgs e)
{
no1 = textBox1.Text;
textBox1.Text = "";
constfun = "nCr";

}
private void Form1_Load(object sender, EventArgs e)
{
}
private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
}

//coding for off button


private void button39_Click(object sender, EventArgs e)
{
textBox1.Enabled = false;
textBox1.Text = "";
inputstatus = false;
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
}
private void userControl11_Load(object sender, EventArgs e)
{
Application.Exit();
}
private void userControl11_Load_1(object sender, EventArgs e)
{
}
private void userControl11_Load_2(object sender, EventArgs e)
{
}

}
}

You might also like