diff --git a/CPP2/CPP2.cpp b/CPP2/CPP2.cpp index a067523..9b42991 100644 --- a/CPP2/CPP2.cpp +++ b/CPP2/CPP2.cpp @@ -96,8 +96,8 @@ int PrintList(LinkList L) int main() { LinkList bss1, bss2, bss3; - int A[] = { 958,599,9485,95626,989923 }; - int B[] = { 3155,78,9623,7265,98630,983266 }; + int A[] = { 253,342,465,586,678 }; + int B[] = { 787,895,996,1023,2096,3323 }; CreatList(bss1, 5, A); CreatList(bss2, 6, B); printf("第一个链表: \n"); diff --git a/CPP2/作业二.cpp b/CPP2/作业二.cpp new file mode 100644 index 0000000..9b42991 --- /dev/null +++ b/CPP2/作业二.cpp @@ -0,0 +1,112 @@ +#include +#include + +#define ElemType int +#define OK 1 +#define OVERFLOW 0 + +// 链表定义 +typedef struct LNode{ + ElemType data; + struct LNode* next; +} LNode, * LinkList; + +// 初始化链表 +int InitList(LinkList &L){ + L = (LNode*)malloc(sizeof(LNode)); + if (!L) return OVERFLOW; + L->next = NULL; + return OK; +} + +// 生成新节点 +LNode* MakeNode(ElemType e) { + LNode* bss; + bss = (LNode*)malloc(sizeof(LNode)); + if (bss != NULL) { + bss->data = e; + bss->next = NULL; + } + return bss; +} + +// 插入节点 +int Insert(LinkList &L, LNode* s){ + if (!L) return OVERFLOW; + s->next = L->next; + L->next = s; + return OK; +} + +// 创建链表 +int CreatList(LinkList& L, int n, ElemType A[]){ + LNode* p, * q; + int i; + if (!InitList(L)) return OVERFLOW; + p = L; + for (i = 0; i < n; i++) + { + q = MakeNode(A[i]); + Insert(p, q); + p = q; + } + return OK; +} + +// 合并链表 +int MergeList(LinkList La, LinkList Lb, LinkList& Lc) +{ + LNode* pa, * pb, * pc; + pa = La->next; + pb = Lb->next; + if (!InitList(Lc)) return OVERFLOW; + pc = Lc; + while (pa && pb) + { + if (pa->data <= pb->data) + { + pc->next = pa; + pc = pa; + pa = pa->next; + } + else + { + pc->next = pb; + pc = pb; + pb = pb->next; + } + } + pc->next = pa ? pa : pb; + return OK; +} + +// 打印链表 +int PrintList(LinkList L) +{ + LNode* p = L->next; + while (p) + { + printf("%d ", p->data); + p = p->next; + } + printf("\n"); + return OK; +} + +int main() +{ + LinkList bss1, bss2, bss3; + int A[] = { 253,342,465,586,678 }; + int B[] = { 787,895,996,1023,2096,3323 }; + CreatList(bss1, 5, A); + CreatList(bss2, 6, B); + printf("第一个链表: \n"); + PrintList(bss1); + printf("第二个链表: \n"); + PrintList(bss2); + MergeList(bss1, bss2, bss3); + printf("合并后的链表: \n"); + PrintList(bss3); + + return 0; +} \ No newline at end of file diff --git a/CPP4/CPP4.cpp b/CPP4/CPP4.cpp new file mode 100644 index 0000000..b6e2116 --- /dev/null +++ b/CPP4/CPP4.cpp @@ -0,0 +1,93 @@ +#include +#include + +#define Type int + +// 定义哈希表 +typedef struct HashTable { + Type* table; + int Length; +} HashTable; + +// 哈希函数 +int HashFunction(HashTable &HashTable,int key) { + return key % HashTable.Length; +} + +// 初始化哈希表 +void initHashTable(HashTable &HashTable) { + HashTable.table = (Type*)malloc(HashTable.Length * sizeof(Type)); + for (int i = 0; i < HashTable.Length; i++) { + HashTable.table[i] = -1; + } +} + +// 线性探测再散列 +void insert1(HashTable &HashTable, int key) { + int index = HashFunction(HashTable, key); + while (HashTable.table[index] != -1) { + index = (index + 1) % HashTable.Length; + } + HashTable.table[index] = key; +} + +// 二次探测再散列 +void insert2(HashTable& HashTable, int key) { + int index = HashFunction(HashTable, key); + if (HashTable.table[index] == -1) { + HashTable.table[index] = key; + return; + } + + for (int i = 1; i < HashTable.Length; ++i) { + int sign = (i & 1) ? 1 : -1; + int sq = (i + 1) / 2; + int d = sign * sq * sq; + int position = (index + d) % HashTable.Length; + if (position < 0) position += HashTable.Length; + if (HashTable.table[position] == -1) { + HashTable.table[position] = key; + return; + } + } +} + +// 打印哈希表 +void printHashTable(HashTable &HashTable) { + for (int i = 0; i < HashTable.Length; i++) { + if (HashTable.table[i] == -1) { + printf("空 "); + } + else { + printf("%d ", HashTable.table[i]); + } + } +} + +int main() +{ + HashTable HashTable1, HashTable2; + HashTable1.Length = 11; + HashTable2.Length = 11; + initHashTable(HashTable1); + initHashTable(HashTable2); + int keys[] = { 19, 1, 23, 14, 55, 68, 11, 82, 36 }; + int n = sizeof(keys) / sizeof(keys[0]); + + for (int i = 0; i < n; i++) { + insert1(HashTable1, keys[i]); + } + + for (int i = 0; i < n; i++) { + insert2(HashTable2, keys[i]); + } + + // 打印哈希表 + printf("线性探测再散列结果:\n"); + printHashTable(HashTable1); + printf("\n"); + printf("二次探测再散列结果:\n"); + printHashTable(HashTable2); + + return 0; +} diff --git a/CPP4/CPP4.sln b/CPP4/CPP4.sln new file mode 100644 index 0000000..ffac50b --- /dev/null +++ b/CPP4/CPP4.sln @@ -0,0 +1,31 @@ + +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("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CPP4", "CPP4.vcxproj", "{3E1258FB-07C6-41FC-AA54-03A983857CDE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3E1258FB-07C6-41FC-AA54-03A983857CDE}.Debug|x64.ActiveCfg = Debug|x64 + {3E1258FB-07C6-41FC-AA54-03A983857CDE}.Debug|x64.Build.0 = Debug|x64 + {3E1258FB-07C6-41FC-AA54-03A983857CDE}.Debug|x86.ActiveCfg = Debug|Win32 + {3E1258FB-07C6-41FC-AA54-03A983857CDE}.Debug|x86.Build.0 = Debug|Win32 + {3E1258FB-07C6-41FC-AA54-03A983857CDE}.Release|x64.ActiveCfg = Release|x64 + {3E1258FB-07C6-41FC-AA54-03A983857CDE}.Release|x64.Build.0 = Release|x64 + {3E1258FB-07C6-41FC-AA54-03A983857CDE}.Release|x86.ActiveCfg = Release|Win32 + {3E1258FB-07C6-41FC-AA54-03A983857CDE}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {10EDD9F8-190F-4596-ADAB-DBE0E5F185FC} + EndGlobalSection +EndGlobal diff --git a/CPP4/CPP4.vcxproj b/CPP4/CPP4.vcxproj new file mode 100644 index 0000000..af9a238 --- /dev/null +++ b/CPP4/CPP4.vcxproj @@ -0,0 +1,131 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {3e1258fb-07c6-41fc-aa54-03a983857cde} + CPP4 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + + + \ No newline at end of file diff --git a/CPP4/CPP4.vcxproj.filters b/CPP4/CPP4.vcxproj.filters new file mode 100644 index 0000000..8e12296 --- /dev/null +++ b/CPP4/CPP4.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/cs3/C_Sharp_3_5/Program.cs b/cs3/C_Sharp_3_5/Program.cs index bbe5201..e41ba08 100644 --- a/cs3/C_Sharp_3_5/Program.cs +++ b/cs3/C_Sharp_3_5/Program.cs @@ -1,4 +1,5 @@ -namespace C_Sharp_3_5 +using System; +namespace C_Sharp_3_5 { internal class Program { diff --git a/cs4/CPP5/CPP5.cpp b/cs4/CPP5/CPP5.cpp new file mode 100644 index 0000000..39f946e --- /dev/null +++ b/cs4/CPP5/CPP5.cpp @@ -0,0 +1,20 @@ +// CPP5.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 +// + +#include + +int main() +{ + std::cout << "Hello World!\n"; +} + +// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 +// 调试程序: F5 或调试 >“开始调试”菜单 + +// 入门使用技巧: +// 1. 使用解决方案资源管理器窗口添加/管理文件 +// 2. 使用团队资源管理器窗口连接到源代码管理 +// 3. 使用输出窗口查看生成输出和其他消息 +// 4. 使用错误列表窗口查看错误 +// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 +// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件 diff --git a/cs4/CPP5/CPP5.sln b/cs4/CPP5/CPP5.sln new file mode 100644 index 0000000..c4c26bc --- /dev/null +++ b/cs4/CPP5/CPP5.sln @@ -0,0 +1,31 @@ + +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("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CPP5", "CPP5.vcxproj", "{D3103D25-0742-45FE-A6F9-07DDB00036AA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D3103D25-0742-45FE-A6F9-07DDB00036AA}.Debug|x64.ActiveCfg = Debug|x64 + {D3103D25-0742-45FE-A6F9-07DDB00036AA}.Debug|x64.Build.0 = Debug|x64 + {D3103D25-0742-45FE-A6F9-07DDB00036AA}.Debug|x86.ActiveCfg = Debug|Win32 + {D3103D25-0742-45FE-A6F9-07DDB00036AA}.Debug|x86.Build.0 = Debug|Win32 + {D3103D25-0742-45FE-A6F9-07DDB00036AA}.Release|x64.ActiveCfg = Release|x64 + {D3103D25-0742-45FE-A6F9-07DDB00036AA}.Release|x64.Build.0 = Release|x64 + {D3103D25-0742-45FE-A6F9-07DDB00036AA}.Release|x86.ActiveCfg = Release|Win32 + {D3103D25-0742-45FE-A6F9-07DDB00036AA}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2A3D6FB2-8224-4762-B411-D3B887B40C40} + EndGlobalSection +EndGlobal diff --git a/cs4/CPP5/CPP5.vcxproj b/cs4/CPP5/CPP5.vcxproj new file mode 100644 index 0000000..1598c1a --- /dev/null +++ b/cs4/CPP5/CPP5.vcxproj @@ -0,0 +1,131 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {d3103d25-0742-45fe-a6f9-07ddb00036aa} + CPP5 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + + + \ No newline at end of file diff --git a/cs4/CPP5/CPP5.vcxproj.filters b/cs4/CPP5/CPP5.vcxproj.filters new file mode 100644 index 0000000..02a5ac6 --- /dev/null +++ b/cs4/CPP5/CPP5.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/cs4/CS4_1/CS4_1.csproj b/cs4/CS4_1/CS4_1.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/cs4/CS4_1/CS4_1.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/cs4/CS4_1/CS4_1.sln b/cs4/CS4_1/CS4_1.sln new file mode 100644 index 0000000..f6fd1cd --- /dev/null +++ b/cs4/CS4_1/CS4_1.sln @@ -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}") = "CS4_1", "CS4_1.csproj", "{176395D4-286A-4CFB-8CA6-ABB8FC8E2144}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {176395D4-286A-4CFB-8CA6-ABB8FC8E2144}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {176395D4-286A-4CFB-8CA6-ABB8FC8E2144}.Debug|Any CPU.Build.0 = Debug|Any CPU + {176395D4-286A-4CFB-8CA6-ABB8FC8E2144}.Release|Any CPU.ActiveCfg = Release|Any CPU + {176395D4-286A-4CFB-8CA6-ABB8FC8E2144}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9BE27323-1DB1-4334-A15D-B183D58010C3} + EndGlobalSection +EndGlobal diff --git a/cs4/CS4_1/Program.cs b/cs4/CS4_1/Program.cs new file mode 100644 index 0000000..ca3705d --- /dev/null +++ b/cs4/CS4_1/Program.cs @@ -0,0 +1,52 @@ +using System; +namespace CS4_1 +{ + public class Program + { + static void Main(string[] args) + { + int min, max, sum = 0, average; + int[] A = new int[10]; + Random rand = new Random(); + for (int i = 0; i < A.Length; i++) + { + A[i] = rand.Next(1, 101); + } + Console.WriteLine("原始数组为:"); + foreach (var item in A) + { + Console.Write("{0,4}", item); + } + min = max = A[0]; + for (int i = 0; i < A.Length; i++) + { + if (A[i] < min) min = A[i]; + if (A[i] > max) max = A[i]; + sum += A[i]; + } + average = sum / A.Length; + Console.WriteLine("\n数组的最小值为:{0}", min); + Console.WriteLine("数组的最大值为:{0}", max); + Console.WriteLine("数组的平均值为:{0}", average); + // 元素降序排序 + int n = A.Length; + for (int i = 0; i < n - 1; i++) + { + for (int j = 0; j < n - 1 - i; j++) + { + if (A[j] < A[j + 1]) + { + int temp = A[j]; + A[j] = A[j + 1]; + A[j + 1] = temp; + } + } + } + Console.WriteLine("数组元素降序排序后为:"); + foreach (var item in A) + { + Console.Write("{0,4}", item); + } + } + } +} diff --git a/cs4/CS4_2/CS4_2.csproj b/cs4/CS4_2/CS4_2.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/cs4/CS4_2/CS4_2.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/cs4/CS4_2/CS4_2.sln b/cs4/CS4_2/CS4_2.sln new file mode 100644 index 0000000..3d12b36 --- /dev/null +++ b/cs4/CS4_2/CS4_2.sln @@ -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}") = "CS4_2", "CS4_2.csproj", "{D2BA0541-32E9-4C7D-AE89-9E7B7B49969C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D2BA0541-32E9-4C7D-AE89-9E7B7B49969C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D2BA0541-32E9-4C7D-AE89-9E7B7B49969C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D2BA0541-32E9-4C7D-AE89-9E7B7B49969C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D2BA0541-32E9-4C7D-AE89-9E7B7B49969C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9CC792AC-CC4E-4F02-B199-034BABCE42D4} + EndGlobalSection +EndGlobal diff --git a/cs4/CS4_2/Program.cs b/cs4/CS4_2/Program.cs new file mode 100644 index 0000000..7978023 --- /dev/null +++ b/cs4/CS4_2/Program.cs @@ -0,0 +1,36 @@ +using System; +namespace CS4_2 +{ + public class Program + { + static void Main(string[] args) + { + int[] score = { 80, 90, 67, 89, 78, 85, 45, 65, 77, 95 }; + // 统计分数段 + int a = 0, b = 0, c = 0, d = 0; + for (int i = 0; i < score.Length; i++) + { + if (score[i] >= 90) + { + a++; + } + else if (score[i] >= 80) + { + b++; + } + else if (score[i] >= 60) + { + c++; + } + else + { + d++; + } + } + Console.WriteLine("90分及以上人数:" + a); + Console.WriteLine("80-89分人数:" + b); + Console.WriteLine("60-79分人数:" + c); + Console.WriteLine("60分以下人数:" + d); + } + } +} diff --git a/cs4/CS4_3/CS4_3.csproj b/cs4/CS4_3/CS4_3.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/cs4/CS4_3/CS4_3.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/cs4/CS4_3/CS4_3.sln b/cs4/CS4_3/CS4_3.sln new file mode 100644 index 0000000..97a132e --- /dev/null +++ b/cs4/CS4_3/CS4_3.sln @@ -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}") = "CS4_3", "CS4_3.csproj", "{FCCD1D8D-1B13-483D-837B-FBB41A496BCD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FCCD1D8D-1B13-483D-837B-FBB41A496BCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FCCD1D8D-1B13-483D-837B-FBB41A496BCD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FCCD1D8D-1B13-483D-837B-FBB41A496BCD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FCCD1D8D-1B13-483D-837B-FBB41A496BCD}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FCF021EF-C7A9-414B-ACEB-91F4122C1216} + EndGlobalSection +EndGlobal diff --git a/cs4/CS4_3/Program.cs b/cs4/CS4_3/Program.cs new file mode 100644 index 0000000..041bfe4 --- /dev/null +++ b/cs4/CS4_3/Program.cs @@ -0,0 +1,40 @@ +using System; +namespace CS4_3 +{ + public class Program + { + static void Main(string[] args) + { + int[] A = new int[10]; + Random rand = new Random(); + for (int i = 0; i < A.Length; i++) + { + A[i] = rand.Next(1, 999); + } + Console.WriteLine("原数组:"); + for (int i = 0; i < A.Length; i++) + { + Console.Write(A[i] + " "); + } + // 冒泡排序 + int temp; + for (int i = 0; i < A.Length - 1; i++) + { + for (int j = 0; j < A.Length - 1 - i; j++) + { + if (A[j] > A[j + 1]) + { + temp = A[j]; + A[j] = A[j + 1]; + A[j + 1] = temp; + } + } + } + Console.WriteLine("\n排序后数组:"); + for (int i = 0; i < A.Length; i++) + { + Console.Write(A[i] + " "); + } + } + } +} diff --git a/cs5/5_1/5_1.csproj b/cs5/5_1/5_1.csproj new file mode 100644 index 0000000..1610dc4 --- /dev/null +++ b/cs5/5_1/5_1.csproj @@ -0,0 +1,11 @@ + + + + Exe + net8.0 + _5_1 + enable + enable + + + diff --git a/cs5/5_1/5_1.sln b/cs5/5_1/5_1.sln new file mode 100644 index 0000000..612ea60 --- /dev/null +++ b/cs5/5_1/5_1.sln @@ -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_1", "5_1.csproj", "{82D15861-AC86-4C64-8477-2687C2846721}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {82D15861-AC86-4C64-8477-2687C2846721}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82D15861-AC86-4C64-8477-2687C2846721}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82D15861-AC86-4C64-8477-2687C2846721}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82D15861-AC86-4C64-8477-2687C2846721}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {65D009ED-CB3D-43A5-98F3-0FD1FFFBF78E} + EndGlobalSection +EndGlobal diff --git a/cs5/5_1/Program.cs b/cs5/5_1/Program.cs new file mode 100644 index 0000000..28aba92 --- /dev/null +++ b/cs5/5_1/Program.cs @@ -0,0 +1,34 @@ +using System; +namespace _5_1 +{ + class MyMath + { + public const double PI = 3.1415926; + public static double perimeter(double r) + { + double p = 2 * PI * r; + return p; + } + public static double area(double r) + { + double a = PI * r * r; + return a; + } + public static double volume(double r) + { + double v = (4.0 / 3) * PI * r * r * r; + return v; + } + public class Program + { + static void Main(string[] args) + { + Console.WriteLine("请输入半径:\n"); + double r = Convert.ToDouble(Console.ReadLine()); + Console.WriteLine("圆的周长为:{0}\n", MyMath.perimeter(r)); + Console.WriteLine("圆的面积为:{0}\n", MyMath.area(r)); + Console.WriteLine("球的体积为:{0}\n", MyMath.volume(r)); + } + } + } +} diff --git a/cs5/5_2/5_2.csproj b/cs5/5_2/5_2.csproj new file mode 100644 index 0000000..10d5ee0 --- /dev/null +++ b/cs5/5_2/5_2.csproj @@ -0,0 +1,11 @@ + + + + Exe + net8.0 + _5_2 + enable + enable + + + diff --git a/cs5/5_2/5_2.sln b/cs5/5_2/5_2.sln new file mode 100644 index 0000000..8412bdf --- /dev/null +++ b/cs5/5_2/5_2.sln @@ -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_2", "5_2.csproj", "{24FDF2F6-69DD-4F6F-A667-8EE25A8F65D8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {24FDF2F6-69DD-4F6F-A667-8EE25A8F65D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {24FDF2F6-69DD-4F6F-A667-8EE25A8F65D8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {24FDF2F6-69DD-4F6F-A667-8EE25A8F65D8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {24FDF2F6-69DD-4F6F-A667-8EE25A8F65D8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0F9A79BA-C7F0-4698-B7CC-C8889EA6B5FE} + EndGlobalSection +EndGlobal diff --git a/cs5/5_2/Program.cs b/cs5/5_2/Program.cs new file mode 100644 index 0000000..fc5d474 --- /dev/null +++ b/cs5/5_2/Program.cs @@ -0,0 +1,28 @@ +using System; +namespace _5_2 +{ + public class TemperatureCelius + { + private double degree; + public TemperatureCelius(double degree) + { + this.degree = degree; + } + public double toFahrenheit() + { + return (degree * 9 / 5) + 32; + } + } + public class Program + { + static void Main(string[] args) + { + Console.WriteLine("请输入摄氏温度:\n"); + double celsius = Convert.ToDouble(Console.ReadLine()); + TemperatureCelius tempCelius = new TemperatureCelius(celsius); + double fahrenheit = tempCelius.toFahrenheit(); + Console.WriteLine("对应的华氏温度是:{0}\n", fahrenheit); + Console.ReadKey(); + } + } +} diff --git a/cs5/5_3/5_3.csproj b/cs5/5_3/5_3.csproj new file mode 100644 index 0000000..6d55719 --- /dev/null +++ b/cs5/5_3/5_3.csproj @@ -0,0 +1,11 @@ + + + + Exe + net8.0 + _5_3 + enable + enable + + + diff --git a/cs5/5_3/5_3.sln b/cs5/5_3/5_3.sln new file mode 100644 index 0000000..c7b2f63 --- /dev/null +++ b/cs5/5_3/5_3.sln @@ -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_3", "5_3.csproj", "{32BEEF67-DFCA-4551-90C6-9DC2246E4FF9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {32BEEF67-DFCA-4551-90C6-9DC2246E4FF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {32BEEF67-DFCA-4551-90C6-9DC2246E4FF9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {32BEEF67-DFCA-4551-90C6-9DC2246E4FF9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {32BEEF67-DFCA-4551-90C6-9DC2246E4FF9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9CE2E177-5663-42F5-9B3C-BD782E54D2D4} + EndGlobalSection +EndGlobal diff --git a/cs5/5_3/Program.cs b/cs5/5_3/Program.cs new file mode 100644 index 0000000..be6fe3e --- /dev/null +++ b/cs5/5_3/Program.cs @@ -0,0 +1,10 @@ +namespace _5_3 +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +}