.net lab

veerpatel21
Lab4.zip

Lab4/Misc/documentation.png

Lab4/Labs/Lab4/Lab4b.exe

Lab4/Labs/Lab4/lab4.htm

COMP10204 - Lab 4
To do this lab, you will need to use C# in Visual Studio Professional 2017. You can find this program in the Visual Studio folder, or, if working from home, download and install it as described by the instructions on the main course web page under Hardware and Software.  

To Be Graded - Details

  • These programs will be marked for 6% of your final grade
  • Please examine the Marking Scheme to see the marks breakdown
  • These programs need to have appropriate internal comments, as well as XML comments for every class and every method
  • These programs also need to have an appropriate comment block that contains:
    • Your name and student number
    • The file date
    • The program's purpose
    • Your Statement of Authorship
    • Bundle your projects into one Zip file, save it as LastnameFirstinitial.zip, and upload it to the Dropbox
    • Please read about documentation style
    • Programs that are late or do not include a Statement of Authorship will be penalized 10% per day (includes each day of a weekend)

      Part A: It Takes All Sorts

      Project Name: Lab4a        Create Class: Employee

      In Lab 1 you read a file of Employee objects into an array. That array could be sorted on any of the fields of the class. Since then, we've learned about properties, generics, collections, and lambda expressions.   Using your solution (or mine) rewrite Lab 1 so that it:
        • Eliminates the need for Get()/Set() methods in the Employee class by using properties instead
        • Eliminates the array (and the arbitrary limit) that stores all of the Employee objects, and instead utilizes a generic List<T> collection
        • Eliminates the Sort() method that you researched and instead relies on the built-in Sort() method of the List<T> collection
        • Makes use of the IComparable interface so that each field of the Employee class can be sorted
        • Alternatively, you can use a lambda expression for sorting instead of the IComparable technique
        • Looks and behaves identically to the solution for Lab 1 but utilizes the above changes
        • Contains a highly modularized Main() method

        Part B: A Tangled Web

        Project Name: Lab4b

        Write a Windows Form App (.NET Framework) that:
          • Makes use of a GUI interface that has menu options
          • The File=>Load menu option displays an OpenFileDialog to allow the user to select a valid HTML file
          • Makes use of the OpenFileDialog.Filter property to allow only HTML files to be selected
          • Uses a generic Stack<T> collection to read the HTML file and determine if the HTML container tags are properly balanced (that is, each opening tag has a corresponding closing tag)
          • Displays a status indicating whether the container tags are balanced, or not balanced
          • Ignores certain HTML tags that are not container tags (such as <img>, <hr> or <br>)
          • Contains a modularized Process=>Check Tags method
          • You may download this sample program for a demonstration of program behaviour
          • Here are examples of good and bad test files that you can use to test your program: TestFiles.zip
        (click to enlarge)

        Marking Scheme

        Documentation: Comments, Naming Conventions / 5
        It Takes All Sorts
        Properties: / 2
        Generic List: Sort, IComparable/Lambda / 3
        Identical Behaviour: / 2
        A Tangled Web
        Data Entry: File Name, Reads File / 3
        Generic Stack: Stores Tags / 4
        Output: Message Displayed / 1
        Total: / 20

This page is maintained by: nicholas.corkigian@mohawkcollege.ca

Lab4/Labs/Lab4/TestFiles.zip

BadTest.html

Test File

Here's a simple webpage. We are using it as an example file.

Here's a link tag link

        Here's a photo
Stuff Goes Here
Or Possibly Here

Test.html

Test File

Here's a simple webpage. We are using it as an example file.

Here's a link tag link

        Here's a photo
Stuff Goes Here
Or Possibly Here

Lab4/Labs/Lab4/Lab4B.png

Lab4/images/red-gradient.jpg

Lab4/Lab1 solution.zip

Lab1/Lab1/.vs/Lab1/v15/.suo

Lab1/Lab1/.vs/Lab1/v15/Server/sqlite3/db.lock

Lab1/Lab1/.vs/Lab1/v15/Server/sqlite3/storage.ide

Lab1/Lab1/Lab1.sln

Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Express 2013 for Windows Desktop VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab1", "Lab1\Lab1.csproj", "{2575485E-07F8-4780-B3F8-610D1AF51D41}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {2575485E-07F8-4780-B3F8-610D1AF51D41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2575485E-07F8-4780-B3F8-610D1AF51D41}.Debug|Any CPU.Build.0 = Debug|Any CPU {2575485E-07F8-4780-B3F8-610D1AF51D41}.Release|Any CPU.ActiveCfg = Release|Any CPU {2575485E-07F8-4780-B3F8-610D1AF51D41}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal

