What is type casting in c#

Assignment Help Programming Languages
Reference no: EM131280682

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

Reference no: EM131280682

Questions Cloud

How much power is being supplied to the pump : Water at 40 °C is pumped from an open tank through 200 m of 50-mm-diameter smooth horizontal pipe as shown in Fig. P12.22 and discharges into the atmosphere with a velocity of 3 m/s. Minor losses are negligible.
Explain how conflicts can be constructive : Explain how conflicts can be constructive. What are superordinate goals and how do they help resolve conflicts between antagonistic groups? What are superordinate goals and how do they help resolve conflicts between antagonistic groups? How does dive..
Different kinds of involvement : Is it always good? What key elements are necessary to keep it going? Are there different kinds of involvement?
Predict the future of healthcare delivery in the us : For our final discussion of the class, I would like for you to predict the future of healthcare delivery in the U.S. Review the resources for this week and critique how well you really think they'll work.
What is type casting in c# : M107 -  What is Type Casting in C#? Name the two forms of Type Castings in C#. Why is it needed and what are the access modifiers in C# - state the different ways of passing parameters to a method in C#.
How receiver of delta sigma modulation system is simplified : 1-bit modulation merely restates that the quantizer consists of a hard limiter with only two representation levels. Explain how the receiver of the delta-sigma modulation system is simplified, compared with conventional DM.
Chinese government owns the land : Chinese government owns the land). If you are in Dubai, you can purchase alcohol, but you will need a special license to purchase alcohol. You will also learn that school tuition cost more than an Ivy League education, but fortunately, your comp..
Explain how conflicts can be constructive : How would you analyze supply and demand for health care services? Do you ever think that health care moves too fast in initiating or adopting change? Why or why not? How would you handle a client that is constantly in with the project team and direct..
The importance of the project leaders attitude : The importance of the project leader’s attitude and leadership in reporting progress to stakeholders and senior management.

Reviews

len1280682

11/18/2016 12:22:14 AM

I want this assignment. It's of IT. Please tell the tutor to go through the assignment carefully. And hire the best tutor for it who has good knowledge and experience. Please make sure the tutor sure enough to do the assignment perfectly. Thanks

Write a Review

Programming Languages Questions & Answers

  Write program to accept data for each student

Write a program that accepts data for each student in the school - Student ID, classroom number, and score on the achievement test. Design a program that lists the total points scored for each of the 30 classrooms.

  Write function which takes string as its input

In this, you are required to write the function which takes string as its input, chops sentence into words, and for each word, capitalizes the rst letter

  Prepare a php form which allows input for an individual and

create a php form that allows input for an individual and displays the information on a subsequent page upon

  Create a rexx program that asks a user for separate lines

Create a REXX program that asks a user for four separate lines of input, and then outputs those lines all at once, one line at a time

  Describe how to prepare users for sales organization unit

Describe how you would prepare the users for sales organization unit and how you can set up user groups in particular conditions (global, universal, domain local).

  Write a prolog program that finds the ast item in a list

Write a Prolog program that finds the ast item in a list. Add a test query.

  Calculate the sum of squares of numbers using for loop

Given int variables k and total which have already been declared, use for loop to calculate the sum of squares of first 50 counting numbers, and store this value in total.

  Write program which asks user for names

Write down a program which asks user for names (Prompt user with something like "Enter a name, or q when finished"), assigns new Person (in heap memory) for each of them.

  Write application that inputs a telephone number as string

Write an application that inputs a telephone number as a string in the form (555) 555-5555. The application should String method split to extract the area code as a token.

  Create program in visual studio-produce summary of ammounts

Create the program in Visual Studio, C#, 3.5 .Net that will produce the summary of amounts due for Pat's Auto Repair Shop. Display splash screen first.

  Advantages of turning the atm switches into lsr

Under these conditions, what are the advantages, if any, of turning the ATMswitches into LSRs, as opposed to using an overlay network?

  Create and run the functions in the debug window

Create and run the following functions in the Debug Window. Do not close the Debug Window yet -

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd