User Tools

Site Tools


haas:spring2015:cprog:projects:afn0

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
haas:spring2015:cprog:projects:afn0 [2015/02/26 13:08] – [Execution] wedgehaas:spring2015:cprog:projects:afn0 [2015/03/20 20:45] (current) – [Prerequisites/Corequisites] wedge
Line 15: Line 15:
  
   * can perform this trick in your head/by hand (if you can't do it on your own, you have no business trying to tell the computer how to do it)   * can perform this trick in your head/by hand (if you can't do it on your own, you have no business trying to tell the computer how to do it)
-  * understand the pattern/process to doing it for any length number (2-digit through 24-digdt)+  * understand the pattern/process to doing it for any length number (2-digit through 18-digdt)
   * ability to deploy loops to simplify your process   * ability to deploy loops to simplify your process
   * ability to use arrays to facilitate the storage of your processed values   * ability to use arrays to facilitate the storage of your processed values
Line 189: Line 189:
  
 =====Program===== =====Program=====
-It is your task to write an optimized version of your multiply by eleven program that will use arrays and loops to enable you to enhance and expand the functional capabilities of your program. No longer will you be limited by 1-2-, or 3-digit numbers, but you will be able to input up to 8-digit numbers and have your program successfully determine the result (and 8 is merely an arbitrary value I picked, you should easily be able to up it to the tens of thousands and experience no change in functionality-- actually, our 8-digit limit is considering a data type limitation... the maximum size of an int: **signed int**s can have a maximum value of 2.4 billionso unless we change to a different data type (or different method of inputting the source number)this will be our limitation.+It is your task to write program that obtains a long integer value from the user, and processes that single value into separate array elements (one digit per array element). Determining the number of digitsyou are to perform this "all from nine, last from ten" subtraction method on the number using array transactionsdisplaying a visual representation of the problem being solved to STDOUT.
  
 Your program should: Your program should:
   * obtain its input from STDIN.   * obtain its input from STDIN.
-    * input should be in the form of a single integer value+    * input should be in the form of a single (long) long integer value (you want a 64-bit data type)
   * determine the number of digits of the inputted value (store this in a variable)   * determine the number of digits of the inputted value (store this in a variable)
-  * perform the correct algorithm against the input +  * process that input long integer into separate array elements- one digit per element. 
-  * propagate any carries +    * you may assume a maximum array size of the maximum number of digits you're theoretically able to input that can be stored in a 64-bit value. 
-  * use an array (**digit**) to store individual digits from the number input +  * perform the "all from nine, the last from ten" operation on the array, storing the result in another array. 
-  * use another array (**result**) to store the digits of the result number, following manipulations +  * display the problem being solved, along with the answer 
-    * hint: you will want to make the **result** array one element largerWhy is this? +  * use functions to modularize your code: 
-  Display output showing aspects of the process (see example execution below) +    * have an **longint2array()** function that takes the long int, and returns an array (the function itself handles the processing of splitting up the long int into individual digits). 
-  output the final value (by iterating through the array, displaying one value at a time)+    * have a **printarray()** function, whose responsibility it is to display the indicated array to STDOUT
 +    have a **allfromnine()** function that takes the source array, does the processing, and returns ther result array.
  
 +I might suggest the following function prototypes:
 +
 +<code c>
 +unsigned char *longint2array(unsigned long int);
 +void printarray(unsigned char *, unsigned char);
 +unsigned char *allfromnine(unsigned char *);
 +</code>
 +
 +Some questions to contemplate:
 +
 +  * Why an array of unsigned chars when we're starting with a long (long) int?
 +    * Why is that the "best fit" size-wise?
 +    * Why will that not result in lost data?
 +  * Why unsigned?
 +    * What impact will that have on our input value's upper bound?
 +  * Why represent the size of the usable array as an unsigned char?
 +    * Why is this the "best fit" size-wise?
 =====Execution===== =====Execution=====
 An example of your program in action: An example of your program in action:
Line 235: Line 253:
  
 <cli> <cli>
-$ submit cprog mbe1 mbe1.c +$ submit cprog afn0 afn0.c 
-Submitting cprog project "mbe1": +Submitting cprog project "afn0": 
-    -> mbe1.c(OK)+    -> afn0.c(OK)
  
 SUCCESSFULLY SUBMITTED SUCCESSFULLY SUBMITTED
haas/spring2015/cprog/projects/afn0.1424956139.txt.gz · Last modified: 2015/02/26 13:08 by wedge