Lab1/Lab1/Lab1.suo

Lab1/Lab1/Lab1.v12.suo

Lab1/Lab1/Lab1/bin/Debug/employees.txt

Bruce Wayne 123456 25.88 35.50
Clark Kent 232344 25.88 38.75
Diana Prince 657659 27.62 30.25
Hal Jordan 989431 23.14 44.25
Barry Allan 342562 25.12 25.50
Arthur Curry 565603 21.09 23.75
John Jones 812984 18.99 32.75
Dinah Lance 342988 18.99 34.50
Oliver Queen 340236 17.45 41.25
Ray Palmer 120985 24.75 40.00
Ronald Raymond 239824 16.43 35.00
Carter Hall 657123 19.34 42.75
Shayera Hol 761742 16.73 38.50

Lab1/Lab1/Lab1/bin/Debug/Lab1.exe

Lab1/Lab1/Lab1/bin/Debug/Lab1.pdb

Lab1/Lab1/Lab1/bin/Debug/Lab1.vshost.exe

Lab1/Lab1/Lab1/bin/Debug/Lab1.vshost.exe.manifest

Lab1/Lab1/Lab1/bin/Release/employees.txt

Bruce Wayne 123456 25.88 35.50
Clark Kent 232344 25.88 38.75
Diana Prince 657659 27.62 30.25
Hal Jordan 989431 23.14 44.25
Barry Allan 342562 25.12 25.50
Arthur Curry 565603 21.09 23.75
John Jones 812984 18.99 32.75
Dinah Lance 342988 18.99 34.50
Oliver Queen 340236 17.45 41.25
Ray Palmer 120985 24.75 40.00
Ronald Raymond 239824 16.43 35.00
Carter Hall 657123 19.34 42.75
Shayera Hol 761742 16.73 38.50

Lab1/Lab1/Lab1/bin/Release/Lab1.exe

Lab1/Lab1/Lab1/bin/Release/Lab1.pdb

Lab1/Lab1/Lab1/Employee.cs

using System; using System.Collections.Generic; using System.Linq; using System.Text; /// <summary> /// This class describes the employee /// </summary> public class Employee { private string name; // The employee name private int number; // The employee ID private decimal rate; // The hourly rate private double hours; // The weekly hours private decimal gross; // The gross pay /// <summary> /// Default constructor for Employee - used for creating Employee array /// </summary> public Employee() { } /// <summary> /// Four-argument constructor for Employee /// </summary> /// <param name="name">Employee name</param> /// <param name="number">Employee number</param> /// <param name="rate">Hourly rate of pay</param> /// <param name="hours">Hours worked in a week</param> public Employee(string name, int number, decimal rate, double hours) { /* This is the better way to set data in a class - use the accessor methods. * That way, if their implementation changes, the constructor doesn't need to * be edited as well. */ SetName(name); SetNumber(number); SetRate(rate); SetHours(hours); gross = GetGross(); } // The following Get methods allow for private data retrieval - in the future we'll use properties /// <summary> /// Gross pay get method /// </summary> /// <returns>Gross pay for the week</returns> public decimal GetGross() { // Gross pay is not stored in the file, but is a calculated value if (hours < 40) gross = (decimal)hours * rate; else gross = (40.0m * rate) + (((decimal)hours - 40.0m) * rate * 1.5m); return gross; } /// <summary> /// Hours get method /// </summary> /// <returns>Hours worked this week</returns> public double GetHours() { return hours; } /// <summary> /// Name get method /// </summary> /// <returns>Employee name</returns> public string GetName() { return name; } /// <summary> /// Number get method /// </summary> /// <returns>Employee number</returns> public int GetNumber() { return number; } /// <summary> /// Rate get method /// </summary> /// <returns>Hourly rate of pay</returns> public decimal GetRate() { return rate; } /// <summary> /// Employee display method - in the future, we'll override the ToString method of Object /// </summary> public void PrintEmployee() { System.Console.WriteLine("{0, -20} {1:D5} {2,6:C} {3:#0.00} {4,9:C}", GetName(), GetNumber(), GetRate(), GetHours(), GetGross()); } // The following Set methods allow for private data modification - in the future we'll use properties /// <summary> /// Hours set method /// </summary> /// <param name="hours">Hours worked this week</param> public void SetHours(double hours) { this.hours = hours; } /// <summary> /// Name set method /// </summary> /// <param name="name">Employee name</param> public void SetName(string name) { this.name = name; } /// <summary> /// Number set method /// </summary> /// <param name="number">Employee number</param> public void SetNumber(int number) { this.number = number; } /// <summary> /// /// </summary> /// <param name="rate">Hourly rate of pay</param> public void SetRate(decimal rate) { this.rate = rate; } }

Lab1/Lab1/Lab1/Lab1.cs

/// /// Program: Employee Sort /// /// Author: Nicholas J. Corkigian /// Date: February 2010 /// /// Purpose: This program reads the employee.txt data file and stores the information in an array of /// Employee objects. The user is then presented with a menu that allows them to select which /// of five fields to sort the resultant table by: Employee name, ID, rate, hours, or gross pay. /// /// The program ends when the user selects the exit option from the menu. /// using System; using System.IO; /// <summary> /// This is the main tester class that the program starts at /// </summary> class Lab1 { /// <summary> /// The main method reads the data file, populates the Employee array and provides a menu of sort options. /// </summary> /// <param name="args">Command line arguments are not used in this program</param> static void Main(string[] args) { int count; // Keep track of how many employees are instantiated bool loop = true; // A loop control variable string input; // The user's menu option pick as a string int choice; // The user's menu option pick as an integer Employee[] employees; // The array of Employee objects // Read the data file to build the Employee array and find out how many there are Read(out employees, out count); // Keep the menu loop running so the user can sort several times while (loop) { // Display the menu and retrieve the user's choice input = Menu(); // Based on the user's entry, sort using the appropriate option if (Int32.TryParse(input, out choice)) { switch (choice) { // Sort by employee name - ascending case 1: Sort(employees, count, 1); break; // Sort by employee ID number - ascending case 2: Sort(employees, count, 2); break; // Sort by hourly rate - descending case 3: Sort(employees, count, 3); break; // Sort by weekly hours - descending case 4: Sort(employees, count, 4); break; // Sort by gross pay - descending case 5: Sort(employees, count, 5); break; // Exit the program case 6: loop = false; break; // Trap invalid selections to try again default: Console.WriteLine("\n*** Invalid Choice - Try Again ***\n"); break; } // Display the table when a valid choice is made, otherwise display an error if (choice >= 0 && choice <= 5) DisplayTable(employees, count); } else Console.WriteLine("\n*** Invalid Choice - Try Again ***\n"); } } /// <summary> /// This method displays the entire table, including column headers /// </summary> /// <param name="employees">The array of employees</param> /// <param name="count">How many employees are in use</param> private static void DisplayTable(Employee[] employees, int count) { Console.Clear(); Console.WriteLine("Employee Number Rate Hours Gross Pay Nick's Company"); Console.WriteLine("==================== ====== ====== ===== ========= --------------"); // Display each employee in the array for (int i = 0; i < count; i++) employees[i].PrintEmployee(); Console.WriteLine(); } /// <summary> /// This method displays the menu options to the user and returns their selection /// </summary> /// <returns>The user's menu selection</returns> private static string Menu() { Console.WriteLine("1. Sort by Employee Name"); Console.WriteLine("2. Sort by Employee Number"); Console.WriteLine("3. Sort by Employee Pay Rate"); Console.WriteLine("4. Sort by Employee Hours"); Console.WriteLine("5. Sort by Employee Gross Pay"); Console.WriteLine("\n6. Exit"); Console.Write("\nEnter choice: "); return Console.ReadLine(); } /// <summary> /// This method reads the data file and stores all of the employee information in an array of Employees /// </summary> /// <param name="employees">The array of employees</param> /// <param name="count">How many employees are in use</param> private static void Read(out Employee[] employees, out int count) { count = 0; // The current number of employees string input; // One line of data read from the file employees = new Employee[100]; // The Employee array try { // Open the file for reading purposes FileStream file = new FileStream("employees.txt", FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(file); // As long as there is data in the file, keep processing // Each employee record is comma separated, so explode each piece into an array, // create a new employee object and increment the count while ((input = reader.ReadLine()) != null) { string[] exploded = input.Split(','); employees[count] = new Employee(exploded[0], int.Parse(exploded[1]), decimal.Parse(exploded[2]), double.Parse(exploded[3])); count++; } reader.Close(); // Always good form to close the file } // Just in case the file can't be found - graceful exit catch (IOException e) { Console.WriteLine("*** File is empty - Program Aborting ***\n"); Environment.Exit(1); } } /// <summary> /// This method uses a Bubble Sort to rearrange the Employee array in order. Since there are /// five possible ways to sort, the outer loops remain the same and instead the condition is /// different for each field to sort on. /// </summary> /// <param name="emps">The array of employees</param> /// <param name="size">How many employees are in use</param> /// <param name="choice">The user selected sort choice</param> public static void Sort(Employee[] emps, int size, int choice) { for (int a = 0; a < size - 1; a++) for (int b = 0; b < size - 1; b++) switch (choice) { case 1: // Sort by employee name - ascending if (emps[b].GetName().CompareTo(emps[b + 1].GetName()) > 0) Swap(ref emps[b], ref emps[b + 1]); break; case 2: // Sort by employee ID - ascending if (emps[b].GetNumber() > emps[b + 1].GetNumber()) Swap(ref emps[b], ref emps[b + 1]); break; case 3: // Sort by hourly rate -descending if (emps[b].GetRate() < emps[b + 1].GetRate()) Swap(ref emps[b], ref emps[b + 1]); break; case 4: // Sort by weekly hours - descending if (emps[b].GetHours() < emps[b + 1].GetHours()) Swap(ref emps[b], ref emps[b + 1]); break; case 5: // Sort by gross pay - descending if (emps[b].GetGross() < emps[b + 1].GetGross()) Swap(ref emps[b], ref emps[b + 1]); break; } } /// <summary> /// This method is a utility method for the Bubble Sort. It just swaps two elements in the array /// </summary> /// <param name="a">First employee</param> /// <param name="b">Second employee</param> private static void Swap(ref Employee a, ref Employee b) { Employee temp; // A temporary holding spot for an employee temp = a; a = b; b = temp; } }

Lab1/Lab1/Lab1/Lab1.csproj

Debug AnyCPU 9.0.30729 2.0 {2575485E-07F8-4780-B3F8-610D1AF51D41} Exe Properties Lab1 Lab1 v4.0 512 3.5 true full false bin\Debug\ DEBUG;TRACE prompt 4 pdbonly true bin\Release\ TRACE prompt 4 3.5 3.5 3.5

Lab1/Lab1/Lab1/Lab1.csproj.user

Lab1/Lab1/Lab1/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache

Lab1/Lab1/Lab1/obj/Debug/Lab1.csproj.CoreCompileInputs.cache

a5e07115b6fb6adc30ab9eff7f2ebe2256e21109

Lab1/Lab1/Lab1/obj/Debug/Lab1.csproj.FileListAbsolute.txt

C:\Documents and Settings\corkign\Desktop\Lab1\Lab1\bin\Debug\Lab1.exe C:\Documents and Settings\corkign\Desktop\Lab1\Lab1\bin\Debug\Lab1.pdb C:\Documents and Settings\corkign\Desktop\Lab1\Lab1\obj\Debug\ResolveAssemblyReference.cache C:\Documents and Settings\corkign\Desktop\Lab1\Lab1\obj\Debug\Lab1.exe C:\Documents and Settings\corkign\Desktop\Lab1\Lab1\obj\Debug\Lab1.pdb C:\Documents and Settings\nicholas.corkigian\Desktop\Lab1\Lab1\obj\Debug\Lab1.exe C:\Documents and Settings\nicholas.corkigian\Desktop\Lab1\Lab1\obj\Debug\Lab1.pdb C:\Documents and Settings\nicholas.corkigian\Desktop\Lab1\Lab1\bin\Debug\Lab1.exe C:\Documents and Settings\nicholas.corkigian\Desktop\Lab1\Lab1\bin\Debug\Lab1.pdb C:\Documents and Settings\nicholas.corkigian\Desktop\Lab1\Lab1\obj\Debug\ResolveAssemblyReference.cache C:\Users\nicholas.corkigian\Desktop\Lab1\Lab1\Lab1\bin\Debug\Lab1.exe C:\Users\nicholas.corkigian\Desktop\Lab1\Lab1\Lab1\bin\Debug\Lab1.pdb C:\Users\nicholas.corkigian\Desktop\Lab1\Lab1\Lab1\obj\Debug\Lab1.csproj.CoreCompileInputs.cache C:\Users\nicholas.corkigian\Desktop\Lab1\Lab1\Lab1\obj\Debug\Lab1.exe C:\Users\nicholas.corkigian\Desktop\Lab1\Lab1\Lab1\obj\Debug\Lab1.pdb

Lab1/Lab1/Lab1/obj/Debug/Lab1.exe

Lab1/Lab1/Lab1/obj/Debug/Lab1.pdb

Lab1/Lab1/Lab1/obj/Release/Lab1.csproj.FileListAbsolute.txt

C:\Documents and Settings\corkign\Desktop\Lab1\Lab1\bin\Release\Lab1.exe C:\Documents and Settings\corkign\Desktop\Lab1\Lab1\bin\Release\Lab1.pdb C:\Documents and Settings\corkign\Desktop\Lab1\Lab1\obj\Release\ResolveAssemblyReference.cache C:\Documents and Settings\corkign\Desktop\Lab1\Lab1\obj\Release\Lab1.exe C:\Documents and Settings\corkign\Desktop\Lab1\Lab1\obj\Release\Lab1.pdb

Lab1/Lab1/Lab1/obj/Release/Lab1.exe

Lab1/Lab1/Lab1/obj/Release/Lab1.pdb

Lab1/Lab1/Lab1/Properties/AssemblyInfo.cs

using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Lab1")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Mohawk College")] [assembly: AssemblyProduct("Lab1")] [assembly: AssemblyCopyright("Copyright © Mohawk College 2010")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("1a3220c3-bcd1-44dd-aa57-a6c66005adea")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]

Lab4/default.css

/* Style Sheet for Course Pages - Styles cascade from the top down. Only one font is used for the entire site Written by Mark Yendt in October 2004 Modified by Rob Darling December 2004 for Course Page Template Modified by Mark Yendt November 2005 to match "Corporate" Ozone colour scheme and to be CSS complianant against IE 6.0/Netscape 7.0/Mozilla 1.0 */ body {font-family:Arial, Helvetica, sans-serif; font-size:12px; margin-left: .4in; margin-top: .4in; margin-right: .4in; margin-bottom: .4in; } pre {background-color:#999999; border:thin solid #666666; font-size:14px; font-weight:bold; } h1 {color: #B2AA7D; background-color:#00355f; letter-spacing:0.5em; font-size: 24px; padding: 0px 5px 0px 15px; border: thin solid; border-color:#000000; background-image:url(images/red-gradient.jpg); width: 100%; } h2 {color: #B2AA7D; background-color:#00355f; color: #FFFFFF; letter-spacing: 0.5em; font-size: 16px; padding: 0px 5px 0px 15px; border: thin solid; border-color:#000000; background-image:url(images/red-gradient.jpg); } h5 {font-weight:bold; font-size: 14px; } table.main {width:100%; border-color:#00355f; border-width:1px; border-style:solid; margin: 0px 0px 0px 0px; } table.intern {width:100%; border-color:#00355f; border-width:1px; border-style:solid; margin: 0px 0px 0px 0px; } table.header {width:100%; border-color:#00355f; border-width:1px; border-style:solid; margin: 0px 0px 0px 0px; } table {width:100%; border-color:#00355f; border-width:0px; border-style:solid; margin: 0px 0px 0px 0px; } a {font-weight:bold; color:#000080 } .THead {font-weight: bold; font-size: 16px; color: #B2AA7D; background-image:url(images/red-gradient.jpg)} a:visited {color: #B50C00} a:hover {color: #B50C00} a:active {color: #B50C00} td {font-size:12px; border-collapse:collapse; padding:2px; margin: 0px 0px 0px 0px; } .Normal { } .Normal2 {background-color:#E0E0E0; border-width:0px; border-color: #B50C00; } .Normal1 {background-color:#F0F0F0; border-width: 0px; border-color: #B50C00; } .Current {background-color:lightyellow } .Exam {background-color:#ADD8E6 } .Quiz {font-weight: bold; color:yellow; background-color: rgb(255, 0, 0); } .important {color:#FF0000; font:Arial, Helvetica, sans-serif; font-size:14px; font-weight:bold; } tr#grid td {padding-top: 5px; padding-bottom: 5px; }

Lab4/assignment.png