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 a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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