M107 -nbsp what is type casting in c name the two forms of


Part I: Theoretical Questions

1. What is Type Casting in C#? Name the two forms of Type Castings in C#. Why is it needed?

2. What are the access modifiers in C#?

3. State the different ways of passing parameters to a method in C#.

4. Does C# support multiple inheritance? Explain how multiple inheritance can be implemented in C# with the help of an example.

5. Consider the following code. Convert the if-else statement to switch-case.

if (opt == 1)
{
result = num1 + num2;
Console.WriteLine("\n{0} + {1} = {2}", num1, num2, result); }
else if (opt == 2)
{
result = num1 - num2;
Console.WriteLine("\n{0} - {1} = {2}", num1, num2, result); }
else if (opt == 3)
{
result = num1 * num2;
Console.WriteLine("\n{0} * {1} = {2}", num1, num2, result);
}
else if (opt == 4)
{
result = (float)num1 / num2;
Console.WriteLine("\n{0} / {1} = {2}", num1, num2, result);
}
else { Console.WriteLine("\nInvalid option.Please try again.");
}

Part II: Output and Debugging Questions

Note: Provide a copy of the code and screen shot for the output in the solutions

1. Consider the program below. Will the program generate an output? If not, why? Write the corrected program.

class Program
{
static void Main(string [] args)
{
const int a = 5;
const int b = 6;
for (int i = 1; i <= 5; i++)
{
a = a * i;
b = b * i;
}
Console.WriteLine(a);
Console.WriteLine(b);
Console.ReadLine();
}
}

2. What is the output of the following program?

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int p, q;
int[,] M = new int[5, 5];
for (p = 0; p < 5; ++p)
{
for (q = 0; q < 5; ++q)
{
M[p, q] = p * 1 + q * 1;
Console.Write(M[p, q] + " ");

} Console.Write("\n");

} Console.ReadLine();

}
}
}

3. Identify the errors in the following C# program. Write the correct program. [4 marks]

class Program
{
static void Main(string[] args)
{
/ This is a comment
integer m=9,
Console.WriteLine("value = ', m);

}
}

Part III- Problem Solving Questions

Note: Provide a copy of the code and screen shot for the output in the solutions

1. Using loops, write a C# program which accepts the number of rows and then prints a pattern according to the number of rows as shown below.

Enter number of rows :6

$
$$
$$$
$$$$
$$$$$

2. Write a C# program to:-
a. Define a two dimensional array of three rows and three columns.
b. Read array elements from the keyboard.
c. Print the array elements.
d. Calculate the sum of diagonal elements and print the sum.

1654_Figure1.jpg

3. Write a C# program to
a. Input a string from the keyboard
b. Print the given string
c. Reverse the string and print it.
d. Print the reversed string in capital letters.

1743_Figure2.jpg

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: M107 -nbsp what is type casting in c name the two forms of
Reference No:- TGS01683438

Expected delivery within 24 Hours