0% found this document useful (0 votes)
13 views4 pages

C# Questions1

Uploaded by

Vikash Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

C# Questions1

Uploaded by

Vikash Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

using System;

public class Person


{
public string Name ;
public int Age;
// Parameterized constructor
public Person(string name, int age)
{
Name = name;
Age = age;
}

// Copy constructor
public Person(Person otherPerson)
{
// Copy the values from the otherPerson instance
Name = otherPerson.Name;
Age = otherPerson.Age;
}

public void DisplayInfo()


{
Console.WriteLine($"Name: {Name}, Age: {Age}");
}
}

class Program
{
static void Main()
{

Person person1 = new Person("Alice", 25);

// Use the copy constructor to create a copy of person1


Person person2 = new Person(person1);

// Modify the original person


person1.Name = "Bob";

// Display the information for both persons


Console.WriteLine("Original Person:");
person1.DisplayInfo();
Console.WriteLine("\nCopied Person:");
person2.DisplayInfo();
}
}

2.Create an class Sim should have the following properties:

Instance Variables:

SimNumber:long
SimType:string

Implement two constructors for the Sim class:

1.A parameterized constructor that allows you to set the SimNumber and SimType
2.A Copy constructor copy the data to copy constructor

Methods:
Name:DisplayInfo
ReturnType:string
AccessModifier:public
return the data of the Sim

If you change the sim type for example before simtype is airtel and changed to jio
update the simtype

MethodName:UpdateSimtype
Prameters:NewSimType (string)
Returntype:void
AccessModifier:public
update the simtype.

Create another class SimDetails

create object for Sim class pass the values by using constructor and also call the
UpdateSimtype method.
Display the siminformation using copy constructor and also display details after
update
copy constructor details don't has to change it should be having old details
User has to enter the values.

sample output:
------------------
Enter Sim Number:
123456789
Enter Sim Type:
Airtel

Sim Information (Original):


Sim Number: 123456789
Sim Type: Airtel

Enter New Sim Type:


Jio

Sim Information (Copy):


Sim Number: 123456789
Sim Type: Airtel

Sim Information (Original After Update):


Sim Number: 123456789
Sim Type: Jio

3.Create an class Chess should have the following properties:(longest chess game
ever played)

Instance Variables:

GameName:string
no_of_moves:int
year_of_played:int
player1name:string
player2name:string

Implement constructor for the Employee class:


A parameterized constructor that allows you to set the
GameName,no_of_moves,year_of_played,player1name and player2name

Methods:
Name:DisplayInfo
ReturnType:string
AccessModifier:public
return GameName,no_of_moves,year_of_played,player1name and player2name

Create ChessGame class pass the values by using constructor and also call the
DisplayInfo method.

Note: The longest chess game ever played took place in 1989 between Ivan Nikolic
and Goran Arsovic and lasted for a total of 269 moves over the course of four days.

You might also like