CIS 150 Spring 2018 Midterm exam #1 practice problem

Objectives

  • Write proper documentation comments.
  • Create a program using proper style conventions.
  • Create a program using C++ include directives and "using" statements.
  • Create C++ function prototypes.
  • Declare variables using C++.
  • Get user input.
  • Write code to read in entire lines, including spaces and tabs.
  • Write the code needed to make cin and getline(cin, string) work properly together
  • Display output.
  • Display formatted output.
  • Create a program that does proper input validation.
  • Call functions, sending the appropriate values, and storing returned values as needed.
  • Use C math library functions.
  • Create functions to perform specified tasks.

Program requirements

  1. Write documentation comments. They must include the name of the program, the date, the course number, and your name.
  2. Use proper indentation throughout the program using four spaces per level of indent.
  3. Use spaces and NO tabs for the indentation.
  4. Write whatever include directives and using statements that your program needs.
  5. Write a function prototype for a function named reverse that takes a string and returns the reverse of that string (so "Kish" as input would get "hsiK" as output).
  6. Write a function prototype for a function named display that takes an int "n" and a string "s" and returns nothing. This function should display the string s on the console n times, with a newline after each.
  7. Declare an int variable named "num", a char named "dir", and a string named "msg".
  8. Use input validation and loop until a valid value is entered for num. The prompt should be, "Enter an integer between 1 and 10: ". Display the error message, "Error: Below minimum value of 1", or, "Error: Above maximum value of 10" if the number entered is out of range.
  9. Use an input validation loop to get a message to store in the "msg" variable. Prompt the user with, "Enter message to display: ". Keep looping until the message is a non-zero length. The message must be handled properly (all read in) even if it contains spaces.
  10. Use input validation and loop until a valid value is entered for "dir". The prompt should be, "Enter a direction (F/R): ". Display the error message, "Error: Invalid choice" if the input value is not an 'F' or 'R'.
  11. If the direction entered was 'R', then send the msg to the reverse function and store the returned results back in msg.
  12. Send num and msg to the display function to display the message num times.
  13. Display the square root of num to four decimal positions.
  14. Return a success exit status (0 means success).
  15. Write a function named reverse that takes a string argument, reverses that string and returns it.
  16. Write a function named display that takes an int and a string, and displays the string on the console the number of times specified by the int. Have each message appear on its own line. Return nothing.

Sample output run

Enter an integer between 1 and 10: -2 Error: Below minimum of 1 Enter an integer between 1 and 10: 99 Error: Above maximum of 10 Enter an integer between 1 and 10: 7 Enter message to display: Error: Message can not be zero length Enter message to display: Easy does it! Enter a direction (F/R): r !ti seod ysaE !ti seod ysaE !ti seod ysaE !ti seod ysaE !ti seod ysaE !ti seod ysaE !ti seod ysaE The square root of 7 is 2.6458