Homework 3 - Functions and Strings

Due: Wednesday, October 22, 2008 at 5:00pm

Name your files hw3_<problem>.cpp, such as hw3_1.cpp. Email all the cpp files to my Helios account.

  1. (5 points) This purpose of this problem is to work with function overloading. You will write several versions of functions called find_min(), get_input() and print_min(). The functions are as follows: Use the following main function for this problem:
    int main()
    {
      int num1, num2, num3;
      double dnum1, dnum2;
    
      // Two integer version
      get_input(num1, num2);
      print_min(find_min(num1, num2));
    
      // Two double version
      get_input(dnum1, dnum2);
      print_min(find_min(dnum1, dnum2));
    
      // Three integer version
      get_input(num1, num2, num3);
      print_min(find_min(num1, num2, num3));
    
      return 0;
    }
    
  2. (5 points) For this program, you will read in a name and ID number from the user and then format it when outputting it to the screen. Your program will have two functions: In main, use a do-while loop that will call get_input() then print_student() and then ask if the user wishes to enter another student's information. After reading in the first character of the user's answer, clear the input stream. So if the user types 'yes', read 'y' into a character and then remove "es" from the input stream. If you neglect this step, the remaining characters will be read in as the last name in the next iteration of the loop and points will be deducted. Exit the do-while loop when the user enters 'n' or 'N'.

  3. (10 points) Modify your simple menu program from Homework 2. The menu options will remain the same, but now each option will use a function calls instead of having all the option statements within the switch() statement. Additionally, if you did not use a do-while loop in Homework 2 for your menu, convert your menu over to use a do-while loop.
      Welcome to the CS221 Homework 3 Menu
      ====================================
      1.  Multiply two integers
      2.  Divide two integers
      3.  Check if a number is within the range 10-20
      4.  Find the minimum of a list of 3 numbers
    
      0.  Exit
      ====================================
      Enter selection:
    
    From within each case statement, there will be a void function that gets the input from the user using by-reference parameters and a second void function that takes the input as by-value parameters, does the task and prints the result to the screen. For example, the first menu item case statement would be:
      case 1:
        int a, b;
        get_input(a, b);
        do_multiply(a, b);
        break;
    
    You should have at least the following 7 void functions in your final code. More functions are fine if you wish to break each menu item task into subtasks.