Skip to main content
Engineering LibreTexts

19.3: Exercises

  • Page ID
    54386
  • \( \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. Which operation, internal read or internal write, is required to convert a character string containing a numeric value?
    2. Which operation, internal read or internal write, is required to convert a real value into a character string?
    3. Provide an appropriate statement to convert the character string sNum=“123” into an integer variable iNum. The error status should be written to the variable cvtErr. You may assume all variables are already declared and initialized.
    4. Provide an appropriate statement to convert the integer variable iNum=234 into a character string sNum. The error status should be written to the variable cvtErr. You may assume all variables are already declared and initialized.

    Suggested Projects

    Below are some suggested projects.

    1. Type in the character string to numeric values conversion example program. Update the values of the character strings with different data and verify that the program produces the correct results.
    2. Update the program from the previous question to read a series of character strings from the user, attempt conversion for each character string to a real value. If invalid, the user should be re-prompted. If valid, the sum of the values should be maintained. When the user enters a 0, the program should stop reading numbers, display the final sum, and terminate.
    3. Type in the numeric values to character string values conversion example program. Update the values of the real and integer values with different numbers and verify that the program produces the correct results.
    4. Develop a program to read a series of integer values, sum the values, and convert the final sum into a character string. The string should be concatenated with the string “The sum is ” and displayed to the terminal using a single character string variable.
    5. Write a program to prompt the user for an integer number between 100 and 999, re-prompting until a valid number is provided. When a valid number is provided, create a file name in the form of “file<number>.txt”, open/create the file, and write all numbers from 1 to the number, one per line, and close the file. For example, if 42 is entered, the file file42.txt should be created and contain the numbers 1, 2, 3, ..., 42 (one per line).

    This page titled 19.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?