C++: IT Web

C++: IT Web

Section A: Choose either question 1 or 2 in Section A.

  1. Division by Zero Problem: Create a program titled Division. Have the program prompt the user “Enter numerator and denominator” and store the two values entered. (If you wish the user to “Enter numerator/denominator” be sure to adjust your data gathering variables to include a holder variable for the slash character.)


Include a function titled Quotient that takes 2 integers as input and provides the quotient of the 2 integers as integer output. (The remainder is truncated. Thus, 5/3 will be 1.)


Define an exception class divByZero and have the function Quotient use throw for an exception of this type if the denominator is 0. Display output “You cannot have a denominator that is equal to 0.”


Quotient throws an exception to the higher-level function main to decide whether or not the program should be terminated. Main catches the divByZero and prints out an appropriate comment on the screen. Also include in main a try block to catch the divide-by-zero error.


If no exception occurs, print out a message “The quotient is xxxxx.”

  1. Create a namespace titled globalType that contains four members. The members should be two named constants, n and rate. It should also contain a variable count and the function printResult. Describe how you would access these 4 members in a program. Do not forget to use the scope resolution operator.

Section B: Complete the entire question below in Section B.
Write a program that reads a given text file, outputs the text file as is, and also prints the number of lines and the number of times each letter appears in the text file. (To simplify things, treat uppercase letters and lowercase letters as being the same.)

  1. Create an array of 26 components to do the letter count for the 26 letters in the alphabet and a variable for the line count. (You may wish to call these variables letterCount and lineCount respectively.)
  2. Hint: Use the plan of declaring variables, opening input and output files, initializing the variables, reading and writing the character for each character in a line, incrementing the letter count, incrementing the line count, outputting line and letter counts and, finally, closing the input and output files. (You may wish to call the program outputting line and letter counts writeTotal.)
  3. Create an ASCII (or text) file that contains text that will be used as input to your program. Call this file textinput.
  4. Have the output stored in a file called textouput.
  5. Create ifstream and ofstream objects called “infile” and “outfile” respectively.
  6. Include 4 functions for initializing, copying text, counting, and writing the results to a file, respectively.
    • Initialize the initial array with 0’s.
    • Have the file copying text specifically be able to read a line and output that line. (You may wish to call this file copyText.)
    • Whenever a nonblank character is found, it calls the function that does the counting, characterCount, to update the letter count. (Do not count blank, tab, or end-of-line characters as part of the letter count.)
    • Have the characterCount function convert the letter to uppercase, find the index of the array corresponding to this letter and, if the index is valid, increment appropriate count.
    • Have the main program do the following:
      1. Declare variables.
      2. Open the input and output files.
      3. If the input file does not exist, exit the program.
      4. Open the output file.
      5. If the output file cannot open, exit the program.
      6. Initialize variables counting the lines and letters.
      7. Read the first character.
      8. Use while (not end of input file).
      9. Process the next line using the function that reads a line and outputs the line copyText.
      10. Increment the line count. (Increment the variable lineCount.)
      11. Read the next character.
      12. Output the line count and letter counts.
      13. Use writeTotal.
      14. Close files.

Remember that when you submit this assignment, you should acknowledge to your mentor that you have reviewed all programs using a C++ compiler.

Is this the question you were looking for? If so, place your order here to get started!

Related posts

New Technologies in Nursing

New Technologies in Nursing New Technologies in Nursing Introduction The current nursing technologies have transformed how nurses conduct their duties. Evidently, such technologies and new healthcare systems have endured establishing better services to patients. According to the reports of...