Skip to main content
Engineering LibreTexts

20.3: Exercises

  • Page ID
    54389
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Below are some quiz questions and project suggestions based on this chapter.

    Quiz Questions

    Below are some quiz questions.

    1. Can the date alone be obtained (i.e., without obtaining the time) using the get_date_time() system service (yes/no)?
    2. When using the get_date_time() system service to obtain the integer date and time values, what is the index number for the:
      1. The month value.
      2. The hour value.
      3. The year value.
    3. How can the integer time zone value be converted to hours:minutes format?
    4. Provide the get_date_time() system service call to obtain the current date string into the already declared character variable dStr.
    5. Provide the get_date_time() system service call to obtain the current time string and time zone string into the already declared character variables timeStr and zoneStr.
    6. Provide the get_date_time() system service call to obtain the current date/time integer values, and the current date string into the already declared 8 element integer valuesArr array.
    7. If there are no arguments entered on the command line, what is returned by the get_command_argument() system service?
    8. Provide an appropriate statement to obtain the 3rd command line argument, the argument length, and a status value. You may assume the variables for the command line argument (character), named args, the length (integer), named arg3length, and the status (integer), named, arg3stat are already declared appropriately.

    Suggested Projects

    Below are some suggested projects.

    1. Type in the get date and time example program. Update the output to more clearly display only the current date and time on one line. Remove the unnecessary or redundant output.
    2. Type in the get command line arguments example program. Execute the program using a variety of different expected and unexpected arguments.
    3. Develop a program that reads command line arguments for a title and time (hours and minutes). Calculate and display the difference between the current time and the time from the command line. If the command line arguments are incomplete or incorrect, an error message should be displayed and the program, terminated. The program should use 24-hour format. One possible approach to determining the time difference would be to convert each time into minutes (from hours and minutes), compute the difference, and convert the difference in minutes back to hours and minutes. The final output should display the title, the system time, the entered time, and the time difference. All times should be displayed in hours:minutes format.
    4. Write a program to get the date from the system and display a formatted date. The formatted date should be: <day of week>, <month name> <day>, <year>. For example, 12/2/2013 should be displayed as Monday, December 2, 2013. Each string should include only the appropriate spacing. Specifically, there should be no extra spaces between the words or numbers (including the date value, 2 in the example).
      To calculate the day on which a particular date falls, the following algorithm may be used.
      Note, all variables are integers and the divisions are integer divisions.\[ a = \frac{14 - \textit{month}}{12} \nonumber \]\[ y = \textit{year} - a \nonumber \]\[ m = \textit{month} + 12 \times a - 2 \nonumber \]\[ \textit{dayNum} = \left[\textit{day} + y + \frac{y}{4} - \frac{y}{100} + \frac{y}{400} + \left(31 \times \frac{m}{12} \right) \right] \textit{mod }7\nonumber \]Where the month, day, and year variables are the integer date values (12, 2, and 2013 in the previous example). The final value of dayNum is 0 for a Sunday, 1 for a Monday, 2 for a Tuesday, and so forth with the maximum value of 6 for Saturday.
    5. Update the program from the previous question to write the formatted date to a file. The file name should be created based on the current date in the following format “file<MMDDYY>.txt” For example, for a date of 12/02/2013, the file should be named file120213.txt and contain the character string Monday, December 2, 2013.
    6. Write a program to obtain the current date and attempt to open a file based on the date in the following format, “file<MMDDYY>.txt”. For example, for a date of 12/02/2013, the file should be named file120213.txt. If the file exists, the contents should be displayed to the screen. If the file does not exist, an appropriate error message should be displayed.

    This page titled 20.3: Exercises is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Ed Jorgensen via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?