forked from ehilst515/Lab08Library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ehilst515#2 from ehilst515/Lab08-Library
library interface working
- Loading branch information
Showing
8 changed files
with
442 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.