This repository contains solutions to C# homework assignments, covering key object-oriented programming (OOP) concepts and related topics. The project is structured into multiple sections, each focusing on a specific aspect of C# programming.
The repository is organized into the following folders, corresponding to different topics:
-
Introduction to OOP. Classes and Objects
- Task 2: Create a
Rectangle
class with fields forside1
andside2
. Implement methods to calculate the area and perimeter, along with properties to access these values. The program takes user input and displays the results. - Task 3: Create a
Book
class and associated classesTitle
,Author
, andContent
. Implement aShow()
method to display book details in different colors. - Task 4: Implement classes
Point
andFigure
to work with polygons. TheFigure
class calculates side lengths and the perimeter based on a given number of points. - Task 6: Develop an
Address
class with fields for postal address details. Implement properties for data access and create an instance to display the stored information.
- Task 2: Create a
-
Classes and Objects. Class Diagrams
- Task 2: Create a
Converter
class with fields representing exchange rates for three currencies. Implement methods for currency conversion from and to UAH. - Task 3: Create an
Employee
class with fields for name and surname. Implement a method to calculate salary and tax based on position and experience. Display employee details, salary, and tax on the screen. - Task 4: Implement an
Invoice
class with fields for account number, customer, and provider. These should be immutable after initialization. Include private fields forarticle
andquantity
. Implement methods to calculate the total order cost with and without VAT. - Task 6: Develop a
User
class with fields for user profile information (login, name, surname, and registration date). Ensure that the registration date is immutable after initialization. Implement a method to display user details on the screen.
- Task 2: Create a
-
Inheritance and Polymorphism
- Task 2: Implement a
ClassRoom
class that represents a study group. Create aPupil
class with methodsStudy()
,Read()
,Write()
, andRelax()
. DeriveExcellentPupil
,GoodPupil
, andBadPupil
classes, overriding their methods accordingly. TheClassRoom
constructor should accept up to fourPupil
instances. - Task 3: Develop a
Vehicle
class with properties for coordinates and transport parameters (price, speed, year of manufacture). DerivePlane
,Car
, andShip
classes, adding additional fields such as passenger capacity and home port forShip
, and altitude and passenger count forPlane
. - Task 4: Create a
DocumentWorker
class with methodsOpenDocument()
,EditDocument()
, andSaveDocument()
. Override these methods in aProDocumentWorker
subclass to add extended editing capabilities and further extendExpertDocumentWorker
to support saving in additional formats. The program should instantiate different versions based on the user’s license key. - Task 5: Implement a
Printer
class with a methodPrint(string value)
that prints text. Derive subclasses that override this method to print in different formats or colors.
- Task 2: Implement a
-
Abstraction. Abstract Classes and Interfaces
- Task 2: Implement an
AbstractHandler
class with methodsOpen()
,Create()
,Change()
, andSave()
. DeriveXMLHandler
,TXTHandler
, andDOCHandler
classes that override these methods for different document formats. The program should handle document processing based on its format. - Task 3: Create two interfaces
IPlayable
andIRecodable
, each containing three methods:Play()
,Pause()
, andStop()
forIPlayable
;Record()
,Pause()
, andStop()
forIRecodable
. Develop aPlayer
class implementing both interfaces and execute both playback and recording functionalities in the program.
- Task 2: Implement an
-
Arrays and Indexers
- Task 2: Implement a program that creates an array of
N
elements, fills it with random integers, and displays the maximum, minimum, sum, and average values of the elements, as well as all odd numbers. - Task 3: Develop a
MyMatrix
class that allows defining and resizing a matrix dynamically. Implement methods to retrieve the original and transposed matrices. - Task 4: Create an
Article
class representing a product, including fields for its name, store, and price. Implement aStore
class that holds an array ofArticle
objects and provides search and retrieval functionality based on product names or indices.
- Task 2: Implement a program that creates an array of
-
Static and Nested Classes
- Task 2: Implement a static
FindAndReplaceManager
class with aFindNext(string str)
method to search for a string within a book. - Task 3: Extend the book example by adding a nested
Notes
class insideBook
, allowing users to store notes. - Task 4: Create an extension method for arrays that sorts elements in ascending order, implemented in
ExtensionArray
. - Task 6: Develop a static
Calculator
class containing methods for basic arithmetic operations.
- Task 2: Implement a static
-
Structures and Their Types
This section covers working with structures and comparing them with classes.- Task 2: Implement a
Train
structure containing fields for the destination, train number, and departure time. Create an array ofTrain
structures, sort them by train number, and allow the user to search for a train by number. - Task 3: Create a
MyClass
class and aMyStruct
structure, both containing astring change
field. Implement methods in theProgram
class to modify the field and demonstrate the difference between reference types (classes) and value types (structures). - Task 5: Develop a
Notebook
structure (located inProgram.cs
) with fields for model, manufacturer, and price. Implement a constructor to initialize these fields and a method to display the structure’s contents.
- Task 2: Implement a
-
Enumeration
- Task 2: Implement a static
Printer
class with aPrint(string text, int color)
method to display text in a user-selected color. - Task 3: Develop an
Accountant
class that determines if an employee is eligible for a bonus based on anenum
representing job positions and their required work hours. - Task 5: Create a program (located in
Program.cs
) that accepts a user's birthdate and calculates the number of days until their next birthday.
- Task 2: Implement a static
-
Delegates
- Task 2: Implement four lambda operators to perform arithmetic operations (
Add
,Sub
,Mul
,Div
). Ensure the division operator handles division by zero. - Task 3: Create an anonymous method that takes an array of delegates and returns the average of the results of delegate calls.
- Task 5: Develop an anonymous method that accepts three integer arguments and returns their average value.
- Task 2: Implement four lambda operators to perform arithmetic operations (
-
Generic
- Task 2: Implement a generic
MyList
class that mimics the behavior ofList<T>
. The class should include methods for adding elements, an indexer for retrieving elements by index, and a read-only property for getting the total count. - Task 3: Develop a generic
MagicBag
class that provides a magical way of assigning gifts based on the receiver's type. Each entity can receive only one gift per day. - Task 4: Extend the
MyList
class by implementing an extension method that converts its elements into an array.
- Generic Constraints
- Task 2: Implement a generic
CarCollection
class that allows managing a collection of cars. The class should support adding cars with a name and year, retrieving cars by index, and getting the total count. Additionally, implement a method to clear all cars from the collection. - Task 3: Develop a generic
Dictionary
class that mimics the behavior ofDictionary<TKey, TValue>
fromSystem.Collections.Generic
. Implement methods for adding key-value pairs, retrieving values by indexer, and getting the total count of pairs. - Task 7: The implementation for this task is located in
Program.cs
. Create a generic class that includes a static factory methodT FactoryMethod()
, which generates instances of the type specified as the generic parameterT
. Ensure constraints are applied appropriately.
- Threads
- Task 1: Implemented in
Thread
, this task creates a console application that simulates falling character chains of random lengths. The first character is white, the second is light green, and the rest are dark green. Each step, all characters change their values, and once a chain reaches the bottom, it disappears, and a new chain is generated at the top. - Task 2: Implemented in
Thread2
, this task extends the previous one by allowing two character chains to exist in a single column simultaneously. - Task 4: Implemented in
Thread
, this task involves writing a recursive method where each new call is executed in a separate thread.
- Collections
- Task 2: Implement a
MyList
collection that mimics the behavior ofList<T>
. The class should include methods for adding elements, an indexer for retrieving elements by index, and a read-only property for getting the total count. Implement enumeration support to allow iterating over the collection using loops. - Task 3: Develop a
MyDictionary
collection that functions similarly toDictionary<TKey, TValue>
. The class should support adding key-value pairs, retrieving values by indexer, and iterating through the collection in a loop. - Task 4: Extend
IEnumerable
with a generic extension methodpublic static T[] GetArray(this IEnumerable list)
, which converts an enumerable collection into an array. Apply this extension toMyList
and display the resulting array.
- Exceptions
- Task 2: Implement a
Worker
structure containing fields for the employee's name, position, and the year they started working. Ensure input validation and sort the records alphabetically. If the input year format is incorrect, throw an exception. The program should display employees whose work experience exceeds a user-defined value. - Task 3: Create a
Price
structure that stores information about a product, including its name, store, and price. The program should sort records alphabetically by store name and allow users to search for a store. If the store is not found, throw an exception. - Task 5: Develop a
Calculator
class with methods for addition, subtraction, multiplication, and division. The division method should check for division by zero and throw an exception if invalid input is detected. The program should allow users to input numbers and choose an operation, handling errors gracefully.
- Operator Overload
- Task 2: Implemented in
Block
, this task defines a class with four side length fields. Override theEquals
method for object comparison and theToString
method to return a string representation of the block. - Task 3: Implemented in
House
, this task creates a class with two fields and properties. ImplementClone()
for shallow copying andDeepClone()
for deep copying. - Task 4: Implemented in
DateMath
, this task defines a class storing date information (day, month, year) and overloads operators to calculate the difference between two dates (in days) and to increase a date by a given number of days. - Task 6: Implemented in
Point
, this task defines a structure for a 3D point and overloads the+
operator to allow the addition of two points.
- Anonymous and Dynamic Types. LINQ
- Task 2: Implemented in
Program.cs
, this task involves creating a simple collection of cars (brand, model, year, color) and a second collection containing model, buyer's name, and phone number. Using a basic LINQ query, display buyer information along with the full details of the purchased car. - Task 3: Implemented in
Program.cs
, this task uses anonymous and dynamic types to create an English-Russian dictionary with ten words and display its contents. - Task 5: Implemented in
Program.cs
, this task defines aCalculator
class with methods that accept and returndynamic
types, demonstrating the flexibility ofdynamic
in calculations.
- Namespace. Preprocessor Directives
- Task 1: Integrated
MyDictionary
from Lesson 14 into a separate namespace and configured its usage similarly toDictionary<TKey, TValue>
via dependencies in the solution explorer. - Task 2: Created separate namespaces for different classes and demonstrated that a public method in a class is accessible not only from the current assembly but also from a derived class in an external assembly.
- Task 4: Defined a custom namespace
MyNamespace
containing a classMyClass
and successfully linked it to another program.
-
[C# Basic] Course Project. Task 9: HR Department at the University
Path:TasksOfSCharp/HR Department at the University (Course Project)/
Create a console application “HR Department at the University” that functions as a personnel directory for a university.
The university consists of faculties, departments, and student groups.
Each department has a head, and each group has a group leader (head student) and a profile department.A person in the system can simultaneously have multiple roles:
- A student (with information about parents and group),
- A teacher (with department and position),
- A parent (of one or more students).
-
Load and save the directory data from/to disk.
-
Full data editing capabilities.
-
View and filter information using different criteria:
- List of all students with sorting by full name, faculty, group, and profile department.
- List of students without parent information.
- List of all teachers with sorting options.
- List of all department heads.
- List of groups without head students and departments without heads.
- Search for all student children of a specific parent.
- List of teachers who have student children.
Program.cs
– Entry point of the application, handles console interface and logic.Interfaces.cs
– Contains interfacesIStudent
,ITeacher
, andIParent
to define role behaviors.Person.cs
– Implementation of thePerson
class and the relationships between children and parents.University.cs
– Core logic and structure of the university (faculties, departments, groups, people).
Each section contains one or more C# files that demonstrate concepts through practical examples.
- .NET SDK (latest stable version)
- C# compiler
- IDE of your choice (Visual Studio, JetBrains Rider, or VS Code with C# extension)
- Clone the repository:
git clone https://github.com/Weretik/TasksOfSCharp.git
- Open the project in your preferred IDE.
- Navigate to the specific topic folder.
- Run the
Program.cs
file within that topic to execute the examples.
This project is open-source and available under the MIT License.