Section-A June2018 Task1:Initializingarray. 1. Reversinganarray: class ArrayReverseExample { static void Main() { int[] array = { 1, 2, 3, 4, 5 }; // Get array size int length = array.Length; //...

Tell me price quick


Section-A June2018 Task1:Initializingarray. 1. Reversinganarray: class ArrayReverseExample { static void Main() { int[] array = { 1, 2, 3, 4, 5 }; // Get array size int length = array.Length; // Declare and create the reversed array int[] reversed = new int[length]; // Initialize the reversed array for (int index = 0; index < length;="" index++)="" {="" reversed[length="" -="" index="" -="" 1]="array[index];" }="" print="" the="" reversed="" array="" for="" (int="" index="0;" index="">< length;="" index++)="" {="" console.write(reversed[index]="" +="" "="" ");="" }="" }="" }="" 2.="" here="" is="" the="" result="" of="" the="" above="" example’s="" execution="" for="" n="7:" 5="" 4="" 3="" 2="" 1="" task="" 2:="" reading="" an="" array="" from="" the="" console="" 1.="" declaring="" array="" dynamically="" and="" assigning="" values="" at="" run="" time="" to="" it="" int="" n="int.Parse(Console.ReadLine());" int[]="" array="new" int[n];="" for="" (int="" i="0;" i="">< n;="" i++)="" {="" array[i]="int.Parse(Console.ReadLine());" }="" task="" 3:="" printing="" an="" array="" to="" the="" console="" 1.="" displaying="" array="" values="" string[]="" array="{" "one",="" "two",="" "three",="" "four"="" };="" console.writeline(array);="" string[]="" array1="{" "one",="" "two",="" "three",="" "four"="" };="" for="" (int="" index="0;" index="">< array.length;="" index++)="" {="" print="" each="" element="" on="" a="" separate="" line="" console.writeline("element[{0}]="{1}"," index,="" array[index]);="" }="" 2.="" we="" are="" iterating="" through="" the="" array="" using="" the="" for-loop,="" which="" will="" go="" array.length="" times,="" and="" we="" will="" print="" the="" current="" element="" using="" console.writeline()="" and="" a="" formatted="" string.="" here="" is="" the="" result:="" element[0]="one" element[1]="two" element[2]="three" element[3]="four" task="" 4:="" symmetric="" array="" 1.="" to="" check="" whether="" the="" array="" values="" inserted="" are="" symmetric="" or="" not.="" few="" examples="" of="" symmetric="" arrays="" are="" given="" below:="" 1="" 2="" 2="" 1="" 1="" 2="" 5="" 2="" 1="" 1="" 2="" 5="" 5="" 2="" 1="" console.write("enter="" a="" positive="" integer:="" ");="" int="" n="int.Parse(Console.ReadLine());" int[]="" array="new" int[n];="" console.writeline("enter="" the="" values="" of="" the="" array:");="" for="" (int="" i="0;" i="">< n;="" i++)="" {="" array[i]="int.Parse(Console.ReadLine());" }="" bool="" symmetric="true;" for="" (int="" i="0;" i="">< array.length="" 2;="" i++)="" {="" if="" (array[i]="" !="array[n" -="" i="" -="" 1])="" {="" symmetric="false;" break;="" }="" }="" console.writeline("is="" symmetric?="" {0}",="" symmetric);="" task="" 5:="" two-dimensional="" array="" 1.="" reading="" matrices="" from="" the="" console:="" console.write("enter="" the="" number="" of="" the="" rows:="" ");="" int="" rows="int.Parse(Console.ReadLine());" console.write("enter="" the="" number="" of="" the="" columns:="" ");="" int="" cols="int.Parse(Console.ReadLine());" int[,]="" matrix="new" int[rows,="" cols];="" console.writeline("enter="" the="" cells="" of="" the="" matrix:");="" for="" (int="" row="0;" row="">< rows;="" row++)="" {="" for="" (int="" col="0;" col="">< cols;="" col++)="" {="" console.write("matrix[{0},{1}]=",row, col); matrix[row, col] = int.Parse(Console.ReadLine()); } } for (int row = 0; row < matrix.GetLength(0); row++) { for (int col = 0; col < matrix.GetLength(1); col++) { Console.Write(" "="" +="" matrix[row,="" col]);="" }="" console.writeline();="" }="" 2.="" the="" program="" output="" when="" we="" execute="" it="" is="" enter="" the="" number="" of="" the="" rows:="" 3="" enter="" the="" number="" of="" the="" columns:="" 2="" enter="" the="" cells="" of="" the="" matrix:="" matrix[0,0]="2" matrix[0,1]="3" matrix[1,0]="5" matrix[1,1]="10" matrix[2,0]="8" matrix[2,1]="9" 2="" 3="" 5="" 10="" 8="" 9="" task="" 6:="" jagged="" array="" 1.="" develop="" a="" program="" to="" generate="" and="" visualize="" the="" pascal’s="" triangle:="" 1="" 1="" 1="" 1="" 2="" 1="" 1="" 3="" 3="" 1="" 1="" 4="" 6="" 4="" 1="" .="" .="" .="" class="" pascaltriangle="" {="" static="" void="" main()="" {="" const="" int="" height="12;" allocate="" the="" array="" in="" a="" triangle="" form="" long[][]="" triangle="new" long[height="" +="" 1][];="" for="" (int="" row="0;" row="">< height;="" row++)="" {="" triangle[row]="new" long[row="" +="" 1];="" }="" calculate="" the="" pascal's="" triangle="" triangle[0][0]="1;" for="" (int="" row="0;" row="">< height="" -="" 1;="" row++)="" {="" for="" (int="" col="0;" col=""><= row;="" col++)="" {="" triangle[row="" +="" 1][col]="" +="triangle[row][col];" triangle[row="" +="" 1][col="" +="" 1]="" +="triangle[row][col];" }="" }="" print="" the="" pascal's="" triangle="" for="" (int="" row="0;" row="">< height;="" row++)="" {="" console.write("".padleft((height="" -="" row)="" *="" 2));="" for="" (int="" col="0;" col=""><= row;="" col++)="" {="" console.write("{0,3}="" ",="" triangle[row][col]);="" }="" console.writeline();="" }="" }="" }="" 2.="" the="" program="" output="" when="" we="" execute="" it="" is="" 1="" 1="" 1="" 1="" 2="" 1="" 1="" 3="" 3="" 1="" 1="" 4="" 6="" 4="" 1="" 1="" 5="" 10="" 10="" 5="" 1="" 1="" 6="" 15="" 20="" 15="" 6="" 1="" 1="" 7="" 21="" 35="" 35="" 21="" 7="" 1="" 1="" 8="" 28="" 56="" 70="" 56="" 28="" 8="" 1="" ……="" 1="" 11="" 55="" 165="" 330="" 462="" 462="" 330="" 165="" 55="" 11="" 1="" exercise="" 7.1="" develop="" a="" program="" which="" will="" initialize="" array="" dynamically,="" take="" input="" values="" for="" array,="" and="" display="" the="" values="" of="" array="" on="" the="" console.="" 7.2="" develop="" a="" program="" which="" will="" find="" the="" sub-matrix="" of="" size="" of="" 2="" by="" 2="" with="" maximum="" sum="" of="" its="" elements="" from="" a="" two-dimensional="" rectangular="" (example:="" 4="" rows="" and="" 6="" columns)="" array="" (matrix)="" of="" integers,="" and="" print="" it="" to="" the="" console.="" section-b="" task="" 1:="" substring.="" 1.="" write="" a="" program="" to="" list="" all="" substrings="" in="" a="" given="" string.="" using="" system;="" namespace="" mismatch="" {="" class="" program="" {="" string="" value,="" substring;="" int="" j,="" i;="" string[]="" a="new" string[5];="" void="" input()="" {="" console.writeline("enter="" the="" string="" :="" ");="" value="Console.ReadLine();" console.writeline("all="" possible="" substrings="" of="" the="" given="" string="" are="" :");="" for="" (i="1;" i=""><=value.length; i++)="" {="" for="" (j="0;" j=""><= value.length="" -="" i;="" j++)="" {="" substring="value.Substring(j," i);="" a[j]="substring;" console.writeline(a[j]);="" }="" }="" }="" public="" static="" void="" main()="" {="" program="" pg="new" program();="" pg.input();="" console.readline();="" }="" }="" }="" 2.="" here="" is="" the="" output="" of="" the="" c#="" program.="" enter="" the="" string="" :="" abab="" all="" possible="" substrings="" of="" the="" given="" string="" are="" :="" a="" b="" a="" b="" ab="" ba="" ab="" aba="" bab="" abab="" task="" 2:="" reversing="" string="" 1.="" c#="" program="" to="" reverse="" a="" string="" without="" using="" reverse="" function="" using="" system;="" class="" program="" {="" static="" void="" main(string[]="" args)="" {="" string="" str,="" reversestring="" ;="" int="" length;="" console.write("enter="" a="" string="" :="" ");="" str="Console.ReadLine();" length="Str.Length" -="" 1;="" while="" (length="">=0) { reversestring=reversestring+Str[Length]; Length--; } Console.WriteLine("ReverseStringIs{0}",reversestring);Console.ReadLine(); } } 2. HereistheoutputoftheC#Program. EnteraString:MelbourneReverseStringis:enruobleM Task3:ReplaceString 1. WriteaProgramtoReplaceStringinString usingSystem; classProgram { staticvoidMain() { conststrings="SunRisesintheWest"; Console.WriteLine("SentenceBeforeReplacing:{0}",s); strings1=s.Replace("West","East"); Console.WriteLine("SentenceAfterReplacing:{0}",s1); Console.ReadLine(); } } 2. HereistheoutputoftheC#Program. SentenceBeforeReplacing:SunRisesintheWest SentenceAfterReplacing:SunRisesintheEast Exercises 8.1WriteaC#programtoTrimtheGivenString. 8.2WriteaC#programtoConvertUppercasetoLowerCase. Section –C Task1:Functionwithparameters. 1. WriteafunctionFindMaxthattakestwointegervaluesandreturnsthelargerofthetwo.Ithaspublicaccessspecifier,soitcanbeaccessedfromoutsidetheclassusinganinstanceoftheclass. public static int FindMax(int num1, num2) int { /* local variable declaration */ int result; if num2) > num1 ( num1; result = else result = num2; return result; results // returning } 2. AddfollowingcodesegmentintheMainfunction.inta=100;intb=200; intret; //callingtheFindMaxmethod ret=FindMax(a,b); Console.WriteLine("Maxvalueis:{0}",ret); 3. Hereistheresultoftheaboveexample’sexecution:Maxvalueis:200 Task2:Callingfunctionwithargumentsofpassbyreference. 1. Writeafunctionswapnumthattakestwointegervaluesandinterchangethevalueofvariables.Ithaspublicaccessspecifier,soitcanbeaccessedfromoutsidetheclassusinganinstanceoftheclass. publicstaticvoidswapnum(refintx,refinty) { inttemp; temp=x;/*savethevalueofx*/ x =y;/*putthevalueofyintox*/ y =temp;/*putvalueoftempintoy*/ } 2. NowcalltheswapnumfunctionwithintheMainfunction inta=100;intb=200; Console.WriteLine("Beforeswap,valueofa:{0}",a); Console.WriteLine("Beforeswap,valueofb:{0}",b); /*callingafunctiontoswapthevalues*/swapnum(refa,refb); Console.WriteLine("Afterswap,valueofa:{0}",a); Console.WriteLine("Afterswap,valueofb:{0}",b); 3. Hereistheresultoftheaboveexample’sexecution: Beforeswap,valueofa:100 Beforeswap,valueofb:200 Afterswap,valueofa:200 Afterswap,valueofb:100 Task3:Writetwofunctionstoachievetwofunctionalitiesseparately. 1. Writeaprogramtwoachievefunctionalityofadditionandsubtractionrespectively. publicintsubtract(intfirstNumber,intsecondNumber) { intanswer; answer=firstNumber-secondNumber; returnanswer; } publicintaddUp(intfirstNumber,intsecondNumber) { intanswer; answer=firstNumber+secondNumber; returnanswer; } 2. CreatenewclasswithnameProgram.CallbothfunctionsfromMainfunction.Usefollowingcode.intnumber1=20;intnumber2=7;intsubAnswer; intaddAnswer; //creatinganobjectofcalculatorclass Programcal=newProgram();subAnswer=cal.subtract(number1,number2);addAnswer=cal.addUp(number1,number2); Console.WriteLine("Additionansweris{0}",subAnswer); Console.WriteLine("Subtractionansweris{0}",addAnswer); Console.Read(); 3. Hereistheresultoftheaboveexample’sexecution: Additionansweris27 Subtractionansweris13 Task4:Recursivefunction. 1. Writeaprogramwhichreadsanintegerfromtheconsole,computesitsfactorialandthenprintstheobtainedvalue. staticdecimalFactorial(intn) { //Thebottomoftherecursionif(n==0) {return1; } //Recursivecall:themethodcallsitselfelse {returnn*Factorial(n-1); } } 2. CallMethodFactorialintheMainMethodasbelow. staticvoidMain() { Console.Write("n="); intn=int.Parse(Console.ReadLine());decimalfactorial=Factorial(n); Console.WriteLine("{0}!={1}",n,factorial); } 3. Hereistheresultoftheaboveexample’sexecutionforn=5: 5!=120 Exercises 9.1 WriteaC#programwithfollowingmethod. MethodName-CalcDiscount Returntype–float Parameters–Theamountandthepercentageinfloat Taskofthemethod–Calculatethevalueforthegivenamountusinggivenpercentageandreturnthediscountvalue.(e.g.,amount=amount*percentage/100) 9.2 AddtwomoreMethodstoyourcodeintask3,likeMultiplyandDivide. Section –D June 2018 Objective(s) This assessment item relates to the unit learning outcomes as in the unit descriptors. This checks your understanding about basic constructs of C# programming. ITAP 1001 Assignment Details & Problems In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console Programs to demonstrate your ability to use C# input/output via command line, C# primitive and built-in C# types, C# operators and expression, C# conditional statements, C# loop construct, and show your ability to validate the inputs to avoid run-time errors. Q1) What is managed and unmanaged code? Q2) Give examples of reserved keyword, literals and data types in C#. Q3) What is the difference between “continue” and “break” statements in C#? Explain it with example. Q4) What will be the output / error of given program? static void Main(String[] args) { const int m = 100; int n = 10; const int k = n / 5 * 100 * n; Console.WriteLine(m * k); Console.ReadLine(); } Q5) Give the output for the set of programming code. class Program { static void Main(string[] args) { int i; for ( i = 0; i < 5; i++) copyright © 2015-2018 vit, all rights reserved. 2 { } console. writeline(i); itap 1001 assignment console. readline(); } } q6) write a program that would convert temperature given in centigrade scale to fahrenheit – the number can be integer or real. use the formula: f = 1.8c + 32 q7) given a three-digit integer as input write a c# program to determine whether the number is an armstrong number. an armstrong number is one for which the sum of each digit raised to the power of number of digits results in the number itself. for a three digit number 153 = 13 + 53 + 33 note: confine to 3-digit examples only i.e., number values between 100 to 999. q8) use euclid's algorithm given below to determine the lcm and hcf for given two integer numbers. · take in as input two numbers a and b. · subtract the smaller of the two numbers from the larger number and assign the answer to the larger number. · the above process is repeated until both the numbers are equal, say x. · apparently, the residual number (x) that we have obtained is the hcf. · lcm could then be computed using the formula (a*b)/hcf print out your answers. 5;="" i++)="" copyright="" ©="" 2015-2018="" vit,="" all="" rights="" reserved.="" 2="" {="" }="" console.="" writeline(i);="" itap="" 1001="" assignment="" console.="" readline();="" }="" }="" q6)="" write="" a="" program="" that="" would="" convert="" temperature="" given="" in="" centigrade="" scale="" to="" fahrenheit="" –="" the="" number="" can="" be="" integer="" or="" real.="" use="" the="" formula:="" f="1.8C" +="" 32="" q7)="" given="" a="" three-digit="" integer="" as="" input="" write="" a="" c#="" program="" to="" determine="" whether="" the="" number="" is="" an="" armstrong="" number.="" an="" armstrong="" number="" is="" one="" for="" which="" the="" sum="" of="" each="" digit="" raised="" to="" the="" power="" of="" number="" of="" digits="" results="" in="" the="" number="" itself.="" for="" a="" three="" digit="" number="" 153="13" +="" 53="" +="" 33="" note:="" confine="" to="" 3-digit="" examples="" only="" i.e.,="" number="" values="" between="" 100="" to="" 999.="" q8)="" use="" euclid's="" algorithm="" given="" below="" to="" determine="" the="" lcm="" and="" hcf="" for="" given="" two="" integer="" numbers.="" ·="" take="" in="" as="" input="" two="" numbers="" a="" and="" b.="" ·="" subtract="" the="" smaller="" of="" the="" two="" numbers="" from="" the="" larger="" number="" and="" assign="" the="" answer="" to="" the="" larger="" number.="" ·="" the="" above="" process="" is="" repeated="" until="" both="" the="" numbers="" are="" equal,="" say="" x.="" ·="" apparently,="" the="" residual="" number="" (x)="" that="" we="" have="" obtained="" is="" the="" hcf.="" ·="" lcm="" could="" then="" be="" computed="" using="" the="" formula="" (a*b)/hcf="" print="" out="" your="">
Oct 21, 2020
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here