Embercode
✕
C++ Functions and ScopeQuick quiz

Refactoring

6 questions. Covers Refactoring a long main.

Questions 1 to 5 of 6

  1. 1. Put the four rules of the refactoring method in the order you follow them.

    Use the arrows to put the steps in order.

    1. 1.Compile with -Wall, run the program, and save its new output
    2. 2.Compare the new output with the saved output, and undo the change if they differ
    3. 3.Make one small change, such as moving one group of lines into a function
    4. 4.Save the output of the working program to a file before any change
  2. 2. Put the three cuts of the receipt refactor in the order the lesson makes them.

    Use the arrows to put the steps in order.

    1. 1.Step 3: pull out print_items and print_totals
    2. 2.Step 1: pull out compute_subtotal, the loop that adds up the items
    3. 3.Step 2: pull out compute_discount and compute_tax
  3. 3. In step 2, the line int tax = compute_tax(subtotal); prints Tax: 89 instead of Tax: 80. Why?
  4. 4. Why is the saved output file made from the original program, before any change, and not after each step?
  5. 5. What is wrong with this function? ``cpp int compute_tax(int taxable) { int tax = taxable * 8 / 100; } ``

3 question(s) left on this page.