From c64981703ad44b66aeff2fcea9c8f06f53fb1184 Mon Sep 17 00:00:00 2001 From: Azadi Date: Fri, 12 Dec 2025 17:07:22 +0330 Subject: [PATCH] =?UTF-8?q?=D8=A7=D8=B6=D8=A7=D9=81=D9=87=20=DA=A9=D8=B1?= =?UTF-8?q?=D8=AF=D9=86=20=D9=87=D8=B1=20=DA=86=D9=87=D8=A7=D8=B1=20=D9=BE?= =?UTF-8?q?=D8=B1=D9=88=DA=98=D9=87=20=D8=A8=D9=87=20=D8=AA=D8=B1=D8=AA?= =?UTF-8?q?=DB=8C=D8=A8=20=D8=B3=D9=88=D8=A7=D9=84=20=D8=AF=D8=A7=D8=AF?= =?UTF-8?q?=D9=87=20=D8=B4=D8=AF=D9=87.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConsoleApp1/ConsoleApp1.csproj | 10 +++ ConsoleApp1/Program.cs | 14 ++++ ConsoleApp1/Student.cs | 30 ++++++++ ConsoleApp2/BankAccount.cs | 75 +++++++++++++++++++ ConsoleApp2/ConsoleApp2.csproj | 10 +++ ConsoleApp2/Program.cs | 12 +++ ConsoleApp3/ConsoleApp3.csproj | 10 +++ ConsoleApp3/Program.cs | 22 ++++++ ConsoleApp3/Statistics.cs | 18 +++++ ConsoleApp4/ArrayAnalyzer.cs | 32 ++++++++ ConsoleApp4/ConsoleApp4.csproj | 10 +++ ConsoleApp4/Program.cs | 32 ++++++++ ...Work2-InitialFirstConsoleAppPart2-main.sln | 43 +++++++++++ 13 files changed, 318 insertions(+) create mode 100644 ConsoleApp1/ConsoleApp1.csproj create mode 100644 ConsoleApp1/Program.cs create mode 100644 ConsoleApp1/Student.cs create mode 100644 ConsoleApp2/BankAccount.cs create mode 100644 ConsoleApp2/ConsoleApp2.csproj create mode 100644 ConsoleApp2/Program.cs create mode 100644 ConsoleApp3/ConsoleApp3.csproj create mode 100644 ConsoleApp3/Program.cs create mode 100644 ConsoleApp3/Statistics.cs create mode 100644 ConsoleApp4/ArrayAnalyzer.cs create mode 100644 ConsoleApp4/ConsoleApp4.csproj create mode 100644 ConsoleApp4/Program.cs create mode 100644 HomeWork2-InitialFirstConsoleAppPart2-main.sln diff --git a/ConsoleApp1/ConsoleApp1.csproj b/ConsoleApp1/ConsoleApp1.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/ConsoleApp1/ConsoleApp1.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/ConsoleApp1/Program.cs b/ConsoleApp1/Program.cs new file mode 100644 index 0000000..19b8fc3 --- /dev/null +++ b/ConsoleApp1/Program.cs @@ -0,0 +1,14 @@ +// See https://aka.ms/new-console-template for more information +using ConsoleApp1; + + + +/*********/ +Console.WriteLine("Hi!"); +Console.Write("Please Enter your Name:"); +var nameinput = Console.ReadLine(); +Console.Write("Please Enter your Age:"); +int ageinput = Convert.ToInt32(Console.ReadLine()); +Student student = new Student(nameinput,ageinput); +Console.WriteLine(student.Introduce()); +/*********/ \ No newline at end of file diff --git a/ConsoleApp1/Student.cs b/ConsoleApp1/Student.cs new file mode 100644 index 0000000..539c16f --- /dev/null +++ b/ConsoleApp1/Student.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + internal class Student + { + public Student() + { } + + public Student(string name, int age) + { + Age = age; + Name = name; + } + + private string name; + private int age; + public int Age { get { return age; } set { age = value; } } + public string Name { get { return name; } set { name = value; } } + + public string Introduce() + { + return $"Hello, my name is {Name} and I am {Age} years old."; + } + } +} diff --git a/ConsoleApp2/BankAccount.cs b/ConsoleApp2/BankAccount.cs new file mode 100644 index 0000000..fa4e306 --- /dev/null +++ b/ConsoleApp2/BankAccount.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp2 +{ + internal class BankAccount + { + public BankAccount() { } + + public BankAccount(int init) + { + Balance = init; + } + + private int balance = 0; + + public int Balance + { + get { return balance; } + set + { + balance = value; + } + } + + public bool Deposit(double myvalue) + { + bool result = false; + + if (myvalue < 0) + { + return false; + } + + if (balance + myvalue > int.MaxValue) + { + return false; + } + + balance += (int)myvalue; + return true; + } + + public bool WithDraw(double amount) + { + if (amount <= 0) + { + return false; + } + + if (balance < 0) + { + return false; + } + + if (balance < amount) + { + return false; + } + + balance -= (int)amount; + return true; + + } + + public int GetBalance() + { + return balance; + } + + } +} diff --git a/ConsoleApp2/ConsoleApp2.csproj b/ConsoleApp2/ConsoleApp2.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/ConsoleApp2/ConsoleApp2.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/ConsoleApp2/Program.cs b/ConsoleApp2/Program.cs new file mode 100644 index 0000000..889979f --- /dev/null +++ b/ConsoleApp2/Program.cs @@ -0,0 +1,12 @@ +// See https://aka.ms/new-console-template for more information + +/*********/ +using ConsoleApp2; +Console.WriteLine("Enter init Balance value:"); +int val = Convert.ToInt32(Console.ReadLine()); + +BankAccount ba = new BankAccount(val); +Console.WriteLine("============="); +Console.WriteLine($"your Bank amount is : {ba.GetBalance()}"); +Console.WriteLine("============="); +/*********/ \ No newline at end of file diff --git a/ConsoleApp3/ConsoleApp3.csproj b/ConsoleApp3/ConsoleApp3.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/ConsoleApp3/ConsoleApp3.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/ConsoleApp3/Program.cs b/ConsoleApp3/Program.cs new file mode 100644 index 0000000..3262187 --- /dev/null +++ b/ConsoleApp3/Program.cs @@ -0,0 +1,22 @@ +// See https://aka.ms/new-console-template for more information + +using ConsoleApp3; + +int a ; +Console.Write("Enter a:"); +a = Convert.ToInt32(Console.ReadLine()); +int b; +Console.Write("Enter b:"); +b = Convert.ToInt32(Console.ReadLine()); +int c; +Console.WriteLine($"value a is: {a}"); +Console.WriteLine($"value b is: {b}"); +Statistics stats = new Statistics(); +stats.AnalyzeNumbers(a, ref b, out c); +Console.WriteLine($"After Claculate"); +Console.WriteLine($"value a was: {a}"); +Console.WriteLine($"value b is: {b}"); +Console.WriteLine($"value c is: {c}"); + + + diff --git a/ConsoleApp3/Statistics.cs b/ConsoleApp3/Statistics.cs new file mode 100644 index 0000000..ab5bcc7 --- /dev/null +++ b/ConsoleApp3/Statistics.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp3 +{ + internal class Statistics + { + public string AnalyzeNumbers(int a, ref int b, out int c) + { + c = a + b; + b = b * 2; + return a.ToString(); + } + } +} diff --git a/ConsoleApp4/ArrayAnalyzer.cs b/ConsoleApp4/ArrayAnalyzer.cs new file mode 100644 index 0000000..f934c48 --- /dev/null +++ b/ConsoleApp4/ArrayAnalyzer.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp4 +{ + public class ArrayAnalyzer + { + public void AnalyzeArray(int[] array, ref int max, out double average) + { + if (array == null || array.Length == 0) + { + max = 0; + average = 0.0; + return; + } + max = array[0]; + int sum = 0; + for (int i = 0; i < array.Length; i++) + { + if (array[i] > max) + { + max = array[i]; + } + sum += array[i]; + } + average = (double)sum / array.Length; + } + } +} diff --git a/ConsoleApp4/ConsoleApp4.csproj b/ConsoleApp4/ConsoleApp4.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/ConsoleApp4/ConsoleApp4.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/ConsoleApp4/Program.cs b/ConsoleApp4/Program.cs new file mode 100644 index 0000000..8321c5f --- /dev/null +++ b/ConsoleApp4/Program.cs @@ -0,0 +1,32 @@ +using ConsoleApp4; + +ArrayAnalyzer analyzer = new ArrayAnalyzer(); +Console.Write("اندازه آرایه را وارد کنید: "); +int size = Convert.ToInt32(Console.ReadLine()); +int[] numbers = new int[size]; +if (size == 0) +{ + Console.WriteLine("آرایه خالی است."); +} +else +{ + Console.Write($"اندازه آرایه شما: {size}"); +} +for (int i = 0; i < size; i++) +{ + Console.Write($"عنصر {i + 1} را وارد کنید: "); + while (!int.TryParse(Console.ReadLine(), out numbers[i])) + { + Console.Write($"لطفاً یک عدد صحیح برای عنصر {i + 1} وارد کنید: "); + } +} + +int maxValue = 0; +double averageValue; +analyzer.AnalyzeArray(numbers, ref maxValue, out averageValue); +Console.WriteLine("نتایج :"); + +Console.WriteLine($"بزرگترین عدد: {maxValue}"); +Console.WriteLine($"میانگین اعداد: {averageValue}"); + +Console.ReadLine(); \ No newline at end of file diff --git a/HomeWork2-InitialFirstConsoleAppPart2-main.sln b/HomeWork2-InitialFirstConsoleAppPart2-main.sln new file mode 100644 index 0000000..21470ab --- /dev/null +++ b/HomeWork2-InitialFirstConsoleAppPart2-main.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.36602.27 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{8BA57592-F765-45F5-A6BC-971EF8F7593F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp2", "ConsoleApp2\ConsoleApp2.csproj", "{D02EB025-25FB-4E83-8F18-9EA61F4BC339}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp3", "ConsoleApp3\ConsoleApp3.csproj", "{6093F595-2EA3-4A9D-9C92-97FBA486F1F3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp4", "ConsoleApp4\ConsoleApp4.csproj", "{B36027EB-08E2-4C78-B81D-4BE29305C696}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8BA57592-F765-45F5-A6BC-971EF8F7593F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8BA57592-F765-45F5-A6BC-971EF8F7593F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8BA57592-F765-45F5-A6BC-971EF8F7593F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8BA57592-F765-45F5-A6BC-971EF8F7593F}.Release|Any CPU.Build.0 = Release|Any CPU + {D02EB025-25FB-4E83-8F18-9EA61F4BC339}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D02EB025-25FB-4E83-8F18-9EA61F4BC339}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D02EB025-25FB-4E83-8F18-9EA61F4BC339}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D02EB025-25FB-4E83-8F18-9EA61F4BC339}.Release|Any CPU.Build.0 = Release|Any CPU + {6093F595-2EA3-4A9D-9C92-97FBA486F1F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6093F595-2EA3-4A9D-9C92-97FBA486F1F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6093F595-2EA3-4A9D-9C92-97FBA486F1F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6093F595-2EA3-4A9D-9C92-97FBA486F1F3}.Release|Any CPU.Build.0 = Release|Any CPU + {B36027EB-08E2-4C78-B81D-4BE29305C696}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B36027EB-08E2-4C78-B81D-4BE29305C696}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B36027EB-08E2-4C78-B81D-4BE29305C696}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B36027EB-08E2-4C78-B81D-4BE29305C696}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F82C14CC-D0B5-4CA1-A440-D183D571016D} + EndGlobalSection +EndGlobal