M4ritimeSeeker

PASS Week 2: C Structure, and Week 1 Catch-up

Jan 24th, 2022 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. PROBLEM 1: Interacting with systems software using standard input and the virtual terminal for output.
  2.  
  3. Follow the PASS leader as they ask you to follow their lead exploring your computer. Introduction to the File System using Systems Software. (Windows & Mac)
  4.  
  5. Windows Users:
  6. - Interact with the file system using utility software. (cmd)
  7. - From the root of the filesystem run through various utilities demonstrating how to (cd, dir) both text files and binary files are
  8. listed in the Windows environment.
  9. - Discuss the idea of filepath. (c:\Users\NXXXXX\Desktop).
  10. o The name of the executable program is a binary file.
  11. o The programs are created from source files.
  12.  
  13. Linux/Mac Users:
  14. - Interact with the file systems using the bash command terminal. (under utilities)
  15. - Change directory using the cd utility, list the files using the ls utility.
  16.  
  17.  
  18.  
  19. Quick List of Useful Commands and the Windows or Linux/Mac Equivalent
  20.  
  21. WINDOWS ------ LINUX/MAC
  22. dir ls (Lists the content of the directory you are in)
  23. cd cd (Change the current directory. EXAMPLE: cd Downloads)
  24. cls clear (Clears all text from the terminal, making it easier to read)
  25. md mkdir (Make a new Directory. EXAMPLE: mkdir NewDirectory)
  26. rmdir rmdir (Remove a Directory. EXAMPLE: rmdir NewDirectory)
  27. copy NUL touch (Make a new file of any type. EXAMPLE: copy NUL file.txt EXAMPLE2: touch file.txt)
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. PROBLEM #2: Matching Activity of C Structure and Commenting
  50.  
  51. Using the C Program Structure handout, MATCH EACH LINE OF THE PROGRAM BELOW WITH THE CORRECT COMMENT.
  52. Some of the comments may match multiple lines.
  53. We cover printf and scanf in greater detail in Canvas Module 3.
  54. We cover user defined functions in a far future module
  55. (i.e. don't worry about the doesNothing function too much, just label to the best of your knowledge)
  56.  
  57. COMMENTS:
  58. //Local statements/declarations
  59. //Preprocessor directives
  60. //Global declarations
  61. //Other functions
  62. //Main function
  63.  
  64.  
  65. PROGRAM:
  66.  
  67. #include <stdio.h>
  68. #define PI 3.14
  69.  
  70. int doesNothing(void);
  71.  
  72. int main(void)
  73. {
  74.  
  75. printf(“Hello World!!\n”);
  76. doesNothing();
  77.  
  78. return 0;
  79.  
  80. }
  81.  
  82.  
  83. int doesNothing(){
  84. return 0;
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115. PROBLEM #3: Error checking and correcting activity
  116.  
  117.  
  118. 3 types of Errors:
  119. • Syntax errors – wont compile because of incorrect syntax of the language
  120. • Logical errors – Gets the wrong answers but runs / bad design
  121. • Run time errors – Program ends unpredictably or unexpectedly / Usually due to accessing memory incorrectly.
  122.  
  123.  
  124. Copy the defective source code below exactly into the IDE of your choice. Attempt to compile it. Examine the compiler errors and fix the syntax errors one at a time starting with the firsterror on top of the errors reported. Ask Justin if you need help with scanf() and printf() modifiers. We learned these functions in Week 2.
  125.  
  126. Broken Program Source Code:
  127.  
  128.  
  129. /**************************************************
  130. * Top comment code is not filled for this example.
  131. * You would put your
  132. * N number here too.
  133. **************************************************
  134. #include <stdioh>
  135.  
  136. int main(int)
  137. {
  138.  
  139. int age_In = 0:
  140. print("Enter in your age please.\n");
  141. scanf("%d", age_in);
  142. printf("You told me your age is: %f\n");
  143. return;
  144.  
  145. }
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163. Problem #4: Formatting output using printf() format specifiers.
  164.  
  165. Using the incomplete program below, add format specifiers to print out the various variable values and constants
  166. correctly. The variables that hold money values should be printed out with a precision of .2 and should have a width that fills the following digits: “0000.00”. Sample output is provided below the program as well.
  167.  
  168. Use the following link for more information on format specifiers and how to give the output precision:
  169. https://www.tutorialspoint.com/format-specifiers-in-c
  170.  
  171.  
  172. PROGRAM:
  173.  
  174.  
  175. #include <stdio.h>
  176. #define DOLLARS 9999
  177. #define CENTS 99
  178.  
  179. int main()
  180. {
  181. const short int VALUE1 = -32768;
  182. unsigned int value2 = 4294967295;
  183. float moreMoney = 199.955;
  184.  
  185. /**** ONLY EDIT THE PRINTF STATEMENTS BELOW ****/
  186.  
  187. printf("The value of Dollars and Cents is: $\n", DOLLARS, CENTS);
  188. printf("The value of moreMoney is : %\n", moreMoney);
  189. printf("The vlaue of the short integer is: %\n", VALUE1);
  190. printf("The value of the short unsigned integer is: %\n", value2);
  191.  
  192. return 0;
  193. }
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201. SAMPLE OUTPUT:
  202.  
  203. The value of Dollars and Cents is: $9999.99
  204. The value of moreMoney is : 199.96
  205. The vlaue of the short integer is: -32768
  206. The value of the short ungisned integer is: 4294967295
  207.  
  208.  
  209.  
  210.  
Add Comment
Please, Sign In to add comment