C# Machine Coding Round Problems (With OOP-Based Solutions)

⭐ Introduction

A Machine Coding Round tests how well you can:

✔ Design clean classes
✔ Apply OOPS principles
✔ Write working, readable code quickly
✔ Think in terms of low-level design (LLD)
✔ Handle real-world requirements

This round is not about algorithms — it is about design + implementation.


🎯 What Interviewers Expect

In 60–90 minutes, you should:

  • Design classes
  • Define relationships
  • Use interfaces where needed
  • Avoid hard-coding
  • Write extensible code
  • Handle edge cases
  • Follow OOPS + SOLID

🧩 Problem 1: Design a Parking Lot System

🔹 Requirements

  • Park cars
  • Remove cars
  • Show available slots
  • Support different vehicle types

🔑 OOPS Concepts

✔ Abstraction
✔ Inheritance
✔ Polymorphism
✔ Composition

🧑‍💻 Core Design:

abstract class Vehicle
{
    public string Number { get; set; }
}

class Car : Vehicle { }

class ParkingSlot
{
    public bool IsFree { get; set; } = true;
    public Vehicle Vehicle { get; set; }
}

class ParkingLot
{
    private List<ParkingSlot> slots;

    public ParkingLot(int size)
    {
        slots = new List<ParkingSlot>(size);
        for (int i = 0; i < size; i++)
            slots.Add(new ParkingSlot());
    }

    public void Park(Vehicle v)
    {
        var slot = slots.FirstOrDefault(s => s.IsFree);
        if (slot == null)
        {
            Console.WriteLine("Parking full");
            return;
        }

        slot.Vehicle = v;
        slot.IsFree = false;
        Console.WriteLine("Vehicle parked");
    }
}


🧩 Problem 2: Library Management System

🔹 Requirements

  • Add books
  • Issue books
  • Return books

🔑 OOPS Concepts

✔ Encapsulation
✔ HAS-A relationship
✔ Controller class

🧑‍💻 Core Design:

class Book
{
    public string Title { get; set; }
    public bool IsIssued { get; set; }
}

class Library
{
    private List<Book> books = new();

    public void AddBook(Book book) => books.Add(book);

    public void IssueBook(string title)
    {
        var book = books.FirstOrDefault(b => b.Title == title && !b.IsIssued);
        if (book != null)
        {
            book.IsIssued = true;
            Console.WriteLine("Book issued");
        }
    }
}


🧩 Problem 3: Online Shopping Cart

🔹 Requirements

  • Add products
  • Remove products
  • Calculate total price
  • Support discount later

🔑 OOPS Concepts

✔ Composition
✔ Open/Closed Principle

🧑‍💻 Core Design:

class Product
{
    public string Name { get; set; }
    public double Price { get; set; }
}

class Cart
{
    private List<Product> products = new();

    public void AddProduct(Product p) => products.Add(p);

    public double Total()
    {
        return products.Sum(p => p.Price);
    }
}


🧩 Problem 4: Payment Processing System

🔹 Requirements

  • Support UPI, Card, Wallet
  • Easy to extend

🔑 OOPS Concepts

✔ Interface
✔ Polymorphism
✔ Open/Closed Principle

🧑‍💻 Core Design:

interface IPayment
{
    void Pay(double amount);
}

class UpiPayment : IPayment
{
    public void Pay(double amount)
    {
        Console.WriteLine($"Paid {amount} via UPI");
    }
}


🧩 Problem 5: Notification System

🔹 Requirements

  • Email, SMS, Push notifications
  • Add new type without modifying existing code

🔑 OOPS Concepts

✔ Strategy Pattern
✔ Interface-based design

interface INotification
{
    void Send(string message);
}

class EmailNotification : INotification
{
    public void Send(string message)
    {
        Console.WriteLine("Email: " + message);
    }
}


🧩 Problem 6: Employee Salary Calculator

🔹 Requirements

  • Different salary logic for roles

🔑 OOPS Concepts

✔ Inheritance
✔ Method Overriding

abstract class Employee
{
    public abstract double CalculateSalary();
}

class Developer : Employee
{
    public override double CalculateSalary() => 60000;
}


🧩 Problem 7: Logger System (Singleton Style)

🔹 Requirements

  • Single instance
  • Global access

🔑 OOPS Concepts

✔ Static members
✔ Controlled object creation

class Logger
{
    private static Logger instance;
    private Logger() { }

    public static Logger GetInstance()
    {
        return instance ??= new Logger();
    }
}


🧩 Problem 8: Design a File System

🔹 Requirements

  • Files & folders
  • Hierarchical structure

🔑 OOPS Concepts

✔ Composite Pattern
✔ Polymorphism

abstract class FileSystemItem
{
    public string Name { get; set; }
    public abstract void Display();
}


🧠 How to Approach Machine Coding Round

Step-by-Step Strategy:

1️⃣ Clarify requirements
2️⃣ Identify entities
3️⃣ Decide relationships (IS-A / HAS-A)
4️⃣ Use interfaces for behavior
5️⃣ Keep classes small
6️⃣ Write working code first
7️⃣ Add extensibility


❌ Common Mistakes

❌ Writing everything in Main()
❌ Using public fields
❌ No interfaces
❌ Over-engineering
❌ Ignoring extensibility


✅ What Gets You Selected

✔ Clean design
✔ Correct OOPS usage
✔ Readable code
✔ Correct naming
✔ Handling edge cases
✔ Explaining trade-offs


🎯 Interview Tip (VERY IMPORTANT)

While coding, speak aloud:

“I am using interface here to allow extension.”
“I am using composition to avoid inheritance.”
“This follows Open/Closed principle.”

Interviewers value thinking more than syntax.


🎉 Conclusion

C# machine coding rounds test your real engineering skills, not just theory.

If you can solve these problems confidently:
✔ You understand OOPS deeply
✔ You can design scalable systems
✔ You are interview-ready

Leave a Comment