C# LAB@HOME

ankitwaretechstudies.blogspot.com

sonugiri.blogspot.com

C# Lab@home 1



Predict the output of the following code snippet:


using System;
class Myclass
{
static void Main()
{
string Answer="Y";
string Response_Code="66";
int Counter=60;
Console.writeLine(Answer);
Console.WriteLine("Response Code");
Console.WriteLine(Cunter);
Console.ReadLine();
 }
}




2. Jim is developing software for automating the slot booking process for a video game parlor. Customers fill the Booking Request form with the details of the game, such as the name, number of players, and complexity level. They hand over the form to the booking officer at the parlor. Depending on the availability, the booking officer reserves the time slots and the play station for customers.




using system ;
public class gamedetials
{

      string fname ;
      string lname ;
      int noofplayer ;
      int level ;

      public static void getGameDetail ()
{
      console.writeline (" enter your first name" );
      fname= console.readline();
      console. writeline ( " enter your last name" );
      Lname-console.readline();
      console.writeline( "enter no of players");
      nooFplayer=convert ToInt32(console. readline() )
      console. writeline(" entercomplexity level number:");
      level= convert ToInt32(console.readline());
          Console.ReadLine();
}





public static void showGameDetails()
{
   {
 console. writeline("the details enter are as follows:");
  console. write("first name:");
 console.writeline(fname);
 console.write("last name:");
 console.writeline(lname);
 console.write("no of players:");
 console.writeline(noofplayers);
 console.write("level:");
 console.writeline(level);
  
public static void Main(string []args)
{
 GameDetails gd=new GameDetails();
 gd.getGameDetials();
 gd.showGameDetails();

}

}








C# Lab@home 2






1.As a part of the team that is developing software for a library, you have been assigned the task of writing a program. The program should accept the following book details: 1. Book Number as int 2. Book Category (Fiction or Nonfiction) as string 3. Author Name as string 4. Number of copies available as int Write a C# program to accept and display the preceding book details.

using System;
class Book
{
     string BookCat;
     string FirstName;
     string LastName;
     int IsbnNo;
     int NoOfCopies;

   public void display()
{
      Console.WriteLine("\nThe following are the details of the Book:");
      Consile.writeLine("Category of the Book:");
      Console.write("Name of the Author:");
      Console.Write(FiretName);
      Console.writeLine("{0}",LastName);
      Console.Write("ISBN Number:");
      Console.WriteLine(IsbnNo);
      Console.Write("Number of Copies");
      Console.WriteLine(NoOfCopies);
}
  public void Get()
{
  Console.WriteLine("Please enter the details of the Book");
  Console.WriteLine("Enter the Category of the Book(Fiction/Nonfiction):");
  BookCat=Console.ReadLine();
  Console.WriteLine("First Name of the Author:");
  FirstName=console.ReadLine();
  Console.WriteLine("Last Name of the Author:");
  LastName=console.ReadLine();
  Console.WriteLine("ISBN Number:");
  IsbnNo= Convert.toInt32(Console.ReadLine());
  Console.WriteLine("Number of Copies:");
  NoOfCopies=Convert.TOInt32(Console.ReadLine());
 }
}
    class MyClass
 {
     static void Main(string[] args)
{
     Book My_Fav = new Book();
     Console.readLine();
    }
  }




2. An automobile company has developed an application for maintaining the number of wheels in a vehicle. Predict the output of the following code of the application: using System; class Vehicle { public int Number_of_tyres; } class MyVehicle { static void Main(string[] args) { Vehicle Motorcycle = new Vehicle(); Vehicle Car = new Vehicle(); Console.WriteLine("Enter the number of wheels in a car:"); Car.Number_of_tyres = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the number of wheels in a Motorcycle:"); Motorcycle.Number_of_tyres = Convert.ToInt32 (Console.ReadLine()); Console.WriteLine("\n"); Console.Write (Car.Number_of_tyres); Console.WriteLine(" :is the number of wheels in a Car \n"); Console.Write (Motorcycle.Number_of_tyres); Console.WriteLine(" :is the number of wheels in a Motorcycle \n"); Console.ReadLine(); } }



using System;
class Vehicle
{
      public int Number_of_tyres;
}
     class MyVehicle
{
    static void Main (string[] args)
 {

        Vehicle Motorcycle= new Vehicle();

        Vehicle Car = new Vehicle();

        Console.WriteLine("Enter the number of wheels in a car:");

        Car.Number_of_tyres=Covert.ToInt32(Console.ReadLine());

        Console.WriteLine("Enter the number of wheels in a Motorcycle:");

        Motorcycle.Number_of_tyres=Convert.ToInt32(Console.ReadLine());

        Console.WriteLine("\n");

        Console.Write(Car.Number_of_tyres);

 Console.WriteLine(" :is the number of wheels in a Car\n");

 Console.Write(Motorcycle.Number_of_tyres);

 Console.WriteLine(" :is the number of wheels in a Motorcycle \n");
  }
}





3. TechnoSoft, a leading software company, has developed an application for maintaining the scores of games in a video game parlor. If the new score is greater than the stored top score, the following program should interchange the values of the variables Top_score and New_score. However, the program does not generate the desired output. Identify the error in the following program and write the correct code: using System; class Interchange { int Top_score; int New_score; int Temp; void Swap() { Top_score=5; New_score=10; Temp=top_score; New_score=Top_score; Top_score=New_score; } void Display() { Console.WriteLine("The new value of top score is:"); Console.WriteLine(Top_score); Console.WriteLine("The old value of top score was:"); Console.WriteLine(New_score); } static void Main() { Interchange I1; I1.Swap(); I1.Display(); Console.ReadLine(); } } (Duration: 25 min
 using System;
   class Interchange
 {
 
      int Top_score;
      int New_score;
      int Temp;
      void swap()
 {
     
        Top_score=5;
        New_score=10;
        Temp=Top_score;
        Top_score=New_score;
        New_score=Temp;
 }
   void Display()
 {
 
     Console.WriteLine("The new value of top score is:");
     Console.WriteLine(Top_score);

     Console.WriteLine("The old value of top score was:");
     Console.WriteLine(New_score);
 }
     static void main()
{

     Interchange I1=new Interchange();
     I1.Swap();
     I1.Display();
     Console.ReadLine();
   }
}







C# Lab@home 3





Write a C# program that accepts distance in kilometers, converts it into meters, and then displays the result. (Duration: 45 min)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Quotient
{
    class Meter_Kilometer
    {
        static void Main(string[] args)
        {
            int nDistance, nResult;
            Console.WriteLine("Enter the distance in kilometers");
            nDistance = Convert.ToInt32(Console.ReadLine());
            nResult = nDistance * 1000;
            Console.WriteLine("Distance in meters:" + nResult);
            Console.ReadLine();
        }
    }
}






Write a program to identify whether a character entered by a user is a vowel or a consonant. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace character
{
    class VowelConsotant
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the Alphabet");
            Alphabet = Convert.ToChar(Console.ReadLine());
                       switch (Alphabet)
            {
                case 'a':
                case 'e':
                case 'i':
                case 'o':
                case 'u':
            }
        }
    }
}







Write a program that displays "Congratulations! You have cleared this Level. Entering Level 2..." in red color. The output of this program is shown in the following figure.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Congratulations
{
    class Game
    {
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("\n\n\n\n\n\n");
            Console.WriteLine("\t\tCongratulations");
            Console.WriteLine("\n\n");
            Console.WriteLine("\t\t\t\tEntering! You have cleared this Level");
            Console.ReadLine();
        }
    }
}










C# Lab@home 4





Write a program to identify whether the number entered by a user is even or odd. 

using System;
class EvenOddNumber
{
static void Main (string [] args)
{
int Number;
Console.WriteLine("Enter the number to be checked as Even or Odd");
Number = Convert.ToInt32(Console.ReadLine());
if (Number % 2 == 0)
{
Console.WriteLine(" The number you have entered is an Even number");
}
else
{
Console.WriteLine("The number you need entered is an Odd number");
}
Console.ReadLine();
}
}











David is a cricket coach of a local team. He is analyzing the performance of one of his batsman. For this, he wants a program that should accept the number of recent matches for which the scores of the batsman need to be analyzed. After this, the program should accept the scores of the batsman for these matches, and then display the scores in ascending order. Help David create the program. Hint: Declare an integer array with a maximum capacity of 100 elements. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Sorting of a Number
namespace chapter4
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[100];
            Console.Write("Enter the number of recent matches for which the scores of the batsman need to be analyzed:");
            string s = Console.ReadLine();
            int x = Int32.Parse(s);

            Console.WriteLine("======================");
            Console.WriteLine("Enter the scores:");
            Console.WriteLine("======================");
            for (int j = 0; j < x; j++)
            {
                string s1 = Console.ReadLine();
                a[j] = Int32.Parse(s1);
            }
            int limit = x - 1;
            for (int pass = 0; pass < x - 1; pass++)
            {
                for (int j = 0; j < limit -pass; j++)
                {
                    if (a[j] > a[j + 1])
                    {
                        int k = a[j];
                        a[j] = a[j + 1];
                        a[j + 1] = k;

                    }
                }
            }
            Console.WriteLine("========================================================");
            Console.WriteLine("Scorted scores of the batsman are:");
            for (int j = 0; j < x; j++)
                Console.WriteLine(a[j]);
            Console.ReadLine();
        }
    }
}













