SlideShare a Scribd company logo
1 of 6
Download to read offline
Number 1 I have completed and number 6 is just uploading. I just need some help with the 2,3,4
and 5.
This is my code from Vector.cs:
using System;
using System.Collections.Generic;
using System.Text;
namespace Vector
{
public class Vector<T>
{
// This constant determines the default number of elements in a newly created vector.
// It is also used to extended the capacity of the existing vector
private const int DEFAULT_CAPACITY = 10;
// This array represents the internal data structure wrapped by the vector class.
// In fact, all the elements are to be stored in this private array.
// You will just write extra functionality (methods) to make the work with the array more convenient
for the user.
private T[] data;
// This property represents the number of elements in the vector
public int Count { get; private set; } = 0;
// This property represents the maximum number of elements (capacity) in the vector
public int Capacity
{
get { return data.Length; }
}
// This is an overloaded constructor
public Vector(int capacity)
{
data = new T[capacity];
}
// This is the implementation of the default constructor
public Vector() : this(DEFAULT_CAPACITY) { }
// An Indexer is a special type of property that allows a class or structure to be accessed the same
way as array for its internal collection.
// For example, introducing the following indexer you may address an element of the vector as
vector[i] or vector[0] or ...
public T this[int index]
{
get
{
if (index >= Count || index < 0) throw new IndexOutOfRangeException();
return data[index];
}
set
{
if (index >= Count || index < 0) throw new IndexOutOfRangeException();
data[index] = value;
}
}
// This private method allows extension of the existing capacity of the vector by another
'extraCapacity' elements.
// The new capacity is equal to the existing one plus 'extraCapacity'.
// It copies the elements of 'data' (the existing array) to 'newData' (the new array), and then makes
data pointing to 'newData'.
private void ExtendData(int extraCapacity)
{
T[] newData = new T[Capacity + extraCapacity];
for (int i = 0; i < Count; i++) newData[i] = data[i];
data = newData;
}
// This method adds a new element to the existing array.
// If the internal array is out of capacity, its capacity is first extended to fit the new element.
public void Add(T element)
{
if (Count == Capacity) ExtendData(DEFAULT_CAPACITY);
data[Count] = element;
Count++;
}
// This method searches for the specified object and returns the zerobased index of the first
occurrence within the entire data structure.
// This method performs a linear search; therefore, this method is an O(n) runtime complexity
operation.
// If occurrence is not found, then the method returns 1.
// Note that Equals is the proper method to compare two objects for equality, you must not use
operator '=' for this purpose.
public int IndexOf(T element)
{
for (var i = 0; i < Count; i++)
{
if (data[i].Equals(element)) return i;
}
return -1;
}
// TODO: Your task is to implement all the remaining methods.
// Read the instruction carefully, study the code examples from above as they should help you to
write the rest of the code.
public void Insert(int index, T element)
{
if (Count == Capacity)
{
ExtendData(DEFAULT_CAPACITY);//Used to increase capacity of vector and copy old elements
into new
}
//If index is equal to count, add an element to the end
if (index == Count)
{
Add(element);
return;
}
//Check if a element is being insterted outside of the vector. If it is, throws an exception
if (index > Count || index < 0)
{
throw new IndexOutOfRangeException("Index is out of range: " +
index);
}
int count = Count;
while (count != index)//While loop to shuffle elements to the end of vector
{
data[count] = data[count - 1];//Shuffle
count--;//Goes Back
}
data[count] = element;//Add element
Count++;//Increase vector size for new element
}
public void Clear()
{
Array.Clear(data, 0, Count); //Clear all elements from the array.
Count = 0; //Sets Count to 0
}
public bool Contains(T element)
{
//Check if element is in vector
return IndexOf(element) != -1;
}
public bool Remove(T element)
{
int index = IndexOf(element);//Variable to find index of a particular element
if (index > -1) //Check if its valid
{
RemoveAt(index);//Removes a particular element at index
return true;
}
return false;//method needs return type
}
public void RemoveAt(int index)
{
//Check if the index is within the range of the array.
if (index < 0 || index >= Count)
{
throw new IndexOutOfRangeException("Index is out of range: " +
index);
}
//Removes the element of an index from the vector
for (int i = index; i < Count - 1; i++)
{
data[i] = data[i + 1];
}
Count--;//Decrease Count due to remove of element
}
public override string ToString()
{
StringBuilder stringBuild = new StringBuilder("[", 50);// Stringbuilder Instance
for (var i = 0; i < Count; i++) //for loop to add , to each element
{
stringBuild.Append(data[i]);//Calls append to string
if (i != Count - 1) stringBuild.Append(',');//Check if Count is last elemnt and adjusts if not
}
stringBuild.Append(']');
return stringBuild.ToString();//has to return has method has return type
}
}
}
Here is ss of the tester.cs:
Please comment the new code as well so I can learn it for next task. Thank you.
1. Create a copy of your solution for Task 1.1 and replace the Tester.cs file by that attached to this
task. The Main method of the new Tester class is to be compatible with the Vector T>. Again, it
contains a series of tests that will verify if the functionality that you need to develop in this task
works correctly. See Appendix A for an example of what the program will output when working
correctly. 2. Extend your Vector <T> class by adding the following two overloaded methods: - void
Sort() Sorts the elements in the entire Vector >> collection. The order of elements is determined
by the default comparer for type T, which is comparer <T, Default. - void Sort( IComparer
comparer ) Sorts the elements in the entire Vector <T> collection using the specified comparer. If
the comparer is null, the order of elements is determined by the default comparer for type T, which
is In this task, the implementation of both methods does not require you to implement any sorting
algorithm. Instead, you should delegate sorting of data elements to Array.Sort, which implements
the Introspective sorting algorithm as the sorting method for the Array class. Similar to the two
methods above, Array.Sort is overloaded and has two versions: One that accepts an array along
with the starting index and the number of elements to define the range for sorting, and the other,
which additionally accepts a comparer object for the purpose of determining the order of elements.
Read about these two methods at https://learn.microsoft.com/en-
us/dotnet/api/system.array?redirectedfrom=MSDN&view=net-7.0#methods Once you have your
both Sort methods set up, you should be able to sort integers and succeed with tests A, B, C, and
D in the attached Tester class. To enable these tests, uncomment the respective code lines in
Tester.cs file.| 3. Explore the Student class provided in Tester.cs file. To make two students
comparable (and thus sorted in the Vector <T> collection like in the List<T> ), you must enable a
mechanism that automatically compares two elements of type Student. Keep in mind that in this
case T is a blueprint type, which during the runtime will be replaced by the Student class. 4. One
way to make two elements comparable in the .NET Framework is to introduce a comparison
method right in the type, for example, in the Student class. This is how we can 'teach' the type to
compare one element (referred to as this) with the other element (referred to as another) of the
same type. In the code, this should be done by implementing the special interface in the class,
which in its turn requires implementation of the CompareTo(T another) method that compares this
(current) element with another element and returns an integer value. The integer values is - less
than zero, when this (current) element must precede another element specified as the argument,-
zero, when this (current) element is seen as equal to another element, - greater Ghan zero, when
this (current) element must succeed another element. Your task now is to modify the Student class
and implement the IComparable > interface along with its underlying CompareTo(Student another)
method so that it can sequence students in the ascending order of the ID attribute. When this is
done, you should be able to sort objects of Student class via the Sort( ) method of the Vector <T>
class. Complete this part to pass Test E by activating its respective code lines in the program
code. 5. The other way to make two elements comparable is to develop a so-called comparator
class, whose purpose is to compare a pair of elements of specific type. Such comparator class
must implement the IComparer T> interface. The IComparable T is similar to the IComparer T>,
except that the CompareTo(T another) method belongs to the type, while Compare (Ta,T b) is part
of an independent class implementing the IComparer T>. The Compare(T a, T b) method implied
by the Comparer T> returns an integer value indicating whether argument a is less than, equal to,
or greater than argument b, exactly as the CompareTo method does. There are a few examples of
classes implementing the IComparer > interface in Tester.cs file that sort integers in ascending,
descending, or in the order that places even integers prior to odd integers. You should learn from
these examples to develop your own comparator for the Student class. Specifically, your task is to
provide two comparators for the Student class: - AscendinglDComparer to sort a sequence of
students stored in an instance of the Vector SStudent> class in the ascending order of IDs; -
DescendingNameDescendingldComparer to sort a sequence of students stored in an instance of
the Vector Student> class in the descending order of names, breaking ties by the descending
order of IDs. Once this is done, you should be able to pass tests F and G. Make sure that students
appear in the desired order. Keep in mind that any of these comparators can be the argument of
the Sort(IComparer T> comparer) method of the Vector <T> class; so, test how they work with
your Vector < Student > class. 6. Submit the new version of the Vector <T> class and the updated
Tester.cs file that now constains the extended Student class and both AscendinglDComparer and
DescendingNameDescendingldComparer classes.AStudent student = new Student() { Name =
names [ random. Next (, names. Length )], Id =i}; Console.Writeline("Add student with record: " +
student. ToString()); students. Add(student); Console.Writeline("Sort the students in the order
defined by the DescendingNameDescendingIdComparer class"); // uncomment the line to activate
the test //students. Sort(new DescendingNameDescendingIdComparer ()); Console.
Writeline("Print the vector of students via students. ToString(); "); Console. Writeline(students.
ToString()); Console. Writeline(" : SUCCESS"); result = result +mG; catch (Exception exception)
Console.Writeline(" : FAIL"); Console . Writeline(exception. ToString()); result = result +n";
Console. Writeline(" n Console. Writeline("Tests passed: "+ result); Console.ReadKey();

More Related Content

Similar to Number 1 I have completed and number 6 is just uploading I .pdf

LJ_JAVA_FS_Collection.pptx
LJ_JAVA_FS_Collection.pptxLJ_JAVA_FS_Collection.pptx
LJ_JAVA_FS_Collection.pptxRaneez2
 
01-intro_stacks.ppt
01-intro_stacks.ppt01-intro_stacks.ppt
01-intro_stacks.pptsoniya555961
 
Generics Collections
Generics CollectionsGenerics Collections
Generics Collectionsphanleson
 
21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptxreddy19841
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersANUSUYA S
 
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdfStep 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdfaloeplusint
 
The second programming assignment (HW4) is designed to help you ga.docx
The second programming assignment (HW4) is designed to help you ga.docxThe second programming assignment (HW4) is designed to help you ga.docx
The second programming assignment (HW4) is designed to help you ga.docxoreo10
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfaamousnowov
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfinfo114
 
Use the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docxUse the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docxdickonsondorris
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#Shahzad
 
Ecet 370 Education Organization -- snaptutorial.com
Ecet 370   Education Organization -- snaptutorial.comEcet 370   Education Organization -- snaptutorial.com
Ecet 370 Education Organization -- snaptutorial.comDavisMurphyB81
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxmaxinesmith73660
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfkarymadelaneyrenne19
 
ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com donaldzs157
 
Objective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdfObjective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdfaliracreations
 
Please and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfPlease and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfalicesilverblr
 
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptxvectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptxVivekSharma34623
 

Similar to Number 1 I have completed and number 6 is just uploading I .pdf (20)

LJ_JAVA_FS_Collection.pptx
LJ_JAVA_FS_Collection.pptxLJ_JAVA_FS_Collection.pptx
LJ_JAVA_FS_Collection.pptx
 
Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
 
01-intro_stacks.ppt
01-intro_stacks.ppt01-intro_stacks.ppt
01-intro_stacks.ppt
 
Generics Collections
Generics CollectionsGenerics Collections
Generics Collections
 
21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about Pointers
 
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdfStep 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
 
The second programming assignment (HW4) is designed to help you ga.docx
The second programming assignment (HW4) is designed to help you ga.docxThe second programming assignment (HW4) is designed to help you ga.docx
The second programming assignment (HW4) is designed to help you ga.docx
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdf
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
 
Use the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docxUse the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docx
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#
 
Ecet 370 Education Organization -- snaptutorial.com
Ecet 370   Education Organization -- snaptutorial.comEcet 370   Education Organization -- snaptutorial.com
Ecet 370 Education Organization -- snaptutorial.com
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
 
ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com
 
Objective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdfObjective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdf
 
Data structures
Data structuresData structures
Data structures
 
Please and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfPlease and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdf
 
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptxvectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
 

More from advancethchnologies

On day 1 of the menstrual cycle FSH levels will be 25 pts .pdf
On day 1 of the menstrual cycle FSH levels will be 25 pts .pdfOn day 1 of the menstrual cycle FSH levels will be 25 pts .pdf
On day 1 of the menstrual cycle FSH levels will be 25 pts .pdfadvancethchnologies
 
On August 2 1971 Commander Scott of Apollo 15 confirmed Ga.pdf
On August 2 1971 Commander Scott of Apollo 15 confirmed Ga.pdfOn August 2 1971 Commander Scott of Apollo 15 confirmed Ga.pdf
On August 2 1971 Commander Scott of Apollo 15 confirmed Ga.pdfadvancethchnologies
 
On April 1 2024 Ivanhoe Company purchased 41600 common sh.pdf
On April 1 2024 Ivanhoe Company purchased 41600 common sh.pdfOn April 1 2024 Ivanhoe Company purchased 41600 common sh.pdf
On April 1 2024 Ivanhoe Company purchased 41600 common sh.pdfadvancethchnologies
 
On any given day the probability that Marco eats sushi for .pdf
On any given day the probability that Marco eats sushi for .pdfOn any given day the probability that Marco eats sushi for .pdf
On any given day the probability that Marco eats sushi for .pdfadvancethchnologies
 
Objective Draw the data path and interface with the control.pdf
Objective Draw the data path and interface with the control.pdfObjective Draw the data path and interface with the control.pdf
Objective Draw the data path and interface with the control.pdfadvancethchnologies
 
On a certain island there is a population of snakes foxes.pdf
On a certain island there is a population of snakes foxes.pdfOn a certain island there is a population of snakes foxes.pdf
On a certain island there is a population of snakes foxes.pdfadvancethchnologies
 
Omnichannel retailing is A when a retailer either closes .pdf
Omnichannel retailing is A when a retailer either closes .pdfOmnichannel retailing is A when a retailer either closes .pdf
Omnichannel retailing is A when a retailer either closes .pdfadvancethchnologies
 
Omigo On a Mission to Create a Bidet Culture in the United .pdf
Omigo On a Mission to Create a Bidet Culture in the United .pdfOmigo On a Mission to Create a Bidet Culture in the United .pdf
Omigo On a Mission to Create a Bidet Culture in the United .pdfadvancethchnologies
 
Olfactory receptor cells and auditory receptors share the fo.pdf
Olfactory receptor cells and auditory receptors share the fo.pdfOlfactory receptor cells and auditory receptors share the fo.pdf
Olfactory receptor cells and auditory receptors share the fo.pdfadvancethchnologies
 
Olivia a oneyearold infant is brought to the emergency r.pdf
Olivia a oneyearold infant is brought to the emergency r.pdfOlivia a oneyearold infant is brought to the emergency r.pdf
Olivia a oneyearold infant is brought to the emergency r.pdfadvancethchnologies
 
Okul andaki nfusun yzde on drd zel okullara gidiyor ve.pdf
Okul andaki nfusun yzde on drd zel okullara gidiyor ve.pdfOkul andaki nfusun yzde on drd zel okullara gidiyor ve.pdf
Okul andaki nfusun yzde on drd zel okullara gidiyor ve.pdfadvancethchnologies
 
oklu ve ldrc aleller neden klasik Mendel monohibrit ve .pdf
oklu ve ldrc aleller neden klasik Mendel monohibrit ve .pdfoklu ve ldrc aleller neden klasik Mendel monohibrit ve .pdf
oklu ve ldrc aleller neden klasik Mendel monohibrit ve .pdfadvancethchnologies
 
Okuyucunun trevleri anladn ve anlk hzn dxdt tanmn bildii.pdf
Okuyucunun trevleri anladn ve anlk hzn dxdt tanmn bildii.pdfOkuyucunun trevleri anladn ve anlk hzn dxdt tanmn bildii.pdf
Okuyucunun trevleri anladn ve anlk hzn dxdt tanmn bildii.pdfadvancethchnologies
 
okay ment rebuild the project what is the first ertor you g.pdf
okay ment rebuild the project what is the first ertor you g.pdfokay ment rebuild the project what is the first ertor you g.pdf
okay ment rebuild the project what is the first ertor you g.pdfadvancethchnologies
 
ok hcre saln destekleyen oksijenin verilmesi ve gereksinim.pdf
ok hcre saln destekleyen oksijenin verilmesi ve gereksinim.pdfok hcre saln destekleyen oksijenin verilmesi ve gereksinim.pdf
ok hcre saln destekleyen oksijenin verilmesi ve gereksinim.pdfadvancethchnologies
 
Office Automation Inc developed a proposal for implementin.pdf
Office Automation Inc developed a proposal for implementin.pdfOffice Automation Inc developed a proposal for implementin.pdf
Office Automation Inc developed a proposal for implementin.pdfadvancethchnologies
 
Of the 214 million US firms without paid employees 32 a.pdf
Of the 214 million US firms without paid employees 32 a.pdfOf the 214 million US firms without paid employees 32 a.pdf
Of the 214 million US firms without paid employees 32 a.pdfadvancethchnologies
 
Of the following which is NOT true about the service econom.pdf
Of the following which is NOT true about the service econom.pdfOf the following which is NOT true about the service econom.pdf
Of the following which is NOT true about the service econom.pdfadvancethchnologies
 
Of the following which is the biggest risk factor for the d.pdf
Of the following which is the biggest risk factor for the d.pdfOf the following which is the biggest risk factor for the d.pdf
Of the following which is the biggest risk factor for the d.pdfadvancethchnologies
 
Of the four universal forces strong weak electromagnetic.pdf
Of the four universal forces strong weak electromagnetic.pdfOf the four universal forces strong weak electromagnetic.pdf
Of the four universal forces strong weak electromagnetic.pdfadvancethchnologies
 

More from advancethchnologies (20)

On day 1 of the menstrual cycle FSH levels will be 25 pts .pdf
On day 1 of the menstrual cycle FSH levels will be 25 pts .pdfOn day 1 of the menstrual cycle FSH levels will be 25 pts .pdf
On day 1 of the menstrual cycle FSH levels will be 25 pts .pdf
 
On August 2 1971 Commander Scott of Apollo 15 confirmed Ga.pdf
On August 2 1971 Commander Scott of Apollo 15 confirmed Ga.pdfOn August 2 1971 Commander Scott of Apollo 15 confirmed Ga.pdf
On August 2 1971 Commander Scott of Apollo 15 confirmed Ga.pdf
 
On April 1 2024 Ivanhoe Company purchased 41600 common sh.pdf
On April 1 2024 Ivanhoe Company purchased 41600 common sh.pdfOn April 1 2024 Ivanhoe Company purchased 41600 common sh.pdf
On April 1 2024 Ivanhoe Company purchased 41600 common sh.pdf
 
On any given day the probability that Marco eats sushi for .pdf
On any given day the probability that Marco eats sushi for .pdfOn any given day the probability that Marco eats sushi for .pdf
On any given day the probability that Marco eats sushi for .pdf
 
Objective Draw the data path and interface with the control.pdf
Objective Draw the data path and interface with the control.pdfObjective Draw the data path and interface with the control.pdf
Objective Draw the data path and interface with the control.pdf
 
On a certain island there is a population of snakes foxes.pdf
On a certain island there is a population of snakes foxes.pdfOn a certain island there is a population of snakes foxes.pdf
On a certain island there is a population of snakes foxes.pdf
 
Omnichannel retailing is A when a retailer either closes .pdf
Omnichannel retailing is A when a retailer either closes .pdfOmnichannel retailing is A when a retailer either closes .pdf
Omnichannel retailing is A when a retailer either closes .pdf
 
Omigo On a Mission to Create a Bidet Culture in the United .pdf
Omigo On a Mission to Create a Bidet Culture in the United .pdfOmigo On a Mission to Create a Bidet Culture in the United .pdf
Omigo On a Mission to Create a Bidet Culture in the United .pdf
 
Olfactory receptor cells and auditory receptors share the fo.pdf
Olfactory receptor cells and auditory receptors share the fo.pdfOlfactory receptor cells and auditory receptors share the fo.pdf
Olfactory receptor cells and auditory receptors share the fo.pdf
 
Olivia a oneyearold infant is brought to the emergency r.pdf
Olivia a oneyearold infant is brought to the emergency r.pdfOlivia a oneyearold infant is brought to the emergency r.pdf
Olivia a oneyearold infant is brought to the emergency r.pdf
 
Okul andaki nfusun yzde on drd zel okullara gidiyor ve.pdf
Okul andaki nfusun yzde on drd zel okullara gidiyor ve.pdfOkul andaki nfusun yzde on drd zel okullara gidiyor ve.pdf
Okul andaki nfusun yzde on drd zel okullara gidiyor ve.pdf
 
oklu ve ldrc aleller neden klasik Mendel monohibrit ve .pdf
oklu ve ldrc aleller neden klasik Mendel monohibrit ve .pdfoklu ve ldrc aleller neden klasik Mendel monohibrit ve .pdf
oklu ve ldrc aleller neden klasik Mendel monohibrit ve .pdf
 
Okuyucunun trevleri anladn ve anlk hzn dxdt tanmn bildii.pdf
Okuyucunun trevleri anladn ve anlk hzn dxdt tanmn bildii.pdfOkuyucunun trevleri anladn ve anlk hzn dxdt tanmn bildii.pdf
Okuyucunun trevleri anladn ve anlk hzn dxdt tanmn bildii.pdf
 
okay ment rebuild the project what is the first ertor you g.pdf
okay ment rebuild the project what is the first ertor you g.pdfokay ment rebuild the project what is the first ertor you g.pdf
okay ment rebuild the project what is the first ertor you g.pdf
 
ok hcre saln destekleyen oksijenin verilmesi ve gereksinim.pdf
ok hcre saln destekleyen oksijenin verilmesi ve gereksinim.pdfok hcre saln destekleyen oksijenin verilmesi ve gereksinim.pdf
ok hcre saln destekleyen oksijenin verilmesi ve gereksinim.pdf
 
Office Automation Inc developed a proposal for implementin.pdf
Office Automation Inc developed a proposal for implementin.pdfOffice Automation Inc developed a proposal for implementin.pdf
Office Automation Inc developed a proposal for implementin.pdf
 
Of the 214 million US firms without paid employees 32 a.pdf
Of the 214 million US firms without paid employees 32 a.pdfOf the 214 million US firms without paid employees 32 a.pdf
Of the 214 million US firms without paid employees 32 a.pdf
 
Of the following which is NOT true about the service econom.pdf
Of the following which is NOT true about the service econom.pdfOf the following which is NOT true about the service econom.pdf
Of the following which is NOT true about the service econom.pdf
 
Of the following which is the biggest risk factor for the d.pdf
Of the following which is the biggest risk factor for the d.pdfOf the following which is the biggest risk factor for the d.pdf
Of the following which is the biggest risk factor for the d.pdf
 
Of the four universal forces strong weak electromagnetic.pdf
Of the four universal forces strong weak electromagnetic.pdfOf the four universal forces strong weak electromagnetic.pdf
Of the four universal forces strong weak electromagnetic.pdf
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 

Number 1 I have completed and number 6 is just uploading I .pdf

  • 1. Number 1 I have completed and number 6 is just uploading. I just need some help with the 2,3,4 and 5. This is my code from Vector.cs: using System; using System.Collections.Generic; using System.Text; namespace Vector { public class Vector<T> { // This constant determines the default number of elements in a newly created vector. // It is also used to extended the capacity of the existing vector private const int DEFAULT_CAPACITY = 10; // This array represents the internal data structure wrapped by the vector class. // In fact, all the elements are to be stored in this private array. // You will just write extra functionality (methods) to make the work with the array more convenient for the user. private T[] data; // This property represents the number of elements in the vector public int Count { get; private set; } = 0; // This property represents the maximum number of elements (capacity) in the vector public int Capacity { get { return data.Length; } } // This is an overloaded constructor public Vector(int capacity) { data = new T[capacity]; } // This is the implementation of the default constructor public Vector() : this(DEFAULT_CAPACITY) { } // An Indexer is a special type of property that allows a class or structure to be accessed the same way as array for its internal collection. // For example, introducing the following indexer you may address an element of the vector as vector[i] or vector[0] or ... public T this[int index] { get { if (index >= Count || index < 0) throw new IndexOutOfRangeException(); return data[index];
  • 2. } set { if (index >= Count || index < 0) throw new IndexOutOfRangeException(); data[index] = value; } } // This private method allows extension of the existing capacity of the vector by another 'extraCapacity' elements. // The new capacity is equal to the existing one plus 'extraCapacity'. // It copies the elements of 'data' (the existing array) to 'newData' (the new array), and then makes data pointing to 'newData'. private void ExtendData(int extraCapacity) { T[] newData = new T[Capacity + extraCapacity]; for (int i = 0; i < Count; i++) newData[i] = data[i]; data = newData; } // This method adds a new element to the existing array. // If the internal array is out of capacity, its capacity is first extended to fit the new element. public void Add(T element) { if (Count == Capacity) ExtendData(DEFAULT_CAPACITY); data[Count] = element; Count++; } // This method searches for the specified object and returns the zerobased index of the first occurrence within the entire data structure. // This method performs a linear search; therefore, this method is an O(n) runtime complexity operation. // If occurrence is not found, then the method returns 1. // Note that Equals is the proper method to compare two objects for equality, you must not use operator '=' for this purpose. public int IndexOf(T element) { for (var i = 0; i < Count; i++) { if (data[i].Equals(element)) return i; } return -1; } // TODO: Your task is to implement all the remaining methods.
  • 3. // Read the instruction carefully, study the code examples from above as they should help you to write the rest of the code. public void Insert(int index, T element) { if (Count == Capacity) { ExtendData(DEFAULT_CAPACITY);//Used to increase capacity of vector and copy old elements into new } //If index is equal to count, add an element to the end if (index == Count) { Add(element); return; } //Check if a element is being insterted outside of the vector. If it is, throws an exception if (index > Count || index < 0) { throw new IndexOutOfRangeException("Index is out of range: " + index); } int count = Count; while (count != index)//While loop to shuffle elements to the end of vector { data[count] = data[count - 1];//Shuffle count--;//Goes Back } data[count] = element;//Add element Count++;//Increase vector size for new element } public void Clear() { Array.Clear(data, 0, Count); //Clear all elements from the array. Count = 0; //Sets Count to 0 } public bool Contains(T element) { //Check if element is in vector return IndexOf(element) != -1; } public bool Remove(T element) {
  • 4. int index = IndexOf(element);//Variable to find index of a particular element if (index > -1) //Check if its valid { RemoveAt(index);//Removes a particular element at index return true; } return false;//method needs return type } public void RemoveAt(int index) { //Check if the index is within the range of the array. if (index < 0 || index >= Count) { throw new IndexOutOfRangeException("Index is out of range: " + index); } //Removes the element of an index from the vector for (int i = index; i < Count - 1; i++) { data[i] = data[i + 1]; } Count--;//Decrease Count due to remove of element } public override string ToString() { StringBuilder stringBuild = new StringBuilder("[", 50);// Stringbuilder Instance for (var i = 0; i < Count; i++) //for loop to add , to each element { stringBuild.Append(data[i]);//Calls append to string if (i != Count - 1) stringBuild.Append(',');//Check if Count is last elemnt and adjusts if not } stringBuild.Append(']'); return stringBuild.ToString();//has to return has method has return type } } } Here is ss of the tester.cs: Please comment the new code as well so I can learn it for next task. Thank you. 1. Create a copy of your solution for Task 1.1 and replace the Tester.cs file by that attached to this task. The Main method of the new Tester class is to be compatible with the Vector T>. Again, it contains a series of tests that will verify if the functionality that you need to develop in this task works correctly. See Appendix A for an example of what the program will output when working
  • 5. correctly. 2. Extend your Vector <T> class by adding the following two overloaded methods: - void Sort() Sorts the elements in the entire Vector >> collection. The order of elements is determined by the default comparer for type T, which is comparer <T, Default. - void Sort( IComparer comparer ) Sorts the elements in the entire Vector <T> collection using the specified comparer. If the comparer is null, the order of elements is determined by the default comparer for type T, which is In this task, the implementation of both methods does not require you to implement any sorting algorithm. Instead, you should delegate sorting of data elements to Array.Sort, which implements the Introspective sorting algorithm as the sorting method for the Array class. Similar to the two methods above, Array.Sort is overloaded and has two versions: One that accepts an array along with the starting index and the number of elements to define the range for sorting, and the other, which additionally accepts a comparer object for the purpose of determining the order of elements. Read about these two methods at https://learn.microsoft.com/en- us/dotnet/api/system.array?redirectedfrom=MSDN&view=net-7.0#methods Once you have your both Sort methods set up, you should be able to sort integers and succeed with tests A, B, C, and D in the attached Tester class. To enable these tests, uncomment the respective code lines in Tester.cs file.| 3. Explore the Student class provided in Tester.cs file. To make two students comparable (and thus sorted in the Vector <T> collection like in the List<T> ), you must enable a mechanism that automatically compares two elements of type Student. Keep in mind that in this case T is a blueprint type, which during the runtime will be replaced by the Student class. 4. One way to make two elements comparable in the .NET Framework is to introduce a comparison method right in the type, for example, in the Student class. This is how we can 'teach' the type to compare one element (referred to as this) with the other element (referred to as another) of the same type. In the code, this should be done by implementing the special interface in the class, which in its turn requires implementation of the CompareTo(T another) method that compares this (current) element with another element and returns an integer value. The integer values is - less than zero, when this (current) element must precede another element specified as the argument,- zero, when this (current) element is seen as equal to another element, - greater Ghan zero, when this (current) element must succeed another element. Your task now is to modify the Student class and implement the IComparable > interface along with its underlying CompareTo(Student another) method so that it can sequence students in the ascending order of the ID attribute. When this is done, you should be able to sort objects of Student class via the Sort( ) method of the Vector <T> class. Complete this part to pass Test E by activating its respective code lines in the program code. 5. The other way to make two elements comparable is to develop a so-called comparator class, whose purpose is to compare a pair of elements of specific type. Such comparator class must implement the IComparer T> interface. The IComparable T is similar to the IComparer T>, except that the CompareTo(T another) method belongs to the type, while Compare (Ta,T b) is part of an independent class implementing the IComparer T>. The Compare(T a, T b) method implied by the Comparer T> returns an integer value indicating whether argument a is less than, equal to, or greater than argument b, exactly as the CompareTo method does. There are a few examples of classes implementing the IComparer > interface in Tester.cs file that sort integers in ascending, descending, or in the order that places even integers prior to odd integers. You should learn from these examples to develop your own comparator for the Student class. Specifically, your task is to
  • 6. provide two comparators for the Student class: - AscendinglDComparer to sort a sequence of students stored in an instance of the Vector SStudent> class in the ascending order of IDs; - DescendingNameDescendingldComparer to sort a sequence of students stored in an instance of the Vector Student> class in the descending order of names, breaking ties by the descending order of IDs. Once this is done, you should be able to pass tests F and G. Make sure that students appear in the desired order. Keep in mind that any of these comparators can be the argument of the Sort(IComparer T> comparer) method of the Vector <T> class; so, test how they work with your Vector < Student > class. 6. Submit the new version of the Vector <T> class and the updated Tester.cs file that now constains the extended Student class and both AscendinglDComparer and DescendingNameDescendingldComparer classes.AStudent student = new Student() { Name = names [ random. Next (, names. Length )], Id =i}; Console.Writeline("Add student with record: " + student. ToString()); students. Add(student); Console.Writeline("Sort the students in the order defined by the DescendingNameDescendingIdComparer class"); // uncomment the line to activate the test //students. Sort(new DescendingNameDescendingIdComparer ()); Console. Writeline("Print the vector of students via students. ToString(); "); Console. Writeline(students. ToString()); Console. Writeline(" : SUCCESS"); result = result +mG; catch (Exception exception) Console.Writeline(" : FAIL"); Console . Writeline(exception. ToString()); result = result +n"; Console. Writeline(" n Console. Writeline("Tests passed: "+ result); Console.ReadKey();