0f0469c36ffa4515e00fecada330d9446787954c
haas/fall2026/c4eng/projects/cit0.md
| ... | ... | @@ -0,0 +1,181 @@ |
| 1 | +# ENGR1050 C for Engineers |
|
| 2 | + |
|
| 3 | +# PROJECT: C INTEGER TYPES (cit0) |
|
| 4 | + |
|
| 5 | +## OBJECTIVE |
|
| 6 | + |
|
| 7 | +To begin our exploration of programming, starting with an investigation |
|
| 8 | +into the various integer data types available in C, along with their |
|
| 9 | +properties. |
|
| 10 | + |
|
| 11 | +## OBTAIN THE PROJECT FILES |
|
| 12 | + |
|
| 13 | +To assist with consistency across all implementations, data files for use |
|
| 14 | +with this project are available on the class repository under the |
|
| 15 | +`projects/` directory. Please copy the data to your project directory to |
|
| 16 | +begin work. |
|
| 17 | + |
|
| 18 | +Please study any provided code or supporting documents, and look up, |
|
| 19 | +experiment, and ask questions on aspects that you do not understand. |
|
| 20 | + |
|
| 21 | +## SCOPE |
|
| 22 | + |
|
| 23 | +This project will be exploring the nature of some of the data types |
|
| 24 | +available to us in the C Programming Language. How much space is |
|
| 25 | +allocated to each type, and what are the ranges available for each type? |
|
| 26 | + |
|
| 27 | +A program is provided that will display (to STDOUT) the size (in bytes), |
|
| 28 | +the lower and upper bounds of each studied type, and some other related |
|
| 29 | +information. |
|
| 30 | + |
|
| 31 | +The data types covered for this project will include **signed** (can be |
|
| 32 | +positive/negative) and **unsigned** (absolute values, no sign) variations |
|
| 33 | +of: |
|
| 34 | + |
|
| 35 | + * `char` |
|
| 36 | + * `short int` |
|
| 37 | + * `int` |
|
| 38 | + * `long int` |
|
| 39 | + * `long long int` |
|
| 40 | + |
|
| 41 | +The **sizeof()** and **fprintf()** functions, as well as arithmetic and |
|
| 42 | +logical operators, will be utilized in performing much of the work. |
|
| 43 | + |
|
| 44 | +## TASK |
|
| 45 | + |
|
| 46 | +Your task is to first study and understand what the provided code is |
|
| 47 | +doing. It is expected you will ask questions on discord to gain |
|
| 48 | +clarification. |
|
| 49 | + |
|
| 50 | +There is extensive commenting in place in the source file for you to |
|
| 51 | +read, which will explain many of the details about each item of |
|
| 52 | +information being obtained. |
|
| 53 | + |
|
| 54 | +Once you have an understanding of what is going on, extend the code to |
|
| 55 | +support the other types (both signed and unsigned). In total, you should |
|
| 56 | +have TEN total sections. |
|
| 57 | + |
|
| 58 | +## HEXADECIMAL |
|
| 59 | + |
|
| 60 | +When dealing with things like addresses and raw data on the computer |
|
| 61 | +(a **binary** device), it is common practice to interact in some |
|
| 62 | +power-of-two base, with base 16 (hexadecimal) being the most common in |
|
| 63 | +use today. |
|
| 64 | + |
|
| 65 | +I would encourage you to memorize and become very familiar with |
|
| 66 | +navigating the following table: |
|
| 67 | + |
|
| 68 | +| base 2 | base 8 | base 10 (unsigned) | base 10 (signed) | base 16 | |
|
| 69 | +| ------ | ------ | ------------------ | ---------------- | ------- | |
|
| 70 | +| `0000` | `000` | `0` | `+0` | `0x0` | |
|
| 71 | +| `0001` | `001` | `1` | `+1` | `0x1` | |
|
| 72 | +| `0010` | `002` | `2` | `+2` | `0x2` | |
|
| 73 | +| `0011` | `003` | `3` | `+3` | `0x3` | |
|
| 74 | +| `0100` | `004` | `4` | `+4` | `0x4` | |
|
| 75 | +| `0101` | `005` | `5` | `+5` | `0x5` | |
|
| 76 | +| `0110` | `006` | `6` | `+6` | `0x6` | |
|
| 77 | +| `0111` | `007` | `7` | `+7` | `0x7` | |
|
| 78 | +| `1000` | `010` | `8` | `-8` | `0x8` | |
|
| 79 | +| `1001` | `011` | `9` | `-7` | `0x9` | |
|
| 80 | +| `1010` | `012` | `10` | `-6` | `0xA` | |
|
| 81 | +| `1011` | `013` | `11` | `-5` | `0xB` | |
|
| 82 | +| `1100` | `014` | `12` | `-4` | `0xC` | |
|
| 83 | +| `1101` | `015` | `13` | `-3` | `0xD` | |
|
| 84 | +| `1110` | `016` | `14` | `-2` | `0xE` | |
|
| 85 | +| `1111` | `017` | `15` | `-1` | `0xF` | |
|
| 86 | + |
|
| 87 | +It might be worthwhile to ask questions about the nature of the values on |
|
| 88 | +this table on the class discord, to gain a better understanding of why |
|
| 89 | +these values are here, how they were derived, and what value they bring |
|
| 90 | +to our interaction with computers. |
|
| 91 | + |
|
| 92 | +## COMPILING |
|
| 93 | + |
|
| 94 | +The compilation process for working with your source code is as follows: |
|
| 95 | + |
|
| 96 | +``` |
|
| 97 | +lab46:~/SEMESTER/c4eng/cit0$ gcc -Wall --std=gnu18 -o cit0 cit0.c |
|
| 98 | +lab46:~/SEMESTER/c4eng/cit0$ |
|
| 99 | +``` |
|
| 100 | + |
|
| 101 | +Assuming there are no syntax errors or warnings, and everything compiled |
|
| 102 | +correctly, you should just get your prompt back. In the event of |
|
| 103 | +problems, the compiler will be sure to tell you about them. |
|
| 104 | + |
|
| 105 | +Conceptually, the arrangement is as follows: |
|
| 106 | + |
|
| 107 | +``` |
|
| 108 | +gcc -Wall --std=gnu18 -o BINARYFILE SOURCEFILE |
|
| 109 | +``` |
|
| 110 | + |
|
| 111 | +The `BINARYFILE` comes **immediately after** the **-o**, **NOT** the |
|
| 112 | +`SOURCEFILE` (the source file must never **immediately** follow a |
|
| 113 | +**-o**). It can precede, and such is perfectly valid (especially if you |
|
| 114 | +feel that way more intuitive). |
|
| 115 | + |
|
| 116 | +The `-Wall` (treat all warnings as errors, increase general verbosity |
|
| 117 | +about warnings) and `--std=gnu18` (switch compiler to use a newer |
|
| 118 | +standard of the C language, with GNU extensions) are options given to the |
|
| 119 | +compiler. |
|
| 120 | + |
|
| 121 | +## EXECUTION |
|
| 122 | + |
|
| 123 | +To execute your binary, we need to specify a path to it, so we use |
|
| 124 | +**./**, which basically references the current directory: |
|
| 125 | + |
|
| 126 | +``` |
|
| 127 | +lab46:~/SEMESTER/c4eng/cit0$ ./cit0 |
|
| 128 | +signed char |
|
| 129 | +========================================= |
|
| 130 | +total size in bytes: 1 |
|
| 131 | +total size in bits: 8 |
|
| 132 | +value contains: 17 |
|
| 133 | +value exists in memory at: 0x7ffc1a16d967 |
|
| 134 | +minimum value represented: -128 |
|
| 135 | +maximum value represented: 127 |
|
| 136 | +possible distinct values: 256 |
|
| 137 | +========================================= |
|
| 138 | +``` |
|
| 139 | + |
|
| 140 | +Your completed program will have far more output: additional sections |
|
| 141 | +each representing one of the integer type combinations (a total of 10). |
|
| 142 | + |
|
| 143 | +## SUBMISSION |
|
| 144 | + |
|
| 145 | +To successfully complete this project, the following criteria must be |
|
| 146 | +met: |
|
| 147 | + |
|
| 148 | + * Code must compile/execute cleanly (no notes, warnings, nor errors) |
|
| 149 | + * Code must be nicely and consistently indented |
|
| 150 | + * Code must be well commented |
|
| 151 | + * Do NOT double space your code. Group like statements together. |
|
| 152 | + * Track/version the source code in your private semester repository |
|
| 153 | + |
|
| 154 | +To submit this project to me, make sure the `Makefile` and your completed |
|
| 155 | +`cit0.c` file are placed in your private semester repository under |
|
| 156 | +`c4eng/cit0/` |
|
| 157 | + |
|
| 158 | +What I'll be looking for: |
|
| 159 | + |
|
| 160 | +### RUBRIC |
|
| 161 | + |
|
| 162 | +I'll be evaluating the project based on the following criteria: |
|
| 163 | + |
|
| 164 | +``` |
|
| 165 | +104:cit0:final tally of results (104/104) |
|
| 166 | +*:cit0:code is pushed to private semester repository [26/26] |
|
| 167 | +*:cit0:proper output formatting per specifications [13/13] |
|
| 168 | +*:cit0:clean compile, no compiler messages [13/13] |
|
| 169 | +*:cit0:each integer type explored in full [26/26] |
|
| 170 | +*:cit0:program conforms to project specifications [26/26] |
|
| 171 | +``` |
|
| 172 | + |
|
| 173 | +NOTE: spirit of the project includes using hexadecimal values and bitwise |
|
| 174 | +logic operators to set the pertinent upper/lower bounds. |
|
| 175 | + |
|
| 176 | +Additionally: |
|
| 177 | + * Solutions not abiding by spirit of project will be subject to a 50% overall deduction |
|
| 178 | + * Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction |
|
| 179 | + * Solutions not utilizing indentation to promote scope and clarity or otherwise maintaining consistency in code style and presentation will be subject to a 25% overall deduction |
|
| 180 | + * Solutions not organized and easy to read (assume a terminal at least 90 characters wide, 40 characters tall) are subject to a 25% overall deduction |
|
| 181 | + |