User Tools

Site Tools


user:acrowle1:portfolio:cprogproject3

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
user:acrowle1:portfolio:cprogproject3 [2014/03/02 21:56] – [Reflection] acrowle1user:acrowle1:portfolio:cprogproject3 [2014/03/09 14:53] (current) – [Project: dayofweek] acrowle1
Line 1: Line 1:
-======Project: squares======+======Project: Squares======
  
 A project for CSCS1320S14 by Alana Whittier during the Spring Semester 2014. A project for CSCS1320S14 by Alana Whittier during the Spring Semester 2014.
Line 50: Line 50:
 My first attempt at writing the program was using the modulus operator, %, although abandoned that effort quickly as it was not clear what to do with the factor in order to implement the mental math technique. I then decided to implement the computation of the square in what I deemed more simplistic of an approach and then used a series of if, else if statements to output **//only//** the values I wanted the user to input and obtain (two-digit integers ending in 5), and  finally an else statement in which "Error: Invalid Entry" is displayed for all values greater than 95 and for all values that do not end in 5.  My first attempt at writing the program was using the modulus operator, %, although abandoned that effort quickly as it was not clear what to do with the factor in order to implement the mental math technique. I then decided to implement the computation of the square in what I deemed more simplistic of an approach and then used a series of if, else if statements to output **//only//** the values I wanted the user to input and obtain (two-digit integers ending in 5), and  finally an else statement in which "Error: Invalid Entry" is displayed for all values greater than 95 and for all values that do not end in 5. 
  
-Example 1: +Example 1 (My first submitted program)
  
  
Line 94: Line 94:
 After more consideration, I decided to try again writing the program using the modulus operator, which I called R and the factor which I declared a variable. This code is substantially more efficient as it does not require so many lines of code to obtain the squared values. However, I am uncertain how to completely limit the computation and output, since this approach also works for 3 and 4 digit integers ending in five.  After more consideration, I decided to try again writing the program using the modulus operator, which I called R and the factor which I declared a variable. This code is substantially more efficient as it does not require so many lines of code to obtain the squared values. However, I am uncertain how to completely limit the computation and output, since this approach also works for 3 and 4 digit integers ending in five. 
  
-See the code below.+Example 2 (The second program using modulus operator and factor): 
  
  
Line 211: Line 211:
 Second mistake: The way I used the curly braces. Essentially, I was embedding several else if statements within the initial if. By correcting this my code worked flawlessly. Second mistake: The way I used the curly braces. Essentially, I was embedding several else if statements within the initial if. By correcting this my code worked flawlessly.
  
-Since my initial attempt at writing this program included the modulus operator, which had been quickly abandoned, I decided to revisit that since I now had a working program written in a manner I felt was more simplistic.  +Since my initial attempt at writing this program included the modulus operator, which had been quickly abandoned, I decided to revisit that since I now had a working program written in a manner I felt was more simplistic. What I realized that I was missing from my initial program was the factor (the number of times that 10 went into the integer). For example, if I declared the factor to be i/10 and R= i%10, then for an integer value of 25, R=5 and the factor=2, since 10 can go into 25 twice, with a remainder of 5. With this program written this way, the same mental math technique works for 3 and 4 digit integers ending in 5 as well, to compute the squares. This code is shown above in Example 2 of the Procedure section.    
  
-**Observations** 
  
-The long and long long int (signed and unsigned) appear the same. This is because they are both 64 bit and that is the most the compiler can handle. 
  
-printf() and fprintf() basically do the same thing. The difference being that printf can only print on the monitor, has the default stream of STDOUT, while fprintf can print to a user defined stream (or file). In our project, fprintf uses the STDOUT to the screen AS if it were a file.  
  
-STDOUT is by default printed to the screen unless user specified.  
- 
-%s is the format specifier used to print a string of characters, %hhu is the format specifier for half half unsigned char, % hu is the format specifier for unsigned short int.  
- 
-The difference between %u and %d are that %u denotes an unsigned int type, while %d denotes a signed int type.  
- 
-Considering the 13 in %13 in the first stanza for unsigned char in the program, this just specifies the number of characters in the string, including spaces to be printed for "TYPE" 
- 
-If a sign is left unspecified, it is assumed unsigned by default. 
- 
-The & and | operators are the bitwise logic operators, which in our case took the hex representation of our data types to help us to obtain the appropriate high/low values within our ranges.  
- 
-I experienced some difficulty in initial attempts to obtain the low values for the signed data types. I later learned that not only did I need to change the expression for the "low" values to bitwise OR, but I also needed to type cast in the final line of the signed data type stanza. 
- 
-Based on my program's output, the total bits allocated per the following data types are as follows: 
-   * signed char = 8 bits 
-   * unsigned short int = 16 bits 
-   * unsigned int = 32 bits 
-   * signed int = 32 bits 
-   * signed long long int = 64 bits 
- 
-However, due to the decrementing and incrementing per data type, only the unsigned char actually stored ANY memory at all and stored a total of 16 bits! 
  
  
Line 252: Line 227:
 In performing this project, the following resources were referenced: In performing this project, the following resources were referenced:
  
-  * http://en.cppreference.com/w/cpp/language/types1 +  * http://wildaboutmath.com/2007/11/11/impress-your-friends-with-mental-math-tricks/comment-page-6
-  * http://www.youtube.com/watch?v=SXAr35BiqK8 +  * http://saurabhg.hubpages.com/hub/Vedic-Mathematics---Quick-multiplication-techniques---Part-1 
-  * http://www.binaryhexconverter.com/decimal-to-hex-converter +  * Kernighan, Ritchie //The C Programming Language// Second Edition, AT&T Bell Laboratories, 1988. Print. 
-  * http://en.wikipedia.org/wiki/Signed_number_representations +  * email consultations and guidance from Matt Haas
user/acrowle1/portfolio/cprogproject3.1393797393.txt.gz · Last modified: 2014/03/02 21:56 by acrowle1