Skip To Content
    Dashboard
    • Login
    • Dashboard
    • Courses
    • Calendar
    • 0
      Inbox
    Close
    • My Dashboard
    • Assignments
    • Lab Tutorial - 2
    2022-23 (Odd)
    • Home
    • Modules

    Lab Tutorial - 2

    • Due No Due Date
    • Points 10
    • Submitting a file upload

    Sample Format for file upload.docx

    1 : Predict and write output for the following code.

    using System;

    namespace DecisionMaking

    {

        class Program

        {

            static void Main(string[] args)

            {

                /* local variable definition */

                int a = 10;

     

                /* check the boolean condition using if statement */

                if (a < 20)

                {

                    /* if condition is true then print the following */

                    Console.WriteLine("a is less than 20");

                }

                Console.WriteLine("value of a is : {0}", a);

                Console.ReadLine();

            }

        }

    }

     

    2 : Write missing statement to get the desired output.

    using System;

    namespace DecisionMaking

    {

       

        class Program

        {

            static void Main(string[] args)

            {

     

                /* local variable definition */

                int a = 100;

     

                /* check the boolean condition */

                if (a < 20)

                {

                    /* if condition is true then print the following */

                    Console.WriteLine("a is less than 20");

                }

                else

                {

                    /* if condition is false then print the following */

                       //………………………………Missing statement-1……………………………….//

                 }

                   //………………………………Missing statement-2……………………………….//                

                  Console.ReadLine();

            }

        }

    }

    Output

    a is not less than 20

    value of a is : 100

     

    3 : Correct the following code and write output for the corrected code.

    using System;

    namespace ConsoleApplication1

    {

        class Program

        {

            static void Main(string[] args)

            {

                char firstName = "John";

                char lastName = "Doe";

                Console.WriteLine("Name: " + firstName + " " + lastName);

     

                Console.WriteLine("Please enter a new first name:")

                firstName = Console.ReadLine();

     

                Console.WriteLine("New name: "  firstName  " "  lastName);

     

                Console.ReadLine();

            }

        }

    }

     

    4 : Input two number A and B. perform different operations using different operators and different data types available in C#. (Note : Follow all the operators and data types to do above task. Use Online help whenever necessary.)

     

    5 : Rearrange the given code to correct the program. The resultant program will be to enter 5 elements into an array and print sum of these elements.

     

    using System;

    namespace ConsoleApplication1

    {

        class Program

        {

            static void Main(string[] args)

            {

     

                for (int i = 0; i < 5; i++)

                {

                   

                    string str = Console.ReadLine();

        

                }

                for (int i = 0; i < 5; i++)

                {

                    sum = sum + arr[i];

                }

                Console.WriteLine("Sum of Elements : {0}",sum);

                int[] arr = new int[5];

                int sum = 0;

               arr[i] = Convert.ToInt32(str);

               Console.Write("Enter Element {0}: ", i);

                Console.Read();

            }

           

        }

    }

     

    Output:

    Enter Element 0: 1

    Enter Element 1: 2

    Enter Element 2: 3

    Enter Element 3: 4

    Enter Element 4: 5

    Sum of Elements : 15

     

    6: Write missing statement to get the desired output.

    using System;

    public class Hello3

    {

       public static void Main(string[] args)

       {

          Console.WriteLine("Hello, World!");

          Console.WriteLine("You entered the following {0} command line arguments:",

             args.Length );

              //………………………………Missing statement-1……………………………….//      

              //………………………………Missing statement-2……………………………….//       

              //………………………………Missing statement-3……………………………….//       

              //………………………………Missing statement-4……………………………….//       

       }

    }

     

    Output:

    -------------------

    Hello, World!

    You entered the following 4 command line arguments:

    A

    B

    C

    D

     

    7 : Predict and write the output of the given code.

    using System;

    namespace CalculatorApplication

    {

       class NumberManipulator

       {

          public void swap(ref int x, ref int y)

          {

             int temp;

             temp = x; /* save the value of x */

             x = y;   /* put y into x */

             y = temp; /* put temp into y */

           }

       }

      class TestRef

       {

          static void Main(string[] args)

          {

             NumberManipulator n = new NumberManipulator();

             /* local variable definition */

             int a = 100;

             int b = 200;

     

             Console.WriteLine("Before swap, value of a : {0}", a);

             Console.WriteLine("Before swap, value of b : {0}", b);

     

             /* calling a function to swap the values */

             n.swap(ref a, ref b);

     

             Console.WriteLine("After swap, value of a : {0}", a);

             Console.WriteLine("After swap, value of b : {0}", b);

     

             Console.ReadLine();

          }

       }

    }

     

    8 : Find out error code and correct it. Write the output of the corrected code.

    using System;

    namespace CalculatorApplication

    {

       class NumberManipulator

       {

          public int getValues(out int x, out int y, out int z )

          {

              Console.WriteLine("Enter the first value: ");

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

              Console.WriteLine("Enter the second value: ");

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

              sum = “x” + “y” + “z”;

              return “sum”;

          }

       }

     class TestOut

     {

          static void Main(string[] args)

          {

             NumberManipulator n = new NumberManipulator();

             /* local variable definition */

             int a , b, c, sum;

            

             /* calling a function to get the values */

             sum = n.getValues(out a, out b, out c);

     

             Console.WriteLine("After method call, value of a : {0}", a);

             Console.WriteLine("After method call, value of b : {0}", b);

             Console.WriteLine("After method call, value of c : {0}", c);

             Console.WriteLine("Sum : {0}", );

     

          }

       }

    }

    9 : Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers.

    Example 1:Input: 

     

    N = 2

    arr[] = {1, 2, 3, 2, 1, 4}

    Output:

    3 4 

    Explanation:

    3 and 4 occur exactly once.

     

    Example 2:

    Input:

    N = 1

    arr[] = {2, 1, 3, 2}

    Output:

    1 3

    Explanation:

    1 3 occur exactly once.




    10: Given a matrix mat[][] of size N x M, where every row and column is sorted in increasing order, and a number X is given. The task is to find whether element X is present in the matrix or not.

     

    Example 1:

    Input:

    N = 3, M = 3

    mat[][] = 3 30 38 

             44 52 54 

             57 60 69

    X = 62

    Output:

    0

    Explanation:

    62 is not present in the

    matrix, so output is 0

     

    Example 2:

    Input:

    N = 1, M = 6

    mat[][] = 18 21 27 38 55 67

    X = 55

    Output:

    1

    Explanation:

    55 is present in the

    matrix at 5th cell.

     

    Your Task:

    You don't need to read input or print anything. You just have to complete the function matSearch() which takes a 2D matrix mat[][], its dimensions N and M and integer X as inputs and returns 1 if the element X is present in the matrix and 0 otherwise.

     

    Expected Time Complexity: O(N+M).

    Expected Auxiliary Space: O(1).

     

    Constraints:

    1 <= N, M <= 1005

    1 <= mat[][] <= 10000000

    1<= X <= 10000000

     

    11: Write a program to find the sum of N elements of an Array.

    12: Write a program to find the element from an Array and print 1 if element is found else print 0.

    13. Write a Program that will accept the amount and find how many minimum
    no of notes you required for that.
    (Using the rupee notes of 1, 2, 5, 10, 20, 50, 100, 200, 500, 2000)
    Input: 5748
    Output:
    Notes of Rs.2000 = 2 Notes of Rs.500 = 3 Notes of Rs.200 = 1
    Notes of Rs.20 = 2 Notes of Rs.10 = 0 Notes of Rs.5 = 1
    Notes of Rs.2 = 1 Notes of Rs.1 = 1

    14. Write a Program to find the eligibility of admission for a  professional course
    based on the following criteria:
    Marks in Maths >=65
    Marks in Phy >=55
    Marks in Chem>=50 and
    Total in all three subject >=180 or
    Total in Math and Physics >=140
    INPUT:
    Input the marks obtained in Maths :72
    Input the marks obtained in Physics :65
    Input the marks obtained in Chemistry :51
    OUTPUT:
    The candidate is eligible for admission.

    15.Write a Program which accepts name from the user and prints the same

    INPUT : R K University
    OUTPUT: R K University

     

     

    0
    Additional Comments:
    Rating max score to > pts

    Rubric

     
     
     
     
     
         
    Can't change a rubric once you've started using it.  
    Find a Rubric
    Find Rubric
    Title
    You've already rated students with this rubric. Any major changes could affect their assessment results.
    Title
    Criteria Ratings Pts
    Edit criterion description Delete criterion row
    This criterion is linked to a Learning Outcome Description of criterion
    view longer description
    threshold: 5 pts
    Edit rating Delete rating
    5 to >0 pts
    Full Marks
    blank
    Edit rating Delete rating
    0 to >0 pts
    No Marks
    blank_2
    This area will be used by the assessor to leave comments related to this criterion.
    pts
      / 5 pts
    --
    Additional Comments
    Total Points: 5 out of 5
    In order to create video or audio recordings your computer needs to be webcam-enabled. If you don't have a webcam on your computer, you can still record audio-only messages by first installing the Google Video Chat plugin.
    Install the Video Plugin
    Don't have a webcam?