Cs1010 Model Key
Cs1010 Model Key
Cs1010 Model Key
Part – A (5 x 2 = 10 Marks)
1. Define Versioning and Interoperability
- Making new versions of software modules work with the existing applications is known as
versioning. C# provides support for versioning with the help of new and override keywords.
.NETe
ii) Explain the different types of operators supported in C#(8)
An operator is a symbol that tells the computer to perform certain mathematical or logical
manipulations.
C sharp operators can be classified into a number of related categories
1. Arithmetic operators 2. Relational operators 3.Logical operators
4.Assignment operators 5.Increment and Decrement 6. Conditional
7.Bitwise and 8.Special operators(is,as,typeof, sizeof, new,.(dot),checked,unchecked)
(Or)
b) i) What is type conversion. Explain the different types of type conversion?(8)
Converting of one data type into other data type is called type conversion.
Types of conversations:
• Implicit type conversions: (Arithmetic operations)- no loss of data-
• Explicit type conversions:(Casting operations)-loss of data
ii) What is an array list. Write a program to sort and reverse of an array using methods(8)
using System;
namespace arrayclass
{
class SortReverse
{
static void Main(string[] args)
{
int[] x = {30, 10, 80, 90, 20};
Console.WriteLine("Array before Sorting");
foreach(int i in x)
Console.WriteLine("" +i);
Console.WriteLine();
Array.Sort(x);
Console.WriteLine("SORTED ARRAY");
foreach(int i in x)
Console.WriteLine(" "+i);
Console.WriteLine();
Array.Reverse(x);
Console.WriteLine("reversed contents");
foreach (int i in x)
Console.WriteLine(" " + i);
Console.WriteLine();
x.SetValue(25, 1);
Console.WriteLine("the values are");
foreach (int i in x)
Console.WriteLine(" " + i);
Console.WriteLine();
}
}
}
12 a) i) Explain different types of constructors in C#(10)
C# supports a special type of method, called a constructor that enables an object to initialize
itself when it is created. Constructor has the name as class itself. They don’t not specify the
return type , not even void. Constructors are usually public because they are provided to create
objects
Types:
• Copy constructors
• Private constructor
• Static constructor
• Over loaded constructor
ii) Write a program to add two complex numbers using operator overloading(6)
using System;
class Complex
{
double x;
double y;
public Complex()
{
}
public Complex(double real,double imag)
{
x=real;
y=imag;
}
public static Complex operator + (Complex c1,Complex c2)
{
Complex c3=new Complex();
c3.x=c1.x+c2.x;
c3.y=c1.y+c2.y;
return(c3);
}
public void display()
{
Console.Write(x);
Console.Write("+j" +y);
Console.WriteLine();
}
}
class ComplexTest
{
public static void Main()
{
Complex a,b,c;
a=new Complex(2.5,3.5);
b=new Complex(1.6,2.7);
c=a+b;
Console.Write("a=");
a.display();
Console.Write("b=");
b.display();
Console.Write("c=");
c.display();
}
}
(Or)
b)i) Write the necessary steps to create and use delegates(8)
A delegate object is a special type of object that contains the details of a method rather
than data. Delegates in c # are used for two purposes: Call back and Event handling
the steps involved in creating and using delegates
*Delegate declaration
*Delegate methods definition
*Delegate instantiation
*Delegate invocation
ii) Define Exception handling. Explain the mechanism to handle exceptions(8)
An Exception is a condition that is caused by run time error in the program. When the C
# compile encounters an error such as dividing an integer by zero, it creates an
exception object and throws it
Common C# exceptions:
1 SystemException
2.AccessException
3.ArgumentException
Mechanisms to handle exceptions:
*Find the problem
*Inform that an error has occurred
*Receive the error information
*take corrective actions.
13 a i) Write a windows program to estimate the price of the computer(8)
CODING :
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;
namespace ComputerPriceEstimator
{
public MainForm()
{
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void btnCalculate_Click(object sender, System.EventArgs e)
{
decimal basePrice = 200;
string strBase = string.Format("Base: {0:C}", basePrice);
Debug.WriteLine(strBase);
// CPU
decimal cpuPrice;
if (rdoIntel22.Checked)
cpuPrice = 125;
else if (rdoIntel26.Checked)
cpuPrice = 160;
else
cpuPrice = 165;
string strCpu = string.Format("CPU: {0:C}", cpuPrice);
Debug.WriteLine(strCpu);
basePrice += cpuPrice;
// Memory
decimal memPrice;
if (rdo128MB.Checked)
memPrice = 55;
else if (rdo256MB.Checked)
memPrice = 75;
else
memPrice = 120;
string strMem = string.Format("Memory: {0:C}", memPrice);
Debug.WriteLine(strMem);
basePrice += memPrice;
// DISK
decimal diskPrice;
if (rdo40GB.Checked)
diskPrice = 125;
else if (rdo60GB.Checked)
diskPrice = 140;
else
diskPrice = 200;
string strDisk = string.Format("Disk: {0:C}", diskPrice);
Debug.WriteLine(strDisk);
basePrice += diskPrice;
// Fax/Modem
decimal faxPrice = 0;
if (chkFaxModem.Checked)
faxPrice += 45;
string strFax = string.Format("Fax/Modem: {0:C}", faxPrice);
Debug.WriteLine(strFax);
basePrice += faxPrice;
// Wireless NIC
decimal nicPrice = 0;
if (chkWirelessNIC.Checked)
nicPrice += 75;
string strNic = string.Format("Wireless NIC: {0:C}", nicPrice);
Debug.WriteLine(strNic);
basePrice += nicPrice;
// Floppy
decimal floppyPrice = 0;
if (chkFloppy.Checked)
floppyPrice += 30;
string strFloppy = string.Format("Floppy: {0:C}", floppyPrice);
Debug.WriteLine(strFloppy);
basePrice += floppyPrice;
DATA SET:
The DataSet represents a subset of the entire database, cached on your machine without a
continuous connection to the database.
DATATABLES AND DATACOLUMNS:
DATARELATIONS:
In addition to the Tables collection, the DataSet has a Relations property, which returns a
DataRelationCollection consisting of DataRelation objects. Each DataRelation represents a
relationship between two tables through DataColumn objects.
ROWS:
DataTable's Rows collection returns a set of rows for any given table.
DATA ADAPTER:
The DataSet is an abstraction of a relational database. ADO.NET uses a DataAdapter as a
bridge between the DataSet and the data source, which is the underlying database.
DataAdapter provides the Fill ( ) method to retrieve data from the database and populate the
DataSet.
DBCOMMAND AND DBCONNECTION:
The DBConnection object represents a connection to a data source. This connection can
be shared among different command objects.
Notice that every field in the record is represented by a column in the DataGrid, and that the
titles of the columns are the names of the fields. All of this is the default behavior of the
DataGrid.
ii) List out the categories of controls used in windows based applications and explains the
importance of each components
• All windows forms
• Common controls
• Containers
• Menus and tool bars
• data
• Components
• Printing
• Dialogs
• WPF interoperability
• Reporting
• Visual Basic PowerPacks
• General
14a i) Explain the web form life cycle in details(6)
Initialize,
Load ViewState,
Process Postback Data,
Load,
Send Postback Change Modifications,
Handle Postback Events,
PreRender,
Save State,
Render,
Dispose
namespace WebService3
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment
the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public double Add(double x, double y)
{
return x+y;
}
[WebMethod]
public double Sub(double x, double y)
{
return x-y;
}
[WebMethod]
public double Mult(double x, double y)
{
return x*y;
}
[WebMethod]
public double Div(double x, double y)
{
return x/y;
}
[WebMethod]
public double Pow(double x, double y)
{
double retVal = x;
for (int i = 0;i < y-1;i++)
{
retVal *= x;
}
return retVal;
}
}
}
15 a) i) Explain about Assemblies in detail (8)
• An assembly is a collection of files that appears to the user to be a single dynamic link
library (DLL) or executable (EXE). DLLs are collections of classes and methods that are
linked into your running program only when they are needed.
• Multi-Module Assemblies
• An assembly is loaded into its application by the AssemblyResolver through a process called
probing. The assembly resolver is called by the .NET Framework automatically; you do
not call it explicitly. Its job is to resolve the assembly name to an EXE program and load
your program.
TYPES OF ASSEMBLIES:
Assemblies come in two flavors: private and shared
Private Assemblies.
Private assemblies are intended to be used by only one application; shared assemblies are
intended to be shared among many applications
Shared Assemblies
• You can create assemblies that can be shared by other applications. You might want to do
this if you have written a generic control or a class that might be used by other
developers. If you want to share your assembly, it must meet certain stringent
requirements.
• First, your assembly must have a strong name. Strong names are globally unique.
• Second, your shared assembly must be protected against newer versions trampling over
it, and so it must have version control.
• Finally, to share your assembly, place it in the Global Assembly Cache (GAC)
(pronounced GACK). This is an area of the filesystem set aside by the Common
Language Runtime (CLR) to hold shared assemblies.
ii) What is marshalling and explain its importance (8)
The process of preparing an object to be remoted is called marshaling. On a single machine,
objects might need to be marshaled across context, app domain, or process boundaries.
• Application Domains
• Creating and Using App Domains:
• Marshaling Across App Domain Boundaries:
• Understanding marshaling with proxies:
• Specifying the marshaling method:
• Marshaling across app domain boundaries
• Marshaling Across Context Boundaries
(Or)
b i) What is Remoting ? Explain the necessary steps to access remote methods (8)
When an object is marshaled, either by value or by proxy, across a process or machine boundary,
it is said to be remoted
steps:
• create interface program
• building the server
• creating the server program
• building the client
• creating the client program
ii) Explain the threading concepts in C#
Threads are relatively lightweight processes responsible for multitasking within a single
application. The System.Threading namespace provides a wealth of classes and interfaces to
manage multithreaded programming.
Starting Threads
Thread myThread = new Thread( new ThreadStart(myFunc) );
Joining Threads
To join thread 1 (t1) onto thread 2 (t2), write:
t2.Join( );
Suspending Threads
Killing Threads