From f23e00641da17fbe8f2ea22ab55d9c327e431e2b Mon Sep 17 00:00:00 2001 From: Joe Walter Date: Sat, 29 May 2021 15:08:32 -0400 Subject: [PATCH 1/2] Port banner to C# --- 06 Banner/csharp/banner.cs | 251 +++++++++++++++++++++++++++++++++ 06 Banner/csharp/banner.csproj | 8 ++ 06 Banner/csharp/banner.sln | 25 ++++ 3 files changed, 284 insertions(+) create mode 100644 06 Banner/csharp/banner.cs create mode 100644 06 Banner/csharp/banner.csproj create mode 100644 06 Banner/csharp/banner.sln diff --git a/06 Banner/csharp/banner.cs b/06 Banner/csharp/banner.cs new file mode 100644 index 00000000..6b0ff142 --- /dev/null +++ b/06 Banner/csharp/banner.cs @@ -0,0 +1,251 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace banner +{ + class Banner + { + private int Horizontal { get; set; } + private int Vertical { get; set; } + private bool Centered { get; set; } + private string Character { get; set; } + private string Statement { get; set; } + + // This provides a bit-ended representation of each symbol + // that can be output. Each symbol is defined by 7 parts - + // where each part is an integer value that, when converted to + // the binary representation, shows which section is filled in + // with values and which are spaces. i.e., the 'filled in' + // parts represent the actual symbol on the paper. + Dictionary letters = new Dictionary() + { + {' ', new int[] { 0, 0, 0, 0, 0, 0, 0 } }, + {'A', new int[] {505, 37, 35, 34, 35, 37, 505} }, + {'B', new int[] {512, 274, 274, 274, 274, 274, 239} }, + {'C', new int[] {125, 131, 258, 258, 258, 131, 69} }, + {'D', new int[] {512, 258, 258, 258, 258, 131, 125} }, + {'E', new int[] {512, 274, 274, 274, 274, 258, 258} }, + {'F', new int[] {512, 18, 18, 18, 18, 2, 2} }, + {'G', new int[] {125, 131, 258, 258, 290, 163, 101} }, + {'H', new int[] {512, 17, 17, 17, 17, 17, 512} }, + {'I', new int[] {258, 258, 258, 512, 258, 258, 258} }, + {'J', new int[] {65, 129, 257, 257, 257, 129, 128} }, + {'K', new int[] {512, 17, 17, 41, 69, 131, 258} }, + {'L', new int[] {512, 257, 257, 257, 257, 257, 257} }, + {'M', new int[] {512, 7, 13, 25, 13, 7, 512} }, + {'N', new int[] {512, 7, 9, 17, 33, 193, 512} }, + {'O', new int[] {125, 131, 258, 258, 258, 131, 125} }, + {'P', new int[] {512, 18, 18, 18, 18, 18, 15} }, + {'Q', new int[] {125, 131, 258, 258, 322, 131, 381} }, + {'R', new int[] {512, 18, 18, 50, 82, 146, 271} }, + {'S', new int[] {69, 139, 274, 274, 274, 163, 69} }, + {'T', new int[] {2, 2, 2, 512, 2, 2, 2} }, + {'U', new int[] {128, 129, 257, 257, 257, 129, 128} }, + {'V', new int[] {64, 65, 129, 257, 129, 65, 64} }, + {'W', new int[] {256, 257, 129, 65, 129, 257, 256} }, + {'X', new int[] {388, 69, 41, 17, 41, 69, 388} }, + {'Y', new int[] {8, 9, 17, 481, 17, 9, 8} }, + {'Z', new int[] {386, 322, 290, 274, 266, 262, 260} }, + {'0', new int[] {57, 69, 131, 258, 131, 69, 57} }, + {'1', new int[] {0, 0, 261, 259, 512, 257, 257} }, + {'2', new int[] {261, 387, 322, 290, 274, 267, 261} }, + {'3', new int[] {66, 130, 258, 274, 266, 150, 100} }, + {'4', new int[] {33, 49, 41, 37, 35, 512, 33} }, + {'5', new int[] {160, 274, 274, 274, 274, 274, 226} }, + {'6', new int[] {194, 291, 293, 297, 305, 289, 193} }, + {'7', new int[] {258, 130, 66, 34, 18, 10, 8} }, + {'8', new int[] {69, 171, 274, 274, 274, 171, 69} }, + {'9', new int[] {263, 138, 74, 42, 26, 10, 7} }, + {'?', new int[] {5, 3, 2, 354, 18, 11, 5} }, + {'*', new int[] {69, 41, 17, 512, 17, 41, 69} }, + {'=', new int[] {41, 41, 41, 41, 41, 41, 41} }, + {'!', new int[] {1, 1, 1, 384, 1, 1, 1} }, + {'.', new int[] {1, 1, 129, 449, 129, 1, 1} } + }; + + + /// + /// This displays the provided text on the screen and then waits for the user + /// to enter a integer value greater than 0. + /// + /// Text to display on the screen asking for the input + /// The integer value entered by the user + private int GetNumber(string DisplayText) + { + Console.Write(DisplayText); + string TempStr = Console.ReadLine(); + + Int32.TryParse(TempStr, out int TempInt); + + if (TempInt <= 0) + { + throw new ArgumentException($"{DisplayText} must be greater than zero"); + } + + return TempInt; + } + + /// + /// This displays the provided text on the screen and then waits for the user + /// to enter a Y or N. It cheats by just looking for a 'y' and returning that + /// as true. Anything else that the user enters is returned as false. + /// + /// Text to display on the screen asking for the input + /// Returns true or false + private bool GetBool(string DisplayText) + { + Console.Write(DisplayText); + return (Console.ReadLine().StartsWith("y", StringComparison.InvariantCultureIgnoreCase)); + } + + /// + /// This displays the provided text on the screen and then waits for the user + /// to enter an arbitrary string. That string is then returned 'as-is'. + /// + /// Text to display on the screen asking for the input + /// The string entered by the user. + private string GetString(string DisplayText) + { + Console.Write(DisplayText); + return (Console.ReadLine().ToUpper()); + } + + /// + /// This queries the user for the various inputs needed by the program. + /// + private void GetInput() + { + Horizontal = GetNumber("Horizontal "); + Vertical = GetNumber("Vertical "); + Centered = GetBool("Centered "); + Character = GetString("Character (type 'ALL' if you want character being printed) "); + Statement = GetString("Statement "); + // We don't care about what the user enters here. This is just telling them + // to set the page in the printer. + _ = GetString("Set page "); + } + + /// + /// This prints out a single character of the banner - adding + /// a few blanks lines as a spacer between characters. + /// + private void PrintChar(char ch) + { + // In the trivial case (a space character), just print out the spaces + if (ch.Equals(' ')) + { + Console.WriteLine(new string('\n', 7 * Horizontal)); + return; + } + + // If a specific character to be printed was provided by the user, + // then user that as our ouput character - otherwise take the + // current character + char outCh = Character == "ALL" ? ch : Character[0]; + int[] letter = new int[7]; + try + { + letters[outCh].CopyTo(letter, 0); + } + catch (KeyNotFoundException) + { + throw new KeyNotFoundException($"The provided letter {outCh} was not found in the letters list"); + } + + // New int array declarations default to zeros + // numSections decides how many 'sections' need to be printed + // for a given line of each character + int[] numSections = new int[7]; + // fillInSection decides whether each 'section' of the + // character gets filled in with the character or with blanks + int[] fillInSection = new int[9]; + + // This iterates through each of the parts that make up + // each letter. Each part represents 1 * Horizontal lines + // of actual output. + for (int idx = 0; idx < 7; idx++) + { + // This uses the value in each part to decide which + // sections are empty spaces in the letter or filled in + // spaces. For each section marked with 1 in fillInSection, + // that will correspond to 1 * Vertical characters actually + // being output. + for (int exp = 8; exp >= 0; exp--) + { + if (Math.Pow(2, exp) < letter[idx]) + { + fillInSection[8 - exp] = 1; + letter[idx] -= (int)Math.Pow(2, exp); + if (letter[idx] == 1) + { + // Once we've exhausted all of the sections + // defined in this part of the letter, then + // we marked that number and break out of this + // for loop. + numSections[idx] = 8 - exp; + break; + } + } + } + + // Now that we know which sections of this part of the letter + // are filled in or spaces, we can actually create the string + // to print out. + string lineStr = ""; + + if (Centered) + lineStr += new string(' ', (int)(63 - 4.5 * Vertical) * 1 / 1 + 1); + + for (int idx2 = 0; idx2 <= numSections[idx]; idx2++) + { + lineStr = lineStr + new string(fillInSection[idx2] == 0 ? ' ' : outCh, Vertical); + } + + // Then we print that string out 1 * Horizontal number of times + for (int lineidx = 1; lineidx <= Horizontal; lineidx++) + { + Console.WriteLine(lineStr); + } + } + + // Finally, add a little spacer after each character for readability. + Console.WriteLine(new string('\n', 2 * Horizontal - 1)); + } + + /// + /// This prints the entire banner based in the parameters + /// the user provided. + /// + private void PrintBanner() + { + // Iterate through each character in the statement + foreach (char ch in Statement) + { + PrintChar(ch); + } + + // In the original version, it would print an additional 75 blank + // lines in order to feed the printer paper...don't really need this + // since we're not actually printing. + Console.WriteLine(new string('\n', 75)); + } + + /// + /// Main entry point into the banner class and handles the main loop. + /// + public void Play() + { + GetInput(); + PrintBanner(); + } + } + + class Program + { + static void Main(string[] args) + { + new Banner().Play(); + } + } +} diff --git a/06 Banner/csharp/banner.csproj b/06 Banner/csharp/banner.csproj new file mode 100644 index 00000000..c73e0d16 --- /dev/null +++ b/06 Banner/csharp/banner.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/06 Banner/csharp/banner.sln b/06 Banner/csharp/banner.sln new file mode 100644 index 00000000..34f63984 --- /dev/null +++ b/06 Banner/csharp/banner.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31321.278 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "banner", "banner.csproj", "{9E24FA30-F2AC-4BF3-ADFB-92D3F796561C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9E24FA30-F2AC-4BF3-ADFB-92D3F796561C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9E24FA30-F2AC-4BF3-ADFB-92D3F796561C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9E24FA30-F2AC-4BF3-ADFB-92D3F796561C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9E24FA30-F2AC-4BF3-ADFB-92D3F796561C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FF2A268C-9C4A-457F-8733-2E8931E07A1D} + EndGlobalSection +EndGlobal From f66f929ac26b63c7ba6725dee8f8258e078cc5d5 Mon Sep 17 00:00:00 2001 From: Joe Walter Date: Sat, 29 May 2021 15:48:10 -0400 Subject: [PATCH 2/2] Port banner to VB --- 06 Banner/csharp/.vs/banner/v16/.suo | Bin 0 -> 13824 bytes 06 Banner/csharp/banner.cs | 18 +-- 06 Banner/vbnet/.vs/banner/v16/.suo | Bin 0 -> 22016 bytes 06 Banner/vbnet/banner.sln | 25 +++ 06 Banner/vbnet/banner.vb | 226 +++++++++++++++++++++++++++ 06 Banner/vbnet/banner.vbproj | 9 ++ 6 files changed, 269 insertions(+), 9 deletions(-) create mode 100644 06 Banner/csharp/.vs/banner/v16/.suo create mode 100644 06 Banner/vbnet/.vs/banner/v16/.suo create mode 100644 06 Banner/vbnet/banner.sln create mode 100644 06 Banner/vbnet/banner.vb create mode 100644 06 Banner/vbnet/banner.vbproj diff --git a/06 Banner/csharp/.vs/banner/v16/.suo b/06 Banner/csharp/.vs/banner/v16/.suo new file mode 100644 index 0000000000000000000000000000000000000000..07fa45168df2bae30999fdced3c33a53d49c60a0 GIT binary patch literal 13824 zcmeHN%X1^e8E-AGU9#a3U?GHuLmXIO$Bd-0EP2CXJ%K759OPXdr7CJHjb$&kq#DV} zlJ%x?NafFTl*BpWl7;-47o8LPW|rag+FF?}WHD)E`6pnErp45I3XEzHj#S_Sk(B0L`QF zf5d@TL=(S`m=Q(MK<$gSxs}G{l(?n0=eLb{YU%yIy#DFxKVv_^xIf&j2Co2PQ(P1; z0{c2zMR94&Ed94nK_bKK?!PPzEntfESD#R?UiIu}SgI zV6s0^aZp|sJHWCfHnDy}J%qV{9$yU`dL@49;Vl5tF?3+)Mh@*i2LF$v{%?2zLHi{7 zsn0rnz@V0^XCB!;yL_%e;A!D$PsLIHwJ$fq0%&{2HB#bjm@h@R4;~tg^z`81V zuqD<|UjhY;|GJ>3IyU;F>>i6THq!P|PCDlD9PTq_V|fuPFC+4N8o0&SUC0D&+n{nL zz|S)kX&5vn+84$jwt?f?NA_Ru^7p4cvj0D9`%n9_22WeZkAANNFVKJ;F2f^jOOLn} zH6MNdVgC+ff1~)9LB%%w0rOC=2DCKcm4mPIbinSjoyM! zZc6<0LSagR2ZPE1e#WefQBCnPhoa+;D1L>Bk&wznWkE+vEaM;ZL#j7GEvr;u{~1S{ z;wP_k{813UMg+2g*mo1FrYEi=C)ENE8h~0D)xb96ALe>^Ml{9$5XNf!{r-Lx+}{De zJH33MFC)_qs3QmV7du!#`Duzj?Eeawx7xSAE9hxUUMrk!@k$_*%m}W5M_!1GH1PB6 z!ZVC1{(CU?*&qPhzyHiSRuKhzLuEdMUd&9Pe~c9vud_t)50-y5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nBJZ%xigK7Z@6N(>ViPtcdgA#=6X5sW(75>`Dz3 zT=U+~ee3k_jHTZHPD%^qE{k&-PextLk_YW|N$qjLY~=8n&*H?yGce&Q3>fprF=1rx zhWTbwbLaVEEwY*OKK#_0`HvgO&}&}*Y<{s)phGQq-J#wpCxfwl+jo#>uS19d(cV|6 e#XA2KLr&=+-~VxPe*4HA408bdKdywo|N9?pS3u7I literal 0 HcmV?d00001 diff --git a/06 Banner/csharp/banner.cs b/06 Banner/csharp/banner.cs index 6b0ff142..e3e59b4b 100644 --- a/06 Banner/csharp/banner.cs +++ b/06 Banner/csharp/banner.cs @@ -153,19 +153,19 @@ namespace banner throw new KeyNotFoundException($"The provided letter {outCh} was not found in the letters list"); } - // New int array declarations default to zeros - // numSections decides how many 'sections' need to be printed - // for a given line of each character - int[] numSections = new int[7]; - // fillInSection decides whether each 'section' of the - // character gets filled in with the character or with blanks - int[] fillInSection = new int[9]; - // This iterates through each of the parts that make up // each letter. Each part represents 1 * Horizontal lines // of actual output. for (int idx = 0; idx < 7; idx++) { + // New int array declarations default to zeros + // numSections decides how many 'sections' need to be printed + // for a given line of each character + int[] numSections = new int[7]; + // fillInSection decides whether each 'section' of the + // character gets filled in with the character or with blanks + int[] fillInSection = new int[9]; + // This uses the value in each part to decide which // sections are empty spaces in the letter or filled in // spaces. For each section marked with 1 in fillInSection, @@ -228,7 +228,7 @@ namespace banner // In the original version, it would print an additional 75 blank // lines in order to feed the printer paper...don't really need this // since we're not actually printing. - Console.WriteLine(new string('\n', 75)); + // Console.WriteLine(new string('\n', 75)); } /// diff --git a/06 Banner/vbnet/.vs/banner/v16/.suo b/06 Banner/vbnet/.vs/banner/v16/.suo new file mode 100644 index 0000000000000000000000000000000000000000..07cc06fb840fc14b7fd08f682824e8fc5c6e32bf GIT binary patch literal 22016 zcmeHPPmEhf86O8)5-60kC6v;@LYETSyv6_jY)G12+i8ljbm?xAN*Iv;yxnZ-*elz+ zNyz2^TzZE?g*X%mq23AzB+lhj38@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y_~yZe6{ z$B>V0<&Sy)&z%2J?tih{q^q6HFqra>yhk_c{V%>d&Rq93Ev&_ds@$i2%6xqF$xZQ7>b?OT<~ zQ}KkZ6d`H;;m#xT)wk{({oSH?efFEj|Ey9E()_c*Q~R&gjp2#df4f(imI|DOVUGNy z9pn8Zsm|{XSz6!!F>BGKg53XU+wWtsOgyrdiaD`N8TR{lDdUvV#fXzBCu6a4r4&yj z%J-oCevGq(92scb_eZ^OKmK9Jk@oRPsBiRS(T%2x$x_&HWATI&kEYX3CRtf?5^iw~ z%;LJSWM(cLj>VFZ9nE?=d|ZUU&%e|^5xxaa!!b7;G~gMIdUpoDZS}8-f8PDq?k?}V z^X75y{Tmzm4|OHA3|+sqq;k5Sru_%Kq&a$I_blFI8zl9Rc*xXTJwGp?eQYBA>!Gqd zaO7ogZaa9Kcpb{DbKuA!={<0)pzJnEl1PvPN3&4{sh;(LqnV==_a<7ye@MetzII?+ zdC?ok^R(2Oe@^?Cf6RP`@%?iAc54YXR!;l|tg*af&pT(lX{D`B=2t^J2fqcobPC@f zrD2`sH%Tejsu$3QIIxd{C%>Au|AMIk#_Oi5?t7Y4$>H5)blVheS6?j=}kyao@=A-(x5#ySwCf5eWifX7qatl;27qjfVgG%kOTnw20a2)K1Rp z;Q#*en`_7p|4-%jzG#^bMSjcA8STG5l=yD}oMr#b=5tsrlaz4N??>?s>RtW)=s3;K z?bA1}qqn)U(YTPEFI<#g3}04X4CmTk4Cj2l7+#bg3HQ$UL@WFM?R%&@36sacZ>(b+ z{PyxYYWrg1#vu4@7AGFv{{e|Mv`Z32NAL}M7+8~T5VnN=6+Z{=JP5ZZ6(*%6oi{GE R9g;Jo+$s5Aue#;;{{YbB`mz83 literal 0 HcmV?d00001 diff --git a/06 Banner/vbnet/banner.sln b/06 Banner/vbnet/banner.sln new file mode 100644 index 00000000..5fdc8737 --- /dev/null +++ b/06 Banner/vbnet/banner.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31321.278 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "banner", "banner.vbproj", "{1738D297-A04C-4E6E-8219-D9E72982C39D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1738D297-A04C-4E6E-8219-D9E72982C39D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1738D297-A04C-4E6E-8219-D9E72982C39D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1738D297-A04C-4E6E-8219-D9E72982C39D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1738D297-A04C-4E6E-8219-D9E72982C39D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {04E18CE1-1C55-432F-A15A-DC2FA9DDC0F1} + EndGlobalSection +EndGlobal diff --git a/06 Banner/vbnet/banner.vb b/06 Banner/vbnet/banner.vb new file mode 100644 index 00000000..90e183b8 --- /dev/null +++ b/06 Banner/vbnet/banner.vb @@ -0,0 +1,226 @@ +Imports System + +Module Banner + Private Horizontal As Integer + Private Vertical As Integer + Private Centered As Boolean + Private Character As String + Private Statement As String + + ' This provides a bit-ended representation of each symbol + ' that can be output. Each symbol Is defined by 7 parts - + ' where each part Is an integer value that, when converted to + ' the binary representation, shows which section Is filled in + ' with values And which are spaces. i.e., the 'filled in' + ' parts represent the actual symbol on the paper. + Private letters As Dictionary(Of Char, Integer()) = New Dictionary(Of Char, Integer()) From + { + {" ", {0, 0, 0, 0, 0, 0, 0}}, + {"A", {505, 37, 35, 34, 35, 37, 505}}, + {"B", {512, 274, 274, 274, 274, 274, 239}}, + {"C", {125, 131, 258, 258, 258, 131, 69}}, + {"D", {512, 258, 258, 258, 258, 131, 125}}, + {"E", {512, 274, 274, 274, 274, 258, 258}}, + {"F", {512, 18, 18, 18, 18, 2, 2}}, + {"G", {125, 131, 258, 258, 290, 163, 101}}, + {"H", {512, 17, 17, 17, 17, 17, 512}}, + {"I", {258, 258, 258, 512, 258, 258, 258}}, + {"J", {65, 129, 257, 257, 257, 129, 128}}, + {"K", {512, 17, 17, 41, 69, 131, 258}}, + {"L", {512, 257, 257, 257, 257, 257, 257}}, + {"M", {512, 7, 13, 25, 13, 7, 512}}, + {"N", {512, 7, 9, 17, 33, 193, 512}}, + {"O", {125, 131, 258, 258, 258, 131, 125}}, + {"P", {512, 18, 18, 18, 18, 18, 15}}, + {"Q", {125, 131, 258, 258, 322, 131, 381}}, + {"R", {512, 18, 18, 50, 82, 146, 271}}, + {"S", {69, 139, 274, 274, 274, 163, 69}}, + {"T", {2, 2, 2, 512, 2, 2, 2}}, + {"U", {128, 129, 257, 257, 257, 129, 128}}, + {"V", {64, 65, 129, 257, 129, 65, 64}}, + {"W", {256, 257, 129, 65, 129, 257, 256}}, + {"X", {388, 69, 41, 17, 41, 69, 388}}, + {"Y", {8, 9, 17, 481, 17, 9, 8}}, + {"Z", {386, 322, 290, 274, 266, 262, 260}}, + {"0", {57, 69, 131, 258, 131, 69, 57}}, + {"1", {0, 0, 261, 259, 512, 257, 257}}, + {"2", {261, 387, 322, 290, 274, 267, 261}}, + {"3", {66, 130, 258, 274, 266, 150, 100}}, + {"4", {33, 49, 41, 37, 35, 512, 33}}, + {"5", {160, 274, 274, 274, 274, 274, 226}}, + {"6", {194, 291, 293, 297, 305, 289, 193}}, + {"7", {258, 130, 66, 34, 18, 10, 8}}, + {"8", {69, 171, 274, 274, 274, 171, 69}}, + {"9", {263, 138, 74, 42, 26, 10, 7}}, + {"?", {5, 3, 2, 354, 18, 11, 5}}, + {"*", {69, 41, 17, 512, 17, 41, 69}}, + {"=", {41, 41, 41, 41, 41, 41, 41}}, + {"!", {1, 1, 1, 384, 1, 1, 1}}, + {".", {1, 1, 129, 449, 129, 1, 1}} + } + + ' + ' This displays the provided text on the screen And then waits for the user + ' to enter a integer value greater than 0. + ' + ' Text to display on the screen asking for the input + ' The integer value entered by the user + Private Function GetNumber(DisplayText As String) As Integer + Console.Write(DisplayText) + Dim TempStr As String = Console.ReadLine() + Dim TempInt As Integer + + Int32.TryParse(TempStr, TempInt) + + If (TempInt <= 0) Then + Throw New ArgumentException($"{DisplayText} must be greater than zero") + End If + + Return TempInt + End Function + + ' + ' This displays the provided text on the screen And then waits for the user + ' to enter a Y Or N. It cheats by just looking for a 'y' and returning that + ' as true. Anything else that the user enters Is returned as false. + ' + ' Text to display on the screen asking for the input + ' Returns true Or false + Private Function GetBool(DisplayText As String) As Boolean + Console.Write(DisplayText) + Return Console.ReadLine().StartsWith("y", StringComparison.InvariantCultureIgnoreCase) + End Function + + ' + ' This displays the provided text on the screen And then waits for the user + ' to enter an arbitrary string. That string Is then returned 'as-is'. + ' + ' Text to display on the screen asking for the input + ' The string entered by the user. + Private Function GetString(DisplayText As String) As String + Console.Write(DisplayText) + Return (Console.ReadLine().ToUpper()) + End Function + + ' + ' This queries the user for the various inputs needed by the program. + ' + Private Sub GetInput() + Horizontal = GetNumber("Horizontal ") + Vertical = GetNumber("Vertical ") + Centered = GetBool("Centered ") + Character = GetString("Character (type 'ALL' if you want character being printed) ") + Statement = GetString("Statement ") + ' We don't care about what the user enters here. This is just telling them + ' to set the page in the printer. + GetString("Set page ") + End Sub + + ' + ' This prints out a single character of the banner - adding + ' a few blanks lines as a spacer between characters. + ' + Private Sub PrintChar(ch As Char) + ' In the trivial case (a space character), just print out the spaces + If ch.Equals(" ") Then + Console.WriteLine(New String("\n", 7 * Horizontal)) + Return + End If + + ' If a specific character to be printed was provided by the user, + ' then user that as our ouput character - otherwise take the + ' current character + Dim outCh As Char = IIf(Character.Equals("ALL"), ch, Character.Substring(0, 1)) + Dim letter(7) As Integer + Try + letters(outCh).CopyTo(letter, 0) + Catch ex As KeyNotFoundException + Throw New KeyNotFoundException($"The provided letter {outCh} was not found in the letters list") + End Try + + ' This iterates through each of the parts that make up + ' each letter. Each part represents 1 * Horizontal lines + ' of actual output. + For idx As Integer = 0 To 7 + ' New int array declarations default to zeros + ' numSections decides how many 'sections' need to be printed + ' for a given line of each character + Dim numSections(7) As Integer + ' fillInSection decides whether each 'section' of the + ' character gets filled in with the character Or with blanks + Dim fillInSection(9) As Integer + + ' This uses the value in each part to decide which + ' sections are empty spaces in the letter Or filled in + ' spaces. For each section marked with 1 in fillInSection, + ' that will correspond to 1 * Vertical characters actually + ' being output. + For exp As Integer = 8 To 0 Step -1 + If (Math.Pow(2, exp) < letter(idx)) Then + fillInSection(8 - exp) = 1 + letter(idx) -= Math.Pow(2, exp) + If (letter(idx) = 1) Then + ' Once we've exhausted all of the sections + ' defined in this part of the letter, then + ' we marked that number And break out of this + ' for loop. + numSections(idx) = 8 - exp + Exit For + End If + End If + Next exp + + ' Now that we know which sections of this part of the letter + ' are filled in Or spaces, we can actually create the string + ' to print out. + Dim lineStr As String = "" + + If (Centered) Then + lineStr += New String(" ", (63 - 4.5 * Vertical) * 1 / 1 + 1) + End If + + For idx2 As Integer = 0 To numSections(idx) + lineStr = lineStr + New String(IIf(fillInSection(idx2) = 0, " ", outCh), Vertical) + Next idx2 + + ' Then we print that string out 1 * Horizontal number of times + For lineIdx As Integer = 1 To Horizontal + Console.WriteLine(lineStr) + Next lineIdx + Next idx + + + ' Finally, add a little spacer after each character for readability. + Console.WriteLine(New String(Environment.NewLine, 2 * Horizontal - 1)) + End Sub + + ' + ' This prints the entire banner based in the parameters + ' the user provided. + ' + Private Sub PrintBanner() + ' Iterate through each character in the statement + For Each ch As Char In Statement + PrintChar(ch) + Next ch + + ' In the original version, it would print an additional 75 blank + ' lines in order to feed the printer paper...don't really need this + ' since we're not actually printing. + Console.WriteLine(New String(Environment.NewLine, 75)) + End Sub + + ' + ' Main entry point into the banner class And handles the main loop. + ' + Public Sub Play() + GetInput() + PrintBanner() + End Sub +End Module + +Module Program + Sub Main(args As String()) + Banner.Play() + End Sub +End Module diff --git a/06 Banner/vbnet/banner.vbproj b/06 Banner/vbnet/banner.vbproj new file mode 100644 index 00000000..659fea7b --- /dev/null +++ b/06 Banner/vbnet/banner.vbproj @@ -0,0 +1,9 @@ + + + + Exe + banner + netcoreapp3.1 + + +