Sie sind auf Seite 1von 20

Q1.

Write a Program in C# that inputs a positive integer n and then prints a triangle of asterix n times high and 2n-1 column wide.For example f input is ! then the output would "e. # # ## # # ### # # # # ### Code$using System; using System.Collections.Generic; using System.Text; namespace printStar { class Program { static void Main(string[] args { Console.!rite"ine(#$nter t%e value # ; int & ' int.Parse(Console.(ead"ine( ; int n ' & ) *; int x ' + , (& ) * - *; ../uter "oop 0ill run depends ..on t%e value entered 1y user 2or (int p ' 3; p 4' n; p-{ 2or (int 5 ' & ) *; 5 6' 3; 5)) { Console.!rite(# # ; 7 .. main loop to print Start 2or (int i ' 3; i 4' (x ) + , (& ) * { i2 (i 8 + '' * { Console.!rite(#,# ; 7 else { Console.!rite(# # ; 7 7 Console.!rite"ine( ; &)); 7 Console.(ead"ine( ; 7 7 7

; i--

OUTPUT

Q2. Write a program to implement the "u""le sort in C#. Code$using System; using System.Collections.Generic; using System.Text; namespace ConsolePrograms { class 9u11elSort { pu1lic void 1u11le( { int[] a ' { :; <; =; >?; ?:; :@ 7; int temp; 2or (int pass ' *; pass 4' a."engt% ) +; pass-{ 2or (int i ' 3; i 4' a."engt% ) +; i-{ i2 (a[i] 6 a[i - *] { temp ' a[i - *]; a[i - *] ' a[i]; a[i] ' temp; 7 7 7 Console.!rite"ine(#T%e Sorted array# ; 2oreac% (int aa in a Console.!rite(aa - # # ; Console.(ead( ; 7 7 using System; using System.Collections.Generic; using System.Text; namespace ConsolePrograms { class Program { static void Main(string[] args { 9u11elSort 1s ' ne0 9u11elSort( ; 1s.1u11le( ; 7 7 7 7

OUTPUT

Q%.&efine a class to represent a 'an( )ccount comprising the following specifications # *ame of the &epositor. # 'alance in the )ccount # )ccount no. # +,pe of acc. -.-'./ F0*C+ 1*2 +o assign initial values &eposition amount +o withdraw after chec(ing +o displa, name 3 "alance. Code$using System; using System.Collections.Generic; using System.Text; namespace ConsolePrograms { class 9an&ManagmentSystem { string [] Aame/2T%eBepositor'ne0 string[*3]; int [] 9alanceCnT%eDccount'ne0 int[*3]; int [] DccountAo'ne0 int[*3]; string []Type/2Dcc'ne0 string[*3]; int i ' 3; pu1lic void Menu( { int a'*; Console.!rite"ine(#*.Beposition amount # ; Console.!rite"ine(#+. To 0it%dra0 # ; Console.!rite"ine(#?.To display name E 1alance.# ; Console.!rite"ine(#:.Ddd a record# ; Console.!rite(#$nter an option# ; 0%ile(aF'3 { int optn ' Console.(ead( ; ..Console.Clear( ; s0itc% (optn { case *G Bepoiste( ; 1rea&; case +G !it%dra0( ; 1rea&; case ?G BisplayCn2o( ; 1rea&; case :G Ddd( ; 1rea&; 7 Console.!rite"ine(#Hn B/ u 0ant to contineu press *# ; a 'Console.(ead( ; 7 7 pu1lic void Ddd( { Console.Clear( ; Console.!rite"ine(#$nter Aame o2 t%e Bepositor# ;

7 pu1lic void Bepoiste( { Console.Clear( ; Console.!rite"ine(#$nter Dccount no# ; int TempDcno 'Console.(ead( ; 2or(int 5'3;54i;5-i2 (TempDcno '' DccountAo[5] { Console.!rite"ine(#Hn$nter t%e Dmount to 1e Beposite# ; int TempDm 'Console.(ead( ; 9alanceCnT%eDccount[5] ' 9alanceCnT%eDccount[5] - TempDm; 7 else { Console.!rite"ine(#Sorry no Dccont exist o2 t%is num1er# ; 7 7 pu1lic void !it%dra0( { Console.Clear( ; Console.!rite"ine(#$nter Dccount no# ; int TempDcno ' int.Parse(Console.(ead"ine( ; 2or (int 5 ' 3; 5 4 i; 5-i2 (TempDcno '' DccountAo[5] { Console.!rite"ine(#Hn$nter t%e Dmount to 1e !idra0# ; int TempDm ' Console.(ead( ; i2 (TempDm 6 9alanceCnT%eDccount[5] { Console.!rite"ine(#HnSorry insu22icint 9alance# ; 7 else { 9alanceCnT%eDccount[5] ' 9alanceCnT%eDccount[5] ) TempDm; 7 7 else { Console.!rite"ine(#Sorry no Dccont exist o2 t%is num1er# ; 7 7 pu1lic void BisplayCn2o( { Console.Clear( ; Console.!rite"ine(#$nter Dccount no 0%ome in2ormation you 0ant to display# ; int TempDcno ' int.Parse(Console.(ead"ine( ; 2or (int 5 ' 3; 5 4 i; 5-i2 (TempDcno '' DccountAo[i] {

Aame/2T%eBepositor[i] ' Console.(ead"ine( ; ; Console.!rite"ine(#$nter Type o2 acc# ; Type/2Dcc[i] ' Console.(ead"ine( ; Console.!rite"ine(#$nter 9alance in t%e Dccount# ; 9alanceCnT%eDccount[i] ' Console.(ead( ; Console.!rite"ine(#$nter Dccount no# ; DccountAo[i] ' int.Parse(Console.(ead"ine( ; int 5 ' Console.(ead( ; i--;

Console.!rite"ine(Aame/2T%eBepositor[5] ; Console.!rite"ine(9alanceCnT%eDccount[5] ; 7 else { Console.!rite"ine(#Sorry no Dccont exist o2 t%is num1er# ; 7 7 7 7

using System; using System.Collections.Generic; using System.Text; namespace ConsolePrograms { class Program { static void Main(string[] args { 9an&ManagmentSystem 1s ' ne0 9an&ManagmentSystem( ; 1s.Menu( ; 7 7 7 OUTPUT

Q4. Write a program to read 5-6 file and displa, all the values in a read onl, Form.

Code$using using using using System; System.Collections.Generic; System.Text; System.Iml;

namespace ConsolePrograms { class IM"(eading { pu1lic IM"(eading( { ImlText(eader xml ' ne0 ImlText(eader(#eGHHperls.xml# ; 0%ile (xml.(ead( { s0itc% (xml.AodeType { case ImlAodeType.$lementG .. T%e node is an element. Console.!rite(#4# - xml.Aame ; 0%ile (xml.MoveToAextDttri1ute( Console.!rite(# # - xml.Aame - #'J# - xml.Kalue - #J# ; Console.!rite"ine(#6# ; 1rea&; case ImlAodeType.TextG Console.!rite"ine(xml.Kalue ; 1rea&; case ImlAodeType.$nd$lementG Console.!rite(#4.# - xml.Aame ; Console.!rite"ine(#6# ; 1rea&; 7 7 7 7 7

using System; using System.Collections.Generic; using System.Text; namespace ConsolePrograms { class Program { static void Main(string[] args { IM"(eading x ' ne0 IM"(eading( ; 7 7 7

Perls.xml

OUTPUT

10

Q!.Write a program to illustrate overloading an indexer. Code$using System; using System.Collections.Generic; using System.Text; namespace ConsolePrograms { class Cndexer/verloading { private string[] myBata; private int arrSiLe; pu1lic Cndexer/verloading(int siLe { arrSiLe ' siLe; myBata ' ne0 string[siLe]; 2or (int i'3; i 4 siLe; i-{ myBata[i] ' #empty#; 7

pu1lic string t%is[int pos] { get { return myBata[pos]; 7 set { myBata[pos] ' value; 7 7 pu1lic string t%is[string data] { get { int count ' 3; 2or (int i'3; i 4 arrSiLe; i-{ i2 (myBata[i] '' data { count--; 7 7 return count.ToString( ;

7 set

2or (int i'3; i 4 arrSiLe; i-{ i2 (myBata[i] '' data {

11

7 7 7 7 7 7

myBata[i] ' value;

using System; using System.Collections.Generic; using System.Text; namespace ConsolePrograms { class Program { static void Main(string[] args { int siLe ' *3; Cndexer/verloading myCnd ' ne0 Cndexer/verloading(siLe ; myCnd[=] ' #Some Kalue#; myCnd[?] ' #Dnot%er Kalue#; myCnd[@] ' #Dny Kalue#; myCnd[#empty#] ' #no value#; Console.!rite"ine(#HnCndexer /utputHn# ; 2or (int i ' 3; i 4 siLe; i-{ Console.!rite"ine(#myCnd[{37]G {*7#; i; myCnd[i] ; 7 Console.!rite"ine(#HnAum1er o2 H#no valueH# entriesG {37#; myCnd[#no value#] ; 7 7 7 OUTPUT

12

Q6.Write

a program with MenuBar, ContextBar an !oo"Bar.

#o""owing $tem% to &e a e un er ea'h Bar() MenuBar( *%e +''e%% ,e-, .eperator &ar an %hort'ut ,e1/ #i"e 2/ 0 it 3/ 1iew 4/ 2e"p ContextBar ( *%e +''e%% ,e-, .eperator &ar 1/Cut 2/Cop3/3a%te 4/#ont !oo"Bar(*%e $mage, too"tip 1/4#ont .t-"e/5i%tBox 2/4#ont 6ame/ 5i%tBox 3/4#ont .i7e/5i%t&ox 4/B859 5/$!+5$C. 6/*n er"ine
Code$-

13

14

:7.Create a #orm in win ow% app"i'ation ;or the 'u%tomer re'or ha<ing text&ox o; 8r er$9, Cu%tomer$9 an %hippe 9ate an =e'or num&er with $6.0=!, *39+!0, 905!0 &utton% an a"%o popu"ate the ata u%ing gri .
Code$using using using using using System; System.Collections.Generic; System.Text; System.Bata.SMl; System.Bata./d1c;

namespace Customer(ecordM*? { class Bata9aseConnectivity { /d1cConnection mc; /d1cCommand odcom; /d1cBata(eader reader; pu1lic Bata9aseConnectivity( { try { String myConString ' #BSA'myC9TBDTD#; mc ' ne0 /d1cConnection(myConString ; mc./pen( ; 7 catc% (Cnvalid/peration$xception iox { Console.!rite"ine(iox.Message ; 7 7 pu1lic /d1cBata(eader GetBata(string Nuery ..Muery 2or return odcom ' ne0 /d1cCommand(Nuery; mc ; reader ' odcom.$xecute(eader( ; mc.Close( ; return reader; 7 pu1lic int SetBata(string Nuery ..Muery 2or insert { int a ' 3; odcom ' ne0 /d1cCommand(Nuery; mc ; a ' odcom.$xecuteAonNuery( ; return a; 7 7 7 using System; using System.Collections.Generic; using System.ComponentModel;

15

using using using using using

System.Bata; System.Bra0ing; System.Text; System.!indo0s.Oorms; System.Bata./d1c;

namespace Customer(ecordM*? { pu1lic partial class Oorm* G Oorm { string /rderCB; string CustomerCB; string s%ippedBate; string (ecordAum1er; Bata9aseConnectivity d1; pu1lic Oorm*( { CnitialiLeComponent( ; 7 private void 1utton:PClic&(o15ect sender; $ventDrgs e { BataOorm d2' ne0 BataOorm( ; d2.S%o0( ; 7 private void 1utton*PClic&(o15ect sender; $ventDrgs e { int a'3; /rderCB ' text9ox*.Text; CustomerCB ' text9ox+.Text; s%ippedBate ' text9ox?.Text; (ecordAum1er ' text9ox:.Text; d1 ' ne0 Bata9aseConnectivity( ; string Nuery ' #insert into customerrecord value(J#-/rderCB-#J;J#-CustomerCB-#J;J#-s%ippedBate-#J;J#-(ecordAum1er-#J#; Nuery ' Nuery - # #; a ' d1.SetBata(Nuery ; i2 (a '' 3 { Message9ox.S%o0(#C%ec& input data# ; 7 else { 7 7 private void 1utton?PClic&(o15ect sender; $ventDrgs e { int a ' 3; string id ' text9ox@.Text; i2 (id.$Muals(## { Message9ox.S%o0(#$nter an /rder CB 2or delete# ; 7 else 1lan&( ;

16

{ - id - #J#;

string Nuery ' #delete 2rom customerrecord 0%ere /rderCB'J# d1.SetBata(Nuery ; i2 (a '' 3 { Message9ox.S%o0(#$rror in deleting# ; 7 else { Message9ox.S%o0(#Succes2lly deleted# ; 7

7 7 private void 1utton+PClic&(o15ect sender; $ventDrgs e { /d1cBata(eader reader; string id ' text9ox@.Text; string Nuery ' #select , 2rom customerrecord 0%ere /rderCB'J#-id-#J#; reader ' d1.GetBata(Nuery ; 1lan&( ; 0%ile (reader.(ead( { text9ox*.Text ' reader.GetString(3 text9ox+.Text ' reader.GetString(* text9ox?.Text ' reader.GetString(+ text9ox:.Text ' reader.GetString(? 7 ..1utton*.Text'#Qpdate#; 7 pu1lic void 1lan&( { text9ox*.Text ' text9ox+.Text ' text9ox?.Text ' text9ox:.Text ' 7 7 7

; ; ; ;

##; ##; ##; ##;

17

:8 Create a +.3.60! page to ;i"" %tu ent etai"%. *%e an- o; the 'omponent% a<ai"a&"e a% eeme ;it ;or the re>uirement% . on the pre%% o; %a<e &utton u%er %hou" &e a&"e to %a<e the ;orm ata in a m-%>" ta&"e .
Code$using using using using using using using using using using using System; System.Bata; System.Con2iguration; System.!e1; System.!e1.Security; System.!e1.QC; System.!e1.QC.!e1Controls; System.!e1.QC.!e1Controls.!e1Parts; System.!e1.QC.RtmlControls; System.Bata./d1c; System.Bata.SMl;

... 4summary6 ... Summary description 2or BataConnectivityProgram ... 4.summary6 pu1lic class BataConnectivityProgram { /d1cConnection mc; /d1cCommand odcom; /d1cBata(eader reader; pu1lic BataConnectivityProgram( { try { String myConString ' #BSA'MSC9TBDTD#; mc ' ne0 /d1cConnection(myConString ; mc./pen( ; 7 catc% (Cnvalid/peration$xception iox { Console.!rite"ine(iox.Message ; 7 7 pu1lic int SetBata(string Nuery ..Muery 2or insert { int a ' 3; odcom ' ne0 /d1cCommand(Nuery; mc ; a'odcom.$xecuteAonNuery( ; mc.Close( ; return a; 7

18

19

:9 Create an +.3 page to i%p"a- the ata o; %tu ent% entere in the pre<iou% ;orm in ta&u"ar ;ormat u%ing an- o; the gri % . u%e 9ata%et to popu"ate the gri .
Code$-

20

Das könnte Ihnen auch gefallen