0% found this document useful (0 votes)
8 views1 page

Lab 04

The document outlines a lab activity for programming technologies focusing on creating a generic class Pair<T> with specific functionalities, including constructors, comparison methods, and string representation. It also instructs on implementing sorting and maximum value methods for arrays of Pair objects, as well as generating a sequence of prime numbers in a new console application. Students are required to upload their completed work before the next lab session.

Uploaded by

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

Lab 04

The document outlines a lab activity for programming technologies focusing on creating a generic class Pair<T> with specific functionalities, including constructors, comparison methods, and string representation. It also instructs on implementing sorting and maximum value methods for arrays of Pair objects, as well as generating a sequence of prime numbers in a new console application. Students are required to upload their completed work before the next lab session.

Uploaded by

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

Programming Technologies and Paradigms.

Lab 4 presential
activity. Groups 1 and 4.

1. Define the generic class Pair<T>, with two T IComparable attributes:

-Default constructor, assigns default T value to both attributes.


-Constructor from two T.
-Implement CompareTo as a lexicographic comparison (an example of a
lexicographic comparison is the alphabetic order of words or car plates date
ordering):
-If the first attribute of the first object precedes the first attribute of the second
object the first object precedes the second.
-If the first attribute of the first object follows the first attribute of the second
object the first object follows the second.
-If the first attributes of both objects occur in the same position , the
comparison is done using the second attributes of both objects.
Examples with char: ['a','x'] precedes ['b','c'] but follows ['a','d']
-Implement ToString.
-Add a console application project to your solution and add Algorithms.cs to the
current project. Try to make your solution self contained, it is easy if the mentioned
source code is inside your solution folder. A quick and dirty trick is copy paste the
file in that folder using windows file browser and then “add existing item” using the
Visual Studio solution browser. If you drag and drop it using the solution explorer
then it is automatically added to the project.
Check if Sort method in your Algorithms.cs copy can be called with a Pair
array. Use an array of randomly generated Pair, using the next method of a
Random type object. If you want to increase the odds of value repetition, reduce the
range of the generated numbers. If you want to test the generic class with capital
letters, generate integers in [65, 90] interval and cast them to char.
-Implement Show, a void generic method that simply outputs an IEnumerable<T>
array to the console using foreach. Additionally, the method takes two optional
char parameters sep and endl with ‘ ‘ and ‘\n’ default parameters.
-Similarly to Sort, Implement Max method (add it to your Algorithms.cs
copy), takes a T array as parameter (or an IEnumerable<T>) and returns the
biggest element in the array (the one that follows all the other values). Do not use
Sort, use CompareTo only. Test it with a int array and with a Pair array.

2. Add a new console application project to your solution. Make this new project the
starting project. Take as starting point the Fibonacci example in the project
enumerables, solution generics. C&p into your new project that project .cs
files. Modify it to generate the sequence of n first prime numbers. A private method
IsPrime taking an int as parameter and returning a bool encoding wether or not
the parameter is prime will be handy. Show the sequence using foreach and using
the suitable iterator, as it is done in the console application: the already
implemented methods should work fine. Test your implementation: if the sequence
length is 5, The list is [2, 3, 5, 7, 11]. Rename the identifiers with F2.

Upload the mandatory activity before the next Lab.

You might also like