ENTERPRISE ARCHITECTURE USING C#.NET (Lab Manual – MCA Vth / M.Sc.IT IIIrd S!"trC$d% PMC&')/PMI&*) N$t% +. I!,l !n t th -$ ll$n0 1rc "" n C# ). Prn t th"cr n $ut ,ut a" an $u t,u t *. Write the algorithm of each program 2. Test the program with various cases
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
7) Pre8Re9uisite: O*+ect orie,te. programmi,g fu,.ame,tals)) Su*+ect Area: omputer Scie,ce;) 7b8ct5% The purpose of the first four exercises is to get used to the C# compiler and to get experience
with properties, operator overloading and user-defined conversions. Next four exercises include windows
application development using Microsoft .NET with C#. Next set of exercises represent web based
application development including !".NET and eb $orms.
(0) Details of the ourse:
Sl)NO ONTENT ONTAT!O#RS
( Write a Program in C# to Check whether a number isPalindrome or not.
10<1 = 40
1
Write a Program in C# to demonstrate Command line
arguments Processing.
3
Write a Program in C# to fnd the roots o Quadratic
Equation.
4
Write a Program in C# to Check whether a number is
Palindrome or not./ Write a Program in C# to demonstrate Command line
arguments processing5
Write a Program in C# to fnd the roots o Quadratic
Equation.
7
Write a Program in C# to demonstrate boing and
un!oing.
"
Write a Program in C# to implement tack
operations.
$
Write a program to demonstrate %perator
o&erloading.
'
( (
)(
)(* ) ,
7/23/2019 PMC 502 # Lab
http://slidepdf.com/reader/full/pmc-502-lab 3/19
*(
Write a Program in C# to fnd the second largest
element in a single dimensional arra-.
**
Write a Program in C# to multipl- to matrices using
ectangular arra-s.
*)/ind the sum o all the elements present in a 0agged
arra- o 1 inner arra-s.
*1
Write a program to re&erse a gi&en string using C#.
*,
2sing 3r-4 Catch and /inall- blocks write a program in
C# to demonstrate error handling.
*+
5esign a simple calculator using witch tatement in
C#.
*6
5emonstrate 2se o irtual and o&erride ke- words in
C# with a simple program
*7 Write a program to displa- the ollowing eedback orm. 3he di8erent options or the list bo must be 9P:;<=4 5ot>E34 ?a&aPro and 2ni4C4C@@. When the ubmit /orm button is clickedater entering the data4 a message as seen in the last line o theabo&e fgure must be displa-ed.
*"
Write a program that displa-s a button in green color and it
should change into -ellow when the mouse mo&es o&er it.*$ Write a program containing the ollowing controlsA
B 9 =ist!oB 9 !uttonB 9n mageB 9 =abel
3he listbo is used to list items a&ailable in a store.When the user clicks on an item in the listbo4 itsimage is displa-ed in the image control. When theuser clicks the button4 the cost o the selected item isdispla-ed in the control.
)( Write a ?a&acript code that displa-s two ad&ertisementsalternatel-. When the user clicks on one o thead&ertisements4 heDshe is redirected towww.amaFon.comG4 and the other ad&ertisement redirectsthe user to www.abmart.comG. 3he weightage o theamaFon ad&ertisement is +( and that o the other one is,(. 3he ad&ertisement should be centered horiFontall- andshould co&er 6(H o the width o the screen. ts heightshould be "( units. 3he width o the border should be +
7/23/2019 PMC 502 # Lab
http://slidepdf.com/reader/full/pmc-502-lab 4/19
units.
TOTA" 40
(() Suggeste. 6oo>s:
Sl)NO NAME OF A#T!ERS26OO?S2P#6"$S!ERS @EAR OFP#6"$AT$ON2REPR$
). Kead /irst C#4 )EA 9 =earnerMs Luide to eal:World Programming withisual C# and .>E3 IKead /irst LuidesJ b- 9ndrew tellman and ?ennierLreene
1. C# ,.( in a >utshellA 3he 5efniti&e eerence b- ?oseph 9lbahari and !en9lbahari
7/23/2019 PMC 502 # Lab
http://slidepdf.com/reader/full/pmc-502-lab 5/19
*. Write a Program in C# to Check whether a number is Palindrome or not.using -stemclass palindrome
Bpublic static &oid <ainCB
int num N ( re& num* N ( num) N (Console.Write=ineCOEnter a numberO
num N int.ParseCConsole.ead=ineCnum) N numwhile Cnum (B
re& N num H *(num N num D *(num* N num* *( @ re&
i Cnum* NN num)
Console.Write=ineCO>umber is PalindromeOelse
Console.Write=ineCO>umber is >%3 PalindromeO Console.eadC
). Write a Program in C# to demonstrate Command line arguments Processing.using -stemclass cmdarg B
public static &oid <ainCB
int num N (tring&' argument N En&ironment.LetCommand=ine9rgsCor Cint i N * i R argument.=ength i@@
num N num @ int.ParseCargument&i'Console.Write=ineCOum is O @ num
Console.eadC
1. Write a Program in C# to fnd the roots o Quadratic Equation.using -stempublic class roots B
double a N ( b N ( c N ( d N ( r* N ( r) N ( n N ( m N (public &oid inputCB
Console.Write=ineCOEnter the quardatic EquationOa N double.ParseCConsole.ead=ineCb N double.ParseCConsole.ead=ineCc N double.ParseCConsole.ead=ineCd N <ath.qrtCb b : , a ci Cd NN (B
Console.Write=ineCO3he oots or the gi&en Equation are eal and EqualOr* N r) N :b D C) aConsole.Write=ineCOoot isA O @ r* @ OandO @ r)
else i Cd R (B
Console.Write=ineCOoots or te gi&en equation are eal and distinctO r* N C:b @ d D C) a r) N C:b : d D C) aConsole.Write=ineCO3he oots areA O @ Cintr* @ OandO @ Cintr)
else B
7/23/2019 PMC 502 # Lab
http://slidepdf.com/reader/full/pmc-502-lab 6/19
Console.Write=ineCO3he oots or the gi&en Equation are maginar-On N :b D C) am N <ath.qrtC<ath.9bsCb b : , a c D C) aConsole.Write=ineCOoot *A O @ n @ O@i O @ mConsole.Write=ineCOoot )A O @ n @ O:i O @ m
class Quad B
public static &oid <ainCB
roots r N new rootsCr.inputC
Console.eadC
,. Write a Program in C# to Check whether a number is Palindrome or not.
using -stemclass Pallin
B public static &oid <ainCtring&' args B int dnre&m Console.Write=ineCOEnter the numberO nNint.ParseCConsole.ead=ineC mNn re&N( whileCnSN( B dNnH*( re&Nre&*(@d nNnD*( i Cre&NNm
B Console.Write=ineCOEntered number O@m@O is pallindromeO else B Console.Write=ineCOEntered number O@m@O is not pallindromeO
+. Write a Program in C# to demonstrate Command line arguments processing.
using -stemTnamespace Console9pplication*Uclass CommandlineUstatic &oid <ainIstringV argsJUConsole.WriteIWE=C%<E to JTConsole.WriteIG G @ argsV(JTConsole.WriteIG G @ argsV*JTConsole.ead=ineIJTXXX
7/23/2019 PMC 502 # Lab
http://slidepdf.com/reader/full/pmc-502-lab 7/19
DDanotherusing -stemTclass Command=ine9rgs Upublic static &oid <ainItringV argsJ Udouble a4bTiIargs.=engthNN(J UConsole.Write=ineI>o arguments oundGJTXelse UaNdouble.ParseIargsV(JTbNdouble.ParseIargsV*JTdouble sumN(4mulN(4di&N(4subN([email protected]=ineIum o @a@G and @b@G is @sumJTsubNa:bTConsole.Write=ineIG ubstraction o @b@G b- @a@G is @subJTmulNabTConsole.Write=ineIG <ultiplication o @a@G and @b@G is @mulJTdi&NaDbTConsole.Write=ineIG 5i&ision o @a@G b- @b@G is @di&JTXXX
6. Write a Program in C# to fnd the roots o Quadratic Equation.
using -stemTusing -stem.3etTnamespace Console9pplication*Uclass QuadY U static &oid <ainIstringV argsJU int a4 b4 cTZoat d4 *4 )TConsole.Write=ineI[n Enter a4b4c A[nGJTConsole.WriteIG a N JTa N Con&ert.3ont1)IConsole.ead=ineIJJTConsole.WriteIG b N JTb N Con&ert.3ont1)IConsole.ead=ineIJJTConsole.WriteIG c N JTc N Con&ert.3ont1)IConsole.ead=ineIJJTd N b b \ , a cT
i Id (JU Console.Write=ineI[n Equation has two roots.GJT* N IZoatJI:b @ <ath.qrtIdJJ D I) aJT) N IZoatJI:b \ <ath.qrtIdJJ D I) aJTConsole.Write=ineI[n 3he roots areA[nGJTConsole.Write=ineI[n root* N @*@G[n root) N @)JTXelse i Id NN (JUConsole.Write=ineI[n Equation has onl- one root.GJT* N IZoatJ:b D I) aJTConsole.Write=ineI[n 3he root isA[nGJTConsole.Write=ineI[n root N G @ *JTXelseU
Console.Write=ineI[n Equation has imaginar- roots.GJT* N IZoatJ:b D I) aJT) N IZoatJ<ath.qrtI:dJ D I) aJTConsole.Write=ineI[n 3he roots areA[nGJTConsole.Write=ineI[n root* N G @ * @ G @ G @ ) @ G i [nG @ G root) N G @ * @ G \ G @ ) @ G iJTXConsole.ead=ineIJTX X X
7/23/2019 PMC 502 # Lab
http://slidepdf.com/reader/full/pmc-502-lab 8/19
7. Write a Program in C# to demonstrate boing and un!oing.
using -stemTclass !o2nbo Upublic static &oid <ainIJUint numTConsole.WriteIEnter the number A JTnumNint.ParseIConsole.ead=ineIJJT
%b0ect oNnumTConsole.Write=ineIalue in numN @numJTConsole.Write=ineIalue in %b0ect (NG@oJTint nTnNIintJoTConsole.Write=ineIalue o nNG@nJTXX
". Write a Program in C# to implement tack operations.
using -stemTclass tackUpublic static &oid <ainItringV argsJ
case *AiItopNNIma:*JJ UConsole.Write=ineItack is ullGJTXelse UConsole.Write=ineIEnter the element to be insertedAGJTnumNint.ParseIConsole.ead=ineIJJTstackV@@topNnumTConsole.Write=ineIElement is successull- insertedGJTXbreakTcase )AiItopNN:*JUConsole.Write=ineItack is Empt-GJTXelse UConsole.Write=ineI5eleted Element is AG@stackVtop::JTXbreakTcase 1AiItopNN:*JUConsole.Write=ineItack is Empt-GJTXelse U
Console.Write=ineIElements in the stackGJTorIint iNtopTiN(Ti\J
$. Write a program to demonstrate %perator o&erloading.
using -stemT
public struct CompleUpublic int realTpublic int imaginar-T
public CompleIint real4 int imaginar-JUthis.real N realTthis.imaginar- N imaginar-TX
DD 5eclare which operator to o&erload I@J4 the t-pesDD that can be added Itwo Comple ob0ectsJ4 and theDD return t-pe ICompleJApublic static Comple operator @IComple c*4 Comple c)JUreturn new CompleIc*.real @ c).real4 c*.imaginar- @ c).imaginar-JTXDD %&erride the 3otring method to displa- an comple number in the suitable ormatApublic o&erride string 3otringIJ
intV arr NU (4 +4 74 :)4 $4 *)4 ,4 " XTint high4 sechigh4tempThigh N sechigh N arrV(TConsole.Write=ineI9rra- elements areGJTor Iint i N (T i R arr.=engthT i@@JConsole.WriteIarrVi@G JTConsole.Write=ineIJTor Iint i N (T i R arr.=engthT i@@JUtemp N arrViTi Itemp highJUsechigh N highThigh N tempTXelse i Itemp sechigh ̂ ^ temp SN highJ
sechigh N tempTXConsole.Write=ineI3he second largest number in the arra- is G @ sechighJTConsole.ead=ineIJTXXX
**.Write a Program in C# to multipl- to matrices using ectangular arra-s.
using -stemTclass matrimulUpublic static &oid <ainItringV argsJ
UintV4 aNnew int V+4+TintV4 bNnew int V+4+TintV4 cNnew int V*(4*(Tint m4n4i404p4q4kTConsole.Write=ineIEnter the order o frst matriGJTmNint.ParseIConsole.ead=ineIJJTnNint.ParseIConsole.ead=ineIJJTConsole.Write=ineIEnter the order o second matriGJTpNint.ParseIConsole.ead=ineIJJTqNint.ParseIConsole.ead=ineIJJTiInSNpJConsole.Write=ineInot possibleGJTelseUConsole.Write=ineIenter arra- elements o forst matri JT
tring out&NGOTConsole.Write=ineIG Enter a string A[nGJTin&NConsole.ead=ineIJTorIint iNin&.=ength:*TiN(Ti\JUout&Nout&@in&.ubstringIi4*JTXConsole.Write=ineI3he re&ersed string isA @out&JTConsole.ead=ineIJTXXX
*,.2sing 3r-4 Catch and /inall- blocks write a program in C# to demonstrate
error handling.
using -stemTusing -stem.Collections.LenericTusing -stem.=inqTusing -stem.3etTnamespace Console9pplication*Uclass EceptionUstatic int m N *(T
static int n N (Tstatic &oid 5i&isionIJUtr-Uint k N m D nTXcatch I9rgumentEception eJUConsole.Write=ineIEception caughtAG @ e.<essageJTXfnall-UConsole.Write=ineInside di&ision methodGJTConsole.ead=ineIJTX
Xstatic &oid <ainIstringV argsJUtr-U5i&isionIJTXcatch I5i&ide!-_eroEception eJUConsole.Write=ineIEception caughtAG @ e.<essageJTXfnall-UConsole.Write=ineIinside main methodGJTConsole.ead=ineIJTXXX X
*+.5esign a simple calculator using witch tatement in C#.
using -stemTclass imcalc Upublic static &oid <ainItringV argsJUdouble a4b4rptN*T
7/23/2019 PMC 502 # Lab
http://slidepdf.com/reader/full/pmc-502-lab 13/19
int choiceTwhileIrptSN(JUConsole.Write=ineIelect the operationGJTConsole.Write=ineI* . 9dditionGJTConsole.Write=ineI) . ubtractionGJTConsole.Write=ineI1 . <ultiplicationGJTConsole.Write=ineI, . 5i&isionGJTConsole.Write=ineI( . EitGJTConsole.Write=ineIEnter ur choice AGJTchoiceNint.ParseIConsole.ead=ineIJJTswitchIchoiceJUcase *AConsole.Write=ineIEnter two numbersAGJTaNdouble.ParseIConsole.ead=ineIJJTbNdouble.ParseIConsole.ead=ineIJJTConsole.Write=ineIesult o 9ddition A @Ia@bJJTbreakTcase )AConsole.Write=ineIEnter two numbersAGJTaNdouble.ParseIConsole.ead=ineIJJTbNdouble.ParseIConsole.ead=ineIJJTConsole.Write=ineIesult o ubtraction A @Ia:bJJTbreakTcase 1AConsole.Write=ineIEnter two numbersAGJT
aNdouble.ParseIConsole.ead=ineIJJTbNdouble.ParseIConsole.ead=ineIJJTConsole.Write=ineIesult o <ultiplication A @IabJJTbreakTcase ,AConsole.Write=ineIEnter two numbersAGJTaNdouble.ParseIConsole.ead=ineIJJTbNdouble.ParseIConsole.ead=ineIJJTiIbNN(J UConsole.Write=ineI5i&ision not possibleGJTXelse UConsole.Write=ineIesult o 5i&ision A @IaDbJJTXbreakTcase (A
*6.5emonstrate 2se o irtual and o&erride ke- words in C# with a simple program
using -stemTusing -stem.Collections.LenericTnamespace Console9pplication*
Upublic class CustomerUpublic &irtual &oid Customer3-peIJUConsole.Write=ineI am customerGJTXXpublic class CorporateCustomerACustomerUpublic o&erride &oid Customer3-peIJUConsole.Write=ineI am Corporate CustomerGJT
7/23/2019 PMC 502 # Lab
http://slidepdf.com/reader/full/pmc-502-lab 14/19
XXpublic class PersonalCustomerACustomerUpublic o&erride &oid Customer3-peIJUConsole.Write=ineI am personal customerGJTXXclass ProgramUstatic &oid <ainIstringV argsJUCustomerV cNnew CustomerV1TcV(Nnew CorporateCustomerIJTcV*Nnew CorporateCustomerIJTcV)Nnew CustomerIJToreachICustomer customerob0ect in cJUcustomerob0ect.Customer3-peIJTXConsole.ead=ineIJTXXX
7/23/2019 PMC 502 # Lab
http://slidepdf.com/reader/full/pmc-502-lab 15/19
*7.
*". Write a program that displa-s a button in green color and it should change into -ellow whenthe mouse mo&es o&er it.
olution.
<html>
<head><title> ASP.NET </title>
</head>
<form id=f1 runat=”server”><body><font olor=”!reen”><s"an id=s1 runat=”server” /></font><br><br><h#> $ove The $ouse %ver $e and oy </h#><as"&button id=”'utton() %nServer*li+=”'utton(,*li+” te-t=”*li+ me toostyle=”font& 0"t
*$.Write a program containing the ollowing controlsA
B 9 =ist!oB 9 !uttonB 9n mageB 9 =abel
3he listbo is used to list items a&ailable in a store. When the user clicks on an item inthe listbo4 itsimage is displa-ed in the image control. When the user clicks the button4 the cost othe selected item isdispla-ed in the control.
olutionA<html><head><Sri"t lan!ua!e=”6” runat=”Server”>void *alulate7%b8et sender9EventAr!s e:;if 7Store.Seletednde- > 21:;int i = Store.Seletednde-*ost.Te-t = ou have hosen Store.Seletedtem.?alue andits ost is @s.”
if 7i==3:*ost.Te-t = #3”else if 7i==1:*ost.Te-t = #(”else if 7i == (:*ost.Te-t = (0”else*ost.Te-t = (”BBvoid dis"lay7%b8et sender9 EventAr!s e:
7/23/2019 PMC 502 # Lab
http://slidepdf.com/reader/full/pmc-502-lab 17/19
;int i = Store.Seletednde-if 7i==3:;m!.ma!eCrl = *ola.!if”m!.AlternateTe-t = *ola”Belse if 7i==1:;m!.ma!eCrl = @ed,"o".!if”
)(. Write a ?a&acript code that displa-s two ad&ertisements alternatel-. When the user clicks onone o the ad&ertisements4 heDshe is redirected to www.amaFon.comG4 and the other
ad&ertisement redirects the user to www.abmart.comG. 3he weightage o the amaFonad&ertisement is +( and that o the other one is ,(. 3he ad&ertisement should be centeredhoriFontall- and should co&er 6(H o the width o the screen. ts height should be "( units. 3hewidth o the border should be + units.