Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions week-1/day-2/exercise-1/Circle/Circle.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Circle
public class Circle
{
internal class Circle
public double Radius { get; set; }

public Circle(double radius)
{
Radius = radius;
}

public double GetArea()
{
// Implement the Circle class here
return Math.PI * Math.Pow(Radius, 2);
}
public double GetCircumference()
{
return 2 * Math.PI * Radius;
}

}
12 changes: 9 additions & 3 deletions week-1/day-2/exercise-1/Circle/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
namespace Circle
namespace DAY2
{
internal class Program
{
static void Main(string[] args)
{
// Create a Circle object and display its area and circumference
double radius = 10;
Circle circle = new Circle(radius);
double area = circle.GetArea();
double circumference = circle.GetCircumference();
Console.WriteLine($"Area:{area}");
Console.WriteLine($"circumference:{circumference}");
Console.WriteLine("Hello, World!");
}
}
}
}
66 changes: 63 additions & 3 deletions week-1/day-2/exercise-3/AnimalExercise/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,70 @@
namespace AnimalExercise
{
internal class Program
internal abstract class Animal
{
String Name;
int Age;

protected abstract void MakeSound();

static void Main(string[] args)
{
// Create a list of Animal objects, add Dog and Cat instances, and call their methods
Console.WriteLine("animals");
List<Animal> animals = new List<Animal>();

Dog dog = new Dog { Name = "abc", Age = 4 };
Dog dog2 = new Dog { Name = "kkk", Age = 5 };
Cat cat = new Cat { Name = "ppp", Age = 6 };
Cat cat2 = new Cat { Name = "ppp", Age = 6 };

animals.Add(dog);
animals.Add(dog2);
animals.Add(cat);
animals.Add(cat2);

foreach (var animal in animals)
{
Console.WriteLine("Name:" + animal.Name + " Age:" + animal.Age);
animal.MakeSound();

if (animal is Imovable movable)
{
movable.move();

}
}


}
}
}

class Dog : Animal, Imovable
{
protected override void MakeSound()
{
Console.WriteLine("woof");
}
public void move()
{
Console.WriteLine("dog is moving");
}

}
class Cat : Animal, Imovable
{
protected override void MakeSound()
{
Console.WriteLine("Meow");
}
public void move()
{
Console.WriteLine("cat is moving");
}

}
interface Imovable
{
public void move();
}
}

111 changes: 107 additions & 4 deletions week-1/day-2/exercise-4/VehicleManagementSystem/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,113 @@
namespace VehicleManagementSystem
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAY2
{
internal class Program
internal class Vehicle
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
{
Car car = new Car();
Truck truck = new Truck();

car.Drive();
truck.Drive();
}
{
VehicleLogger logger = VehicleLogger.Instance;

logger.Log("Car ignition turned on.");
logger.Log("Truck started.");

}
{
VehicleFactory carFactory = new CarFactory();
VehicleFactory truckFactory = new TruckFactory();

carFactory.DoSomethingWithVehicle();
truckFactory.DoSomethingWithVehicle();

}


}



}
}
}
public interface Ivehicle
{
void Drive();


}
public class Car : Ivehicle
{
public void Drive()
{
Console.WriteLine("Car is moving.");
}
}
public class Truck : Ivehicle
{
public void Drive()
{
Console.WriteLine("Truck is moving.");
}
}
public class VehicleLogger
{
private static VehicleLogger instance;
private VehicleLogger()
{

}
public static VehicleLogger Instance
{
get
{
if (instance == null)
{
instance = new VehicleLogger();
}
return instance;
}
}
public void Log(string message)
{
Console.WriteLine($"Logging: {message}");
}
}
public abstract class VehicleFactory
{
public abstract Ivehicle CreateVehicle();

public void DoSomethingWithVehicle()
{
Ivehicle vehicle = CreateVehicle();
Console.WriteLine("Do something with vehicle ");
vehicle.Drive();
}


}
public class CarFactory : VehicleFactory
{
public override Ivehicle CreateVehicle()
{
return new Car();
}
}

public class TruckFactory : VehicleFactory
{
public override Ivehicle CreateVehicle()
{
return new Truck();
}
}
27 changes: 16 additions & 11 deletions week-1/day-3/exercise-1/FactorialApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
namespace FactorialApp
namespace program.cs
{
public class Program
internal class Program
{
public static void Main()
static void Main(string[] args)
{
Console.Write("Enter a number: ");
int number = int.Parse(Console.ReadLine());
Console.WriteLine(" Factorial");
Console.WriteLine(" Enter a number here");
Int32 num = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Number is " + num);

long factorial = CalculateFactorial(number);
Int32 result = num;
Int32 count = 1;

Console.WriteLine($"The factorial of {number} is: {factorial}");
}
while (count < num)
{
result = result * count;
Console.WriteLine(result);
count++;
}
Console.WriteLine("Factorial is " + result);

public static long CalculateFactorial(int number)
{
throw new NotImplementedException();
}
}
}
2 changes: 1 addition & 1 deletion week-1/day-3/exercise-2/ShortesPathAlgorithm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public int[] DijkstraShortestPath(int source)
visited[i] = false;
}

distances[source] = int.MinValue;
distances[source] = 0;

for (int count = 0; count < vertices - 1; count++)
{
Expand Down
37 changes: 33 additions & 4 deletions week-1/day-4/exercise-1/StackApp/ICustomStack.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
namespace StackApp
{
internal interface ICustomStack<T>
class Stack<T>
{
void Push(T item);
T Pop();
bool IsEmpty();
private List<T> list = new List<T>();

public void Push(T item)
{
list.Add(item);
}

public T Pop()
{
if (list.Count == 0)
throw new Exception("Stack is Empty");
T item = list[list.Count - 1];
list.RemoveAt(list.Count - 1);
return item;
}
public bool IsEmpty()
{
return list.Count == 0;
}
}


}
class Person
{
public string Name { get; set; }
public int Age { get; set; }

public Person(string name, int age)
{
Name = name;
Age = age;
}
}
34 changes: 26 additions & 8 deletions week-1/day-4/exercise-1/StackApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
namespace StackApp
using System;

namespace StackApp
{
internal class Program
{
static void Main(string[] args)
{
//ICustomStack<int> intStack = new CustomStack<int>();
//intStack.Push(1);
//intStack.Push(2);
//intStack.Push(3);
//Console.WriteLine(intStack.Pop()); // Output: 3
//Console.WriteLine(intStack.Pop()); // Output: 2
//Console.WriteLine(intStack.IsEmpty()); // Output: False
Stack<int> intstack = new Stack<int>();
intstack.Push(1);
intstack.Push(2);
intstack.Push(3);
intstack.Push(4);
intstack.Push(5);
Console.WriteLine(intstack.Pop()); //out=5

Stack<string> stringstack = new Stack<string>();
stringstack.Push("Namaste");
stringstack.Push("Kem");
stringstack.Push("Cho");
stringstack.Push("Maja");
stringstack.Push("ma");
Console.WriteLine(stringstack.Pop()); //out=ma

Stack<Person> PersonStack = new Stack<Person>();
PersonStack.Push(new Person("Divyansh", 22));
PersonStack.Push(new Person("Arpit", 23));
PersonStack.Push(new Person("Mradul", 22));
PersonStack.Push(new Person("Devyan", 23));
PersonStack.Push(new Person("Pawan", 23));
Console.WriteLine(PersonStack.Pop().Name); //out=pawan
}
}
}
Loading