C# Lab@home 5







Write a program to accept two numbers and display the quotient as a result. In addition, an error message should be displayed if the second number is zero or greater than the first number.  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace two_number_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int num1, num2, result;
            Console.WriteLine("Enter two numbers");
            num1 = Convert.ToInt32(Console.ReadLine());
            num2 = Convert.ToInt32(Console.ReadLine());
            if (num2 != 0)
            {
                if (num2 < num1)
                {
                    result = num2 / num2;
                    Console.WriteLine("result");
                }
                else
                {
                    Console.WriteLine("A number cannot be divided by a number greater than itself");
                }
            }
            else
            {
                Console.WriteLine("A number cannot be divided by zero");
            }
        }

    }
}









Write a program to accept two numbers and check if the first is divisible by the second. In addition, an error message should be displayed if the second number is zero. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int num1, num2, result;
            Console.WriteLine("Enter First Number");
            num1 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter socond Number");
            num2 = Convert.ToInt32(Console.ReadLine());
            if (num2 == 0)
            {
                Console.WriteLine("You cannot divide by 0");
            }
            else
            {
                result = num1 % num2;
                if (result ==0)
                    Console.WriteLine("Divisidle");
                else

                Console.WriteLine("Not DIvisible");
            }

        }
    }

}







Write a program to accept a number from the user and display all the prime numbers from one up to the number entered by user. 

using System;
class primeNumber
{
public void PrimeNum(int Num)
{
Boolean isPrime=true;
Console.WriteLine("\nThe prime numbers between 1-{0} is:",Num);
for (int i = 0; i <=Num; i++)
{
for (int j = 2; j<=Num; j++)
{
if (i !=j && i == 0)
{
isPrime = false;
break;
}
}
if (isPrime == true)
{Console.WriteLine("{0}",i);}
isPrime = true;
}
}
}
class EntryPoint
{
static void Main (string[]args)
{
int Num;
PrimeNumber FindPrimeNo = new PrimeNumber();
string str;
Console.WriteLine("Enter the number till which you want to show the prime Numbers");
str = Convert.ReadLint();
Num = Convert.PrimeNum(Num);
Console.ReadLint();
}
}









C# lab at home 6







C# lab at home 7 

CLICK HERE






C# lab at home 8






C# lab at home 9







C# lab at home 10







C# lab at home 11

1 comment: