Skip to content

Commit

Permalink
Merge pull request ehilst515#2 from ehilst515/Lab08-Library
Browse files Browse the repository at this point in the history
library interface working
  • Loading branch information
ehilst515 authored Sep 3, 2020
2 parents 3ae4d3c + 936d183 commit 65f04d1
Show file tree
Hide file tree
Showing 8 changed files with 442 additions and 5 deletions.
16 changes: 15 additions & 1 deletion Library.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library", "Library\Library.csproj", "{B99D3954-CA4A-40E4-97A2-6BE43B8CE00F}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryProgram", "Library\LibraryProgram.csproj", "{B99D3954-CA4A-40E4-97A2-6BE43B8CE00F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryTests", "LibraryTests\LibraryTests.csproj", "{BD85273C-41E0-41DE-B629-C8C1D0A7C05F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -30,5 +32,17 @@ Global
{B99D3954-CA4A-40E4-97A2-6BE43B8CE00F}.Release|x64.Build.0 = Release|Any CPU
{B99D3954-CA4A-40E4-97A2-6BE43B8CE00F}.Release|x86.ActiveCfg = Release|Any CPU
{B99D3954-CA4A-40E4-97A2-6BE43B8CE00F}.Release|x86.Build.0 = Release|Any CPU
{BD85273C-41E0-41DE-B629-C8C1D0A7C05F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD85273C-41E0-41DE-B629-C8C1D0A7C05F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD85273C-41E0-41DE-B629-C8C1D0A7C05F}.Debug|x64.ActiveCfg = Debug|Any CPU
{BD85273C-41E0-41DE-B629-C8C1D0A7C05F}.Debug|x64.Build.0 = Debug|Any CPU
{BD85273C-41E0-41DE-B629-C8C1D0A7C05F}.Debug|x86.ActiveCfg = Debug|Any CPU
{BD85273C-41E0-41DE-B629-C8C1D0A7C05F}.Debug|x86.Build.0 = Debug|Any CPU
{BD85273C-41E0-41DE-B629-C8C1D0A7C05F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD85273C-41E0-41DE-B629-C8C1D0A7C05F}.Release|Any CPU.Build.0 = Release|Any CPU
{BD85273C-41E0-41DE-B629-C8C1D0A7C05F}.Release|x64.ActiveCfg = Release|Any CPU
{BD85273C-41E0-41DE-B629-C8C1D0A7C05F}.Release|x64.Build.0 = Release|Any CPU
{BD85273C-41E0-41DE-B629-C8C1D0A7C05F}.Release|x86.ActiveCfg = Release|Any CPU
{BD85273C-41E0-41DE-B629-C8C1D0A7C05F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
20 changes: 20 additions & 0 deletions Library/Author.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
namespace LibraryProgram
{
public class Author
{
public string FirstName { get; set; }
public string LastName { get; set; }

public string Name()
{
return $"{FirstName} {LastName}";
}

public Author(string firstName, string lastName)
{
FirstName = firstName;
LastName = lastName;
}
}
}
25 changes: 25 additions & 0 deletions Library/Book.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
namespace LibraryProgram
{
class Book
{
public string Title { get; set; }

public Author Author { get; set; }

public int NumberOfPages { get; set; }

public Genre Genre { get; set; }
}

enum Genre
{
Mystery,
Fantasy,
Nonficiton,
ComicBook,
ScienceFiction,
Fiction

}
}
53 changes: 53 additions & 0 deletions Library/Library.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace LibraryProgram
{
public class Library<T> : IEnumerable<T>
{
private int count = 0;
private T[] books = new T[5];
public int Count => count;

public void Add(T book)
{
if (count >= books.Length)
{
Array.Resize(ref books, books.Length * 2);
}
books[count] = book;
count++;
}

public bool Remove(int index)
{
if (index < 0)
return false;

for (int i = index; i < count; i++)
books[i] = books[i + 1];

books[count] = default;
count--;
return true;
}



public IEnumerator<T> GetEnumerator()
{
for (int i = 0; i < count; i++)
{
yield return books[i];
}
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}
File renamed without changes.
Loading

0 comments on commit 65f04d1

Please sign in to comment.