CISY2320 Assignment 3 in C#

Objective:

This assignment is designed to learn programming in C#.

 

Questions:

(1) (2 marks) In Visual Studio, create and test a C# console application that does the following:

(1) Create three variables of the string data type, named first_name, last_name, and

full_name respectively;

(2) Use the built-in function Console.ReadLine() to get the user’s input for first_name

and last_name using the following statements: Console.WriteLine(“Enter your first name:”); first_name = Console.ReadLine(); Console.WriteLine(“Enter your last name:”); last_name = Console.ReadLine();

(3) Concatenate the variables first_name and last_name together, and then assign the result to the variable full_name as follows (there is a space between the two double quotes):

full_name = first_name + “ ” + last_name;

(4) Use the following statement to display the output:

Console.WriteLine(“Thank you ” + full_name);

 

(2) (4 marks) In Visual Studio, create and test a C# console application that does the following:

(1) Create three variables of int data type, named x, y, z respectively;

(2) Use the built-in function Console.ReadLine() to get the user’s input for x and y as follows (it is assumed that the user always inputs integers when testing this program):

Console.WriteLine(“Input the first number:”); x = Convert.ToInt32(Console.ReadLine());

Console.WriteLine(“Input the second number:”); y = Convert.ToInt32(Console.ReadLine());

(3) Compute the smaller of x and y, and then assign the result to z as follows:

if (x < y)

{

    z = x;

}

else

{

    z = y;

}

(4) Use the following statements to display the output:

Console.WriteLine(“The smaller of the two numbers is”);

 

Console.WriteLine(z);

 

(3) (5 marks) In Visual Studio, create and test a C# console application that does the following:

(1) Create a variable of the int data type, named marks;

(2) Create a variable of the string data type, named grade;

(3) Use the built-in function Console.ReadLine() to get the user’s input for marks as follows (it is assumed that the user always inputs integers when testing this program):

Console.WriteLine(“Input the marks:”);

marks = Convert.ToInt32(Console.ReadLine());

(4) Convert marks into grade as follows using an else-if statement:

 

marks grade

90-100 A+

85-89 A

80-84 A-

77-79 B+

73-76 B

70-72 B-

67-69 C+

63-66 C

60-62 C-

50-59 D

0-49 F

(5) Display the value of grade in the console window using the following statement:

Console.WriteLine(“The grade is ” + grade);

 

(4) (4 marks) Repeat Question 3 using the switch statement (instead of the else-if statement). For simplicity, you may assume the user always inputs an integer between 0 and 100.

 

Hint: The switch statement is a lengthy one and is similar to the following:

switch (marks)

{

case 90: case 91: case 92: case 93: case 94: case 95:

case 96: case 97: case 98: case 99: case 100: grade = “A+”;

break;

case 85: case 86: case 87: case 88: case 89: grade = “A”;

break;

……..

……..

case 50: case 51: case 52: case 53: case 54:

case 55: case 56: case 57: case 58: case 59: grade = “D”;

break; default:

grade = “F”; break;

}

Need a custom answer at your budget?

This assignment has been answered 5 times in private sessions.

Or buy a ready public solution below.

Buy ready solution

Solution previews

© 2020 Codify Tutor. All rights reserved