Classwork 4: More input, output, and operators

Thursday, July 12, 2012     


[Previous Classwork] [Next Classwork]


Complete the following:

  1. Ensure the machine is booted into Linux
  2. Login to Linux
  3. Open a termimal from the top left Applications menu -> System Tools -> Terminal
  4. Create a directory (using mkdir) called cw04 to store this classwork
  5. Go into your new cw04 directory (using cd)
  6. Create a new file using the editor you like (nano, vi, emacs, xemacs) called cw04.c
  7. Type a comment for the header based on the template below:

    /*   File: cw04.c
         Name: A. Student
         Username: astudent1
         Date: 10/24/07
         Description: ...
    */
    

  8. Type in the appropriate #include to use printf and scanf
  9. Create the main block (make sure to have { after main, and } at the end of your code)
  10. Then write code inside main to:
    • Before you start writing code, read through what the program will do and decide how many and what type of variables you will need.
    • Print out the following string "Starting cw04\n" at the start of your progam
    • Print out a string asking the user to input two integers (use printf)
    • Allow the user to input two integers (use scanf)
    • Print out the integral result of dividing the first integer by the second (use division operator /)
    • Print out the integral remainder when dividing the first integer by the second (use modulus operator %)
    • Remember to return zero at the end of main
  11. Remember to use the following command to compile your program as shown below

    linux2[107]% gcc -Wall cw04.c -o cw04
    

  12. And then run your program as shown below

    linux2[108]% ./cw04
    Starting cw04
    

  13. Once you are sure the program is done and working well, start a script using script
  14. Once the script is running, show you compiling your program, and then running the program three times, typing in different values each time.
  15. Exit from the script, which will save the log typescript
  16. Once you are done, use submit to submit two files, cw04.c and typescript

    linux3[26]% submit cs104 cw04 cw04.c typescript
    

  17. After submitting your files, you can verify your files were submitted by using the submitls command as shown below

    linux3[26]% submitls cs104 cw04
    

  18. MAKE SURE YOU LOGOUT AFTER SUBMITTING THE ASSIGNMENT AND BEFORE LEAVING CLASS!