Download presentation
Presentation is loading. Please wait.
1
Hw 5 Hints
2
Managing Complexity Many different ways to solve this problem
Write and test one function at a time Try to use a statically allocated array with say, 100 char Convert to a dynamically allocated array later Creating little helper functions Reverse string Multiply up to 10 Max, min
3
Debugging Remember to check operands of different lengths
Use a global debugging counter to track memory allocation Update the counter whenever new and delete are called
4
The Least Significant Digit First
Integer to string Addition
5
Integer to String 123 -> “123” 123 % 10 = 3, ‘3’ = 3 + ‘0’
123 / 10 = 12 12 % 10 = 2, ‘2’ = 2 + ‘0’ 12 / 10 = 1 1 % 10 = 1, ‘1’ = 1 + ‘0’ 1 / 10 = 0 // terminate
6
Addition
7
The Most Significant Digit First
Multiplication Comparison of two numbers of the same length
8
Multiplication 1111 X
9
Same as… 1111 X 111 ------------ + 1111 ------------- 12321
10
Same as… 1111 x 111 = ((1 x 1111) x x 1111) x x 1111
11
Comparison If two numbers have the same length
The most significant digit decides which number is bigger If they are the same, compare the next digit
12
Some Possible Ways to Store 123
“123” Easier to print and extract input Easier to write the string conversion constructor Easier to multiply Easier to compare numbers “321” Easier to write the integer conversion constructor Easier to add two numbers Lowest significant digit first
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.