Saturday, 24 October 2015

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();
   }
}

No comments:

Post a Comment