Anda di halaman 1dari 6

Universidad Nacional San Luis Gonzaga

de Ica
Facultad Ingeniera de Sistemas
I Prctica Calificada Lenguaje

1.- You are developing a class named ExtensionMethods. You need to ensure that the
ExtensionMethods class implements the IsEmail() method on string objects.
How should you complete the relevant code? (To answer, drag the appropriate code segments to
the correct locations in the answer area. Each code segment may be used once, more than once,
or not at all.)

2.- An application includes a class named Person. The Person class includes a
method named GetData. You need to ensure that the GetData() method can
beused only by the Person class or a class derived from Person class.
Which access modifier should you use for the GetData() method?
Rpta.- Protected The type or member can be accessed only by code in the same class or
structure, or in a
class that is derived from that class.
Universidad Nacional San Luis Gonzaga
de Ica
Facultad Ingeniera de Sistemas
I Prctica Calificada Lenguaje

3.- You are developing an application by using C#. The application includes the following code
segment. (Line numbers are included for reference only.)

The DoWork() method must not throw any exceptions when converting the obj object to the
IDataContainer interface or when accessing the Data property. You need to meet the
requirements. Which code segment should you insert at line 07?

Rpta.- var dataContainer = obj as IDataContainer as return null if can not cast

4.- You are developing an application. The application includes classes named Employee and
Person and an interface named IPerson.
The Employee class must meet the following requirements:
-It must either inherit from the Person class or implement the IPerson interface.
-It must be inheritable by other classes in the application.
You need to ensure that the Employee class meets the requirements.
Which two code segments can you use to achieve thisgoal? (Each correct answer presents a
complete solution. Choose two.)

ByD
Universidad Nacional San Luis Gonzaga
de Ica
Facultad Ingeniera de Sistemas
I Prctica Calificada Lenguaje

5.- You are creating a class named Employee. The class exposes a string property named
EmployeeType.
The following code segment defines the Employee class. (Line numbers are included for
reference only.)

The EmployeeType property value must be accessed only by code within the Employee classor
within a class
derived from the Employee class.
The EmployeeType property value must be modified only by code within the Employee classor
You need to ensure that the implementation of the EmployeeType property meets the
requirements.
Which two actions should you perform?

Replace line 06 with the following code segment: private set;

Replace line 03 with the following code segment: protected string EmployeeType

protected string EmployeeType { get; private set; }


Universidad Nacional San Luis Gonzaga
de Ica
Facultad Ingeniera de Sistemas
I Prctica Calificada Lenguaje

6.- Dada dos cadenas de caracteres de mismo tamao, calcular la distancia de Hamming entre
ellos (caracteres que son diferentes en misma posicin)

Ejemplo:
Para string1 = "abab" y string2 = "cbad", el resultado debera ser
hammingDistance(string1, string2) = 2.
Only the first and the last characters are different.
Slo el primero y el ltimo carcter son diferentes.
Input/Output
[input] string string1
La primera cadena de caracteres.
Restriccin:
3 string1.length 10.
[input] string string2
La segunda cadena de caracteres.
Restriccin:
3 string2.length 10.
[output] integer
Distancia Hamming entre string1 y string2.

class Program
{
public void Leer()
{
string string1, string2;
do {
Console.WriteLine("Ingrese cadena 1:");
string1 = Console.ReadLine();
} while (string1.Length <= 3 || string1.Length >= 10);

do {
Console.WriteLine("Ingrese cadena 2:");
string2 = Console.ReadLine();
} while (string2.Length != string1.Length);

hammingDistance(string1, string2);
}

public void hammingDistance(string string1, string string2)


{
int distancia = 0;
for (int i = 0; i < string1.Length; i++)
{
if (string1[i] != string2[i])
{
distancia++;
}
}

Console.WriteLine("La distancia de hamming es " +distancia);


Console.ReadKey();
}

static void Main(string[] args)


{
Universidad Nacional San Luis Gonzaga
de Ica
Facultad Ingeniera de Sistemas
I Prctica Calificada Lenguaje

Program obj = new Program();


obj.Leer();
}
}
}

7.- Se tiene la siguiente interfaz:

public interface IAnimal


{
int Num_mamas { get; set; }
void HacerSonidos();
void Dormir();
void Ascender();
void Amamantar();
void Comer();
void PonerHuevos();
void Respirar();
void Nadar();
void Volar();
void Nacer();
void Bucear();
void Descender();
void Envenenar();
void Parir();
void ProducirVeneno();
}

Segregar de manera que las clases: PezGlobo, Ornitorrinco y Paloma implementen


solo los mtodos que les correspondan.

Tip 1: Segregar es separar o apartar algo o a alguien de otra u otras cosas

Tip 2: Una de las tantas caractersticas fabulosas que tienen los ornitorrincos son los
espolones en los tobillos los cuales liberan veneno.

public interface IAnimal


{
void HacerSonidos();
void Dormir();
void Comer();
void Respirar();
}
public interface IMamifero : IAnimal
Universidad Nacional San Luis Gonzaga
de Ica
Facultad Ingeniera de Sistemas
I Prctica Calificada Lenguaje

{
int Num_mamas { get; set; }
void Amamantar();
}
public interface IAnimalVolador : IAnimal
{
void Ascender();
void Volar();
void Descender();
}
public interface IAnimalAcuatico : IAnimal
{
void Nadar();
void Bucear();
}
public interface IAnimalVenenoso
{
void Envenenar();
void ProducirVeneno();
}

Quedando las clases:

public class claseOrnitorrinco : IMamifero, IAnimalVenenoso


{
//metodos
}
public class clasePaloma : IAnimalVolador
{
//metodos
}

public class PezGlobo : IAnimalAcuatico, IAnimalVenenoso


{
//mtodos
}

*** El pez globo tambien es venenoso, aunque puede que no lo sepan.

Anda mungkin juga menyukai