Skip to main content

Posts

Showing posts with the label DSDP

DSDP - Week 2 Lab - Exercise 1

Week 2 Lab - Exercise 1 In this lab, we look at manipulating objects in an array, resizing array, and using dynamic and generic collections. 1.        Create a new console application. 2.        Create 3 new classes as shown below                                                                                                                                             3.        In the Main method do the following ·        Create an array farmAnimals that can hold objects of type Animals. ·   ...

DSDP Arrays Lab

Week 2 Lab Ex 1 In this lab we learn about Sorting an array, using ForEach loop, and Random class: Open Visual Studio 2012 Create a new project  by going to File --> New --> Project Select Visual C# --> Windows Desktop -->  Console Application In the Name field, type "W2Lab1-[Last_name]", where [Last_Name] is replaced with your last name. In the location field, give a directory location and click ok. Add code to declare and initialize an Int array that can hold 7 Integers. Using a For loop assign random numbers from the range 1 to 49 inclusive to the above array. Sort the array Using a ForEach loop display the seven numbers separated by tabs to console Week 2 Lab Ex 2  In this lab we learn about Linear Search and break: Add new console application project to the above solution Create an array which hold 20 random numbers in the range of 1 and 100. Using a For loop search for an integer given by user. Break out of the loop if the i...

Singleton Pattern

Singleton Pattern is used to control the instantiation of a class. A Singleton class can have only one instance and the class provides a global access point to that instance. The singleton class has the following responsibility: ensures that only one instance of the class is created. provides access to that instance of the object. ideally the singleton instance should be created only when it is needed. There are situation when we need a single unique instance of a class. To do this we can make the constructor of the class private so that only the class itself is capable of creating an instance of itself. We can hold the instance of the singleton class in a global variable and provide access to this instance through a global method. However, a global variable would exist for the duration of the program taking up resources. This could become a problem when the instance is resource-intensive. Therefore, you may want to create such an object only when it is needed. Si...