Skip to content

Commit

Permalink
Add Operator Overloading program
Browse files Browse the repository at this point in the history
  • Loading branch information
cvpfus committed Sep 19, 2023
1 parent c459b49 commit 73f7240
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
7 changes: 7 additions & 0 deletions FormulatrixBootcamp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinkedList", "W3 D2\LinkedL
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "List", "W3 D2\List\List.csproj", "{5F05DFBC-6EF9-4F4F-8B6D-4E1490171568}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OperatorOverloading", "W2 D3\OperatorOverloading\OperatorOverloading.csproj", "{3108ABBF-67CB-4E65-80A7-6C1F2F3E30B7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -313,11 +315,16 @@ Global
{5F05DFBC-6EF9-4F4F-8B6D-4E1490171568}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F05DFBC-6EF9-4F4F-8B6D-4E1490171568}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F05DFBC-6EF9-4F4F-8B6D-4E1490171568}.Release|Any CPU.Build.0 = Release|Any CPU
{3108ABBF-67CB-4E65-80A7-6C1F2F3E30B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3108ABBF-67CB-4E65-80A7-6C1F2F3E30B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3108ABBF-67CB-4E65-80A7-6C1F2F3E30B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3108ABBF-67CB-4E65-80A7-6C1F2F3E30B7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3108ABBF-67CB-4E65-80A7-6C1F2F3E30B7} = {82AE1F6C-47FF-4067-89F3-87EBEFDA524C}
{A718291C-B218-4283-837F-43CF360568AC} = {A718291C-B218-4283-837F-43CF360568AC}
{77D0C1C7-A06B-4E05-9458-873709BD4BFD} = {44C682DF-E1C9-4394-813D-0CB989CD9262}
{AA5CB577-831E-40F5-AABD-AFF7C56F8A57} = {44C682DF-E1C9-4394-813D-0CB989CD9262}
Expand Down
59 changes: 59 additions & 0 deletions W2 D3/OperatorOverloading/DragonBall.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
namespace OperatorOverloading;

public class DragonBall
{
private string? _characterName;
private int _characterHeight;
private int _characterWeight;
private int _characterPower;

public DragonBall(string characterName, int characterHeight, int characterWeight, int characterPower)
{
_characterName = characterName;
_characterHeight = characterHeight;
_characterWeight = characterWeight;
_characterPower = characterPower;
}

public static DragonBall operator +(DragonBall characterA, DragonBall characterB)
{
Random random = new Random();
string newName = characterA.CharacterName + characterB.CharacterName;
int newHeight = random.Next(Math.Min(characterA.CharacterHeight, characterB.CharacterHeight), Math.Max(characterA.CharacterHeight, characterB.CharacterHeight));
int newWeight = random.Next(Math.Min(characterA.CharacterWeight, characterB.CharacterWeight), Math.Max(characterA.CharacterWeight, characterB.CharacterWeight));
int newPower = random.Next(Math.Min(characterA.CharacterPower, characterB.CharacterPower), Math.Max(characterA.CharacterPower, characterB.CharacterPower));
return new DragonBall(newName, newHeight, newWeight, newPower);
}

public static void PrintCharacterInfo(DragonBall character)
{
Console.WriteLine();
Console.WriteLine($"Character's name: {character.CharacterName}");
Console.WriteLine($"Character's height: {character.CharacterHeight}");
Console.WriteLine($"Character's weight: {character.CharacterWeight}");
Console.WriteLine($"Character's power: {character.CharacterPower}");
}

public string? CharacterName
{
get => _characterName;
}

public int CharacterHeight
{
get => _characterHeight;
set => _characterHeight = value;
}

public int CharacterWeight
{
get => _characterWeight;
set => _characterWeight = value;
}

public int CharacterPower
{
get => _characterPower;
set => _characterPower = value;
}
}
10 changes: 10 additions & 0 deletions W2 D3/OperatorOverloading/OperatorOverloading.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
17 changes: 17 additions & 0 deletions W2 D3/OperatorOverloading/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using OperatorOverloading;

public class Program
{
static void Main()
{
DragonBall goku = new("Goku", 175, 62, 999);
DragonBall vegeta = new("Vegeta", 164, 56, 899);

DragonBall fusionedCharacters = goku + vegeta;

DragonBall.PrintCharacterInfo(goku);
DragonBall.PrintCharacterInfo(vegeta);
DragonBall.PrintCharacterInfo(fusionedCharacters);

}
}

0 comments on commit 73f7240

Please sign in to comment.