111
This commit is contained in:
11
cs5/5_5/5_5.csproj
Normal file
11
cs5/5_5/5_5.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>_5_5</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
25
cs5/5_5/5_5.sln
Normal file
25
cs5/5_5/5_5.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.14.36616.10 d17.14
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "5_5", "5_5.csproj", "{C2EFCC00-2BDF-4E39-BBF1-FB54B8CB2708}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C2EFCC00-2BDF-4E39-BBF1-FB54B8CB2708}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C2EFCC00-2BDF-4E39-BBF1-FB54B8CB2708}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C2EFCC00-2BDF-4E39-BBF1-FB54B8CB2708}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C2EFCC00-2BDF-4E39-BBF1-FB54B8CB2708}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {987BE462-C992-48BE-98EB-41564DDA8179}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
46
cs5/5_5/Program.cs
Normal file
46
cs5/5_5/Program.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
namespace _5_5
|
||||
{
|
||||
public struct Complex
|
||||
{
|
||||
public int real;
|
||||
public int imag;
|
||||
public Complex(int r, int i)
|
||||
{
|
||||
this.real = r;
|
||||
this.imag = i;
|
||||
}
|
||||
public static Complex operator +(Complex c1, Complex c2)
|
||||
{
|
||||
return new Complex(c1.real + c2.real, c1.imag + c2.imag);
|
||||
}
|
||||
public static Complex operator -(Complex c1, Complex c2)
|
||||
{
|
||||
return new Complex(c1.real - c2.real, c1.imag - c2.imag);
|
||||
}
|
||||
public static Complex operator *(Complex c1, Complex c2)
|
||||
{
|
||||
return new Complex(c1.real * c2.real - c1.imag * c2.imag, c1.real * c2.imag + c1.imag * c2.real);
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return (string.Format("{0}+{1}i", this.real, this.imag));
|
||||
}
|
||||
}
|
||||
public class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Complex c1 = new Complex(2, 3);
|
||||
Complex c2 = new Complex(4, 5);
|
||||
Complex sum = c1 + c2;
|
||||
Complex diff = c1 - c2;
|
||||
Complex prod = c1 * c2;
|
||||
Console.WriteLine("第一个复数" + c1);
|
||||
Console.WriteLine("第二个复数" + c2);
|
||||
Console.WriteLine("复数的和" + sum);
|
||||
Console.WriteLine("复数的差" + diff);
|
||||
Console.WriteLine("复数的积" + prod);
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user