CS 2301-03 – Fall 2011

?CSE1322 – C# Lab 2 – ReviewKnow Your Integrated Development EnvironmentLab 2ObjectivesFamiliarize yourself with the Visual Studio IDE.Review searching an array, classes, and objects.For this lab, you should work alone.? The intent is to allow you to familiarize yourself with the Visual Studio IDE and remind you of previous exercises.BackgroundLike most IDEs, Visual Studio offers many features - so many that we won't touch most in this course.? But all modern Integrated Development Environments (IDEs) allow the programmer to write code, manage projects (and all the files within the project), compile, execute, and debug their programs.For this lab, you'll need access to the Visual Studio IDE.TasksThis lab has two parts:Writing a searching function for 1D arrays.Writing a simple class.Part 1 – SearchingContinuing with arrays, we will now expect you to find information in an array and derive useful properties from the information stored in an array.Start Visual Studio.Go to the File menu and select?New Project.Notice that you have a choice of languages. Let's choose a C# project, but make sure you choose a Console Application. Call it YOURNAME_Lab1BArray.Change the directory location to something "safe". You may want to temporarily choose the Desktop and then save the file to something permanent once you're done (e.g. a network drive or flash drive).Create a Main method, and create a 2D integer array called data, with a size of five (5) by five (5). Ask the user to input the values for this array (Scanner’s nextInt).Create a method called LongestPositiveSeries, that takes in a 2D array and finds the length of the longest continuous series of positive numbers in it.For example, if we had an array like this:012345-1-5-553-25625-1505503244625000The length would be 5. For this problem, 0 is considered non-negative and not positive, so we start counting from index [0, 1] (which is 1) to [1, 0] (which is 5) and end at index [1, 1] (which is –1).Hint: Consider using a basic linear search and modifying it to keep track of the current positive streak of numbers.Call that method in your Main, for the array data.Print out the returned result from your method in your Main, along with the content of data.Part 2 – Classes and ObjectsFor this part of the lab, you'll be writing methods to work with classes and objects.Create a new project, called YOURNAME_Lab1BClass.You should consider developing the methods for this project incrementally.Now create another class inside of your project. Go to the Solution Explorer panel, right click on the project name and select Add -> Class.Name the class at the bottom of the pop-up window, Person.Inside of your Person class add two class variables, one for first and one for last name.Create a default (no parameters) constructor method that sets their first name to "Bob” and last name to “Smith”.Create an overloaded constructor method that takes in two parameters and sets their names to them. One parameter will be their first name and the second will be their last name.Create a getter/accessor method and setter/mutator method for both their first and last names.Lastly, create an overriden ToString method that will return the person’s first then last name.Hint: The method header would be:public override String ToString()In your Main method, create an object/instance of your Person class using the default constructor. Create another Person using the overloaded constructor. Have the values that are passed in as arguments come from user input (ReadLine).Directly print out both people’s values using the ToString method.Hint: The ToString method is automatically called when an object/instance is placed into a WriteLine method call.Now change one person’s first name to “Aly” and the other person’s last name to “Sanchez”.Hint: Use the setters/mutators to do so. Please do not create two entirely new objects.Finally, print out both names for both people using the getters/accessors.What to Turn In:Follow submission guidelines on this page: ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download