VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 3B Integral Data (Tutorial)
Tutorial: Binary Conversion Program Visual C++ Programming 2 Problem Analysis Construct a program that allows the user to enter a character and see its decimal (base-10) and binary (base-2) representations For example, if the user entered the letter ‘A’ Its binary representation is displayed Its decimal representation 65 is displayed
Visual C++ Programming 3
Problem Description Visual C++ Programming 4 The ASCII code of the letter is a base-10 integer – no explicit conversion required! To calculate the binary representation Start with the largest binary place value (128) Determine how many whole times the place value goes into the integer in question (using integer division) Display the result Capture the remainder (using mod)
Visual C++ Programming 5
6
7
8
Design Visual C++ Programming 9 Interface sketch requires numerous textboxes Data entry (txtChar) Data output Eight textboxes for the binary digits One textbox (txtDec) for the decimal version Control table Data table Algorithm for the button (btnConvert)
Visual C++ Programming 10
Visual C++ Programming 11
Visual C++ Programming 12
Visual C++ Programming 13
Visual C++ Programming 14
Visual C++ Programming 15
Development Visual C++ Programming 16 Create the interface Create, resize and position multiple textboxes Set MaxLength property to 1 for txtChar Set horizontal spacing Add labels Change ForeColor and BackColor Assign names to match interface design Add a textbox for instructions ( txtInstruct )
Visual C++ Programming 17
Visual C++ Programming 18
Visual C++ Programming 19
Visual C++ Programming 20
Visual C++ Programming 21
Visual C++ Programming 22
Visual C++ Programming 23
Visual C++ Programming 24
Visual C++ Programming 25
Visual C++ Programming 26
Visual C++ Programming 27
Visual C++ Programming 28
Visual C++ Programming
Development (continued) Visual C++ Programming 30 Code Form1_Load() event handler Code btnConvert_Click() Assign first character in txtChar to variable Assign character to an integer variable and display Display groups of 128 Calculate remainder Display other place values
Visual C++ Programming 31
Visual C++ Programming 32
Visual C++ Programming 33
Visual C++ Programming 34
Visual C++ Programming 35
Visual C++ Programming 36
Visual C++ Programming 37
Visual C++ Programming 38
Visual C++ Programming 39
Testing Visual C++ Programming 40 Demonstrate that your program works with A-Z characters a-z characters 0-9 numerals Punctuation marks and special characters Use the ASCII table in Appendix B to verify correctness
Visual C++ Programming 41
On Your Own Visual C++ Programming 42 Demonstrate your understanding Create a diagram like Figure 3-28 to show how your program works with various decimal numbers Replace ToString() with Convert::ToString() Use shorthand operators /= %=