A2-Math and Memory

Table of Contents


Objectives

  • Start practicing C++ commands
  • Start declaring and using numerical variables
  • Obtain and store user input
  • Perform arithmetic operations to solve problems using C++.
  • Make use of modulus operators
  • Work with mathematical functions.
  • Debug errors in your code
  • Write your first complete C++ programs!

Academic Honesty

Read the Scholastic Honesty Policy and Assignment Integrity policies of the syllabus. Here are some clarifications for this particular assignment:

  • You may not show your project work to another person or look at another person's project work until you complete and submit this assignment.
  • You may get help from others if you get stuck, but only if they do not show or tell you what to type.
  • Remember that the instructor performs similarity tests on programming project submissions, and copied or plagiarized code is very easy to detect.

This is a solo assignment.

Preparation

  1. Make sure you have completed the exercises from lesson 2.
  2. Complete the Review Exercises in CodeLab 2. These exercises will help prepare you for the problem-solving program and should be completed first.

Project Specifications

Note that these are solo programming projects and not pair-programming projects. Your solutions to these project must only use techniques we have covered so far.

Programming Style

For all programs, remember to follow all the style rules we covered including:

  1. File block comments.
  2. Placement of curly braces and indentation within curly braces.
  3. Limiting line length to about 80 characters.

    TextPad, and most other text editors, tell you both the line and column location, which lets you check the line length.

  4. Spaces before and after operators.

Image
Image source: Ed Parrish

Project 1: Math Worksheet

Use this worksheet to improve your understanding of how to convert math equations to C++ code. Refer to lesson 2 for more information on C++ maths.

For this worksheet, the user enters three numbers. You write code to display the value of the equations listed below.

Project Specifications
  1. Start by downloading the worksheet: mathwork.cpp.

    Add to the existing code to complete the project. Leave the existing code unchanged, except for comments.

  2. You must name the source code file that you turn in mathwork.cpp and include all your code in this single file.

    Be careful of the spelling, including capitalization, as you will lose points for a misspelled name. Naming is important in programming.

  3. Add your name and the date to the file comment block at the top of the file where shown in the comments.
  4. User input is already coded into the worksheet.

    Do not add any other input commands or change the input order.

  5. Convert each of the following equations to C++ code in the worksheet. The letter `x` represents the expression.
    1. Summation means to add up a sequence of numbers. For expression 1, use the following formula to the sum all the inputs.

      x = a + b + c

      Where `a`, `b` and `c` are the user input.

      Code this equation in the mathwork.cpp program where indicated in the comments. See the Example Run to verify correctness.

    2. For expression 2, calculate the degrees in Celsius using the following formula, assuming the first value entered by the user, `a`, is the degrees in Fahrenheit. Code this equation in the mathwork.cpp program where indicated in the comments. See the Example Run to verify correctness.

      Celsius = 5/9 * Fahrenheit

      Where `a` is the user input

    3. For expression 3, calculate the value using the following formula.

      x = (a - b)(a - b)

      Where `a` and `b` are the user input.

      Code this equation in the mathwork.cpp program where indicated in the comments. See the Example Run to verify correctness.

    4. For expression 4, calculate the value using the following formula.

      x = a · (1 - b^c) / (1 - b)

      Where `a`, `b` and `c` are the user input.

      Code this equation in the mathwork.cpp program where indicated in the comments. See the Example Run to verify correctness.

    5. For expression 5, calculate the value of the formula shown below.

      x = (-b + √(b^2 - 4ac)) / (2a)

      Where `a`, `b` and `c` are the user input.

      Code this equation in the mathwork.cpp program where indicated in the comments. See the Example Run to verify correctness.

  6. Example Run: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and exact wording of the output. For the input shown you must get the same output. However, the output must change properly if the inputs are different.
    ***Math Worksheet***
    Enter three numbers separated by spaces, and press the Enter key
    For example: 1 4 2[Enter]: 1 4 2
    
    You entered: a = 1, b = 4, c = 2
    Parenthesis below show correct results for example numbers.
    
    Expression1 (7): 7
    Expression2 (-17.2222): -17.2222
    Expression3 (9): 9
    Expression4 (5): 5
    Expression5 (-0.585786): -0.585786
    
    ***Math Worksheet***
    Enter three numbers separated by spaces, and press the Enter key
    For example: 1 4 2[Enter]:  10 20 1
    
    You entered: a = 10, b = 20, c = 3
    Parenthesis below show correct results for example numbers.
    
    Expression1 (7): 33
    Expression2 (-17.2222): -12.2222
    Expression3 (9): 100
    Expression4 (5): 4210
    Expression5 (-0.585786): -0.16334
    

    In the above example runs, the user entered the values shown in italics (for emphasis) to produce the output. Your program does NOT print the characters in italics, nor does the user input appear in italics. The numbers in parenthesis show the result using the example values.

  7. Display the output using the default formatting and precision for the numbers -- do NOT add any formatting statements to the code.
  8. After displaying the output, exit the program.
  9. Submit the source code file mathwork.cpp with the rest of the assignment as described in Deliverables.

Units of Length
Image source

Project 2: Distances in Whole Numbers

In the United States we use the system of measurement known as the United States customary units [1]. These units were developed from English units as used in the British Empire before the U.S. became an independent country.

Customary units are primarily used in commercial activities, as well as for personal and social use. Metric units are most often used in science and engineering, though Mechanical Engineering still often uses both customary and metric units [2].

In this project we convert from integer inches to miles, feet, yards and inches all expressed as whole numbers.

Project Specifications
  1. Write a program that asks the user for an input in inches and displays the same distance as integer miles, feet, yards and inches. The miles, yards, feet and inches must collectively add up to the same distance.

    For example 37 inches is: 0 miles, 1 yard, 0 feet and 1 inch.

  2. Name the source code file distances.cpp and include all your code in this single file.

    Be careful of the spelling, including capitalization, as you will lose points for a misspelled name. Naming is important in programming.

  3. Ask the user for the number of inches (integer), and no other input, as shown in the Example Run. Assume the user enters only whole numbers.
  4. Display all numbers as whole numbers [3] with no decimal or fractional parts.
  5. Example Runs: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and exact wording of the output. For the input shown you must get the same output. However, the output must change properly if the inputs are different.
    Enter number of inches: 37
    In whole numbers: 0 miles, 1 yards, 0 feet, and 1 inches.
    
    Enter number of inches: 1234567
    In whole numbers: 19 miles, 853 yards, 1 feet, and 7 inches.
    

    In the above example runs, the user entered the values shown in italics (for emphasis) to produce the output. Your program does NOT print the characters in italics, nor does the user input appear in italics. The output must include labels after the number as shown.

  6. The plurality of the labels may not match the numbers, which is fine.

    We will learn how to correct this problem when we learn if-statements. However, do not use if-statements, or any conditional statements, in this program

  7. After displaying the output, exit the program.
  8. Submit the source code file distances.cpp with the rest of the assignment as described in Deliverables.
Hints:
  • After converting to a unit like miles, take the remainder for conversion of the next lower unit. See lesson 2.3.4 for an example.
References and More Information
  1. United States customary units
  2. Imperial and US customary measurement systems
  3. Whole Numbers and Integers

Smiley face yard
Image source

Project 3: Mowing Quotes

Your friend is starting a gardening business to mow lawns as a way to help pay for living expenses while going to school. He needs a good way of estimating how much to charge for his services. Here is how he has decided to charge for his work:

  • He's going to charge $12.75 for travel time, no matter how much time it takes him to get to the house.
  • He's going to charge $25.00 per hour he spends cutting the lawn; and his estimates will be based on cutting 2500 square feet (SF) of lawn per hour.
  • He has decided he will round up the estimated number of hours for a job. For example, if someone has a 30 feet by 90 feet lawn (2700 SF), he'll estimate that it's a 2 hour job; but a 2500 SF lawn would only be a 1 hour job.
  • Because he's starting out, he's going to give a 10% discount to all his clients. This discount will apply to both travel time, and to the cost of cutting the lawn.
  • Finally, he needs to charge tax, which is currently 15.3% [1] Tax is applied after the 10% discount is given to the sum of travel cost and mowing cost.
Project Specifications
  1. Write a program to calculate and print a mowing quote for a specific lawn.
  2. Name the source code file mowing.cpp and include all your code in this single file.

    Be careful of the spelling, including capitalization, as you will lose points for a misspelled name. Naming is important in programming.

  3. Ask the user for the following inputs (and no other input) in this order as shown in the Example Run below:
    1. width
    2. height

    Assume the user enters only valid numbers.

  4. Numbers may not display with exactly two decimal places, which is fine. Display the output using the default formatting and precision for the numbers - do NOT add any formatting statements to the code.
  5. Display the number of hours for mowing before the estimate as shown in the Example Run below.
  6. Example Run: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and exact wording of the output. For the input shown you must get the same output. However, the output must change properly if the inputs are different.
    Enter the size of the lawn (width x height) in feet
    47.5 67
    To cut a lawn 47.5 by 67 will take 2 hours.
    
    Estimate:
    =========
    Cutting (2H)    $50
    Travel Cost     $12.75
                    --------
    Subtotal        $62.75
    Discount (10%)  - $6.275
    Tax (15.3%)     + $8.64067
                    ========
    Total Owing:    $65.1157
    

    In the above example run, the user entered the values shown in italics (for emphasis) to produce the output. Your program does NOT print the characters in italics, nor does the user input appear in italics. Remember to include the $ (dollar sign) characters.

  7. The output must line up nicely as shown in the Example Run.
  8. After displaying the output, exit the program.
  9. Submit the source code file mowing.cpp with the rest of the assignment as described in Deliverables.
Hints:
  • Calculating a tax of 15.3% is the same as multiplying by 0.153
  • To round up use the ceil() math function from lesson 2.3.5.
  • Print "\t" (inside quotes) before the gap shown in the Example Run to line up the output.
References and More Information
  1. Independent Contractors Must Pay Self-Employment Taxes: for Social Security and Medicare

Image
Image source

Project 4: Pair Programming Worksheet

Pair programming is where two programmers work together at one computer to develop code projects. One, the driver, writes code while the other, the observer or navigator,[1] reviews each line of code as it is typed in. The two programmers switch roles frequently [1]. Students generally have higher confidence in their work and perform better when pair programming [2]. These effects were tested at Cabrillo College among other places [3].

Programming can be beneficial, but following certain guidelines is important to maximize success [4][5]. This project introduces you to the concepts and best practices of pair programming for our course programming projects.

Project Specifications
  1. Watch the video Introduction to Pair Programming, a professionally developed video (10 minutes).
  2. Save this Pair Programming Worksheet following the menu File > Download as > Plain Text (.txt), and save the file as pairprogramming.txt.
  3. Fill out and answer the questions in pairprogramming.txt without deleting any of the existing text.
  4. Submit the pairprogramming.txt file with the rest of the assignment as described in Deliverables.
  5. For reference, here is a link to the The Rules of Pair Programming
References and More Information
  1. Pair programming: Wikipedia article
  2. The effects of pair-programming on performance in an introductory programming course.
  3. Pair Programming (Case Study 1)
  4. The Rules of Pair Programming
  5. All I Really Need to Know about Pair Programming I Learned in Kindergarten: Good suggestions on how to program in pairs.

Extra Credit

Completing the following is worth the extra credit points shown in parenthesis.

  1. Add an additional interesting and useful math equation derived from mathworks.cpp making use of all three of the variables and a math function. (1 point for completing with a math function and 1 point for interest and usefulness.)
    1. Submit the source code with the extra math equation in a file named xcmathwork.cpp.
    2. Describe what the equation is used for in your README.txt file.
    3. Include the data input section of the original mathwork.cpp file.
    4. Follow the format of the previous equations by assigning the solution to the variable `x`.
    5. Follow the output of the previous equations by labeling the equation with a cout statement displaying the label Equation6 followed by the value assigned to (`x`) when entering the example values 1 4 2 and then the equation result itself, like:
    6. Equation6 (42): 42
      Equation6 (42): 210
  2. Look up constant variables in the textbook (p.39) and declare and use constants integers in distances.cpp for all the following values: (1 point)
    1. Inches per mile
    2. Inches per yard
    3. Inches per foot

    This extra credit will require three (3) constant variables minimum, one for each value. Your program must use the constant variables in place of their numbers in the equations.

  3. Look up constant variables in the textbook (p.39) and declare and use constant variables in mowing.cpp for all the following values: (1 point)
    1. travel cost
    2. square feet of lawn cut per hour
    3. cost per hour
    4. discount rate
    5. tax rate

    This extra credit will require five (5) constant variables minimum, one for each value. Your program must use the constant variables in place of their numbers in the equations.

Make sure to list the extra credit you complete in the README.txt file.

Tutorial Lab

In preparation for next weeks lessons, complete the following:

  1. Read the assigned reading in the textbook
  2. Complete the Tutorial Exercises in CodeLab 2 before the specified due date.

    Refer to the assigned reading for the next lesson to help you understand the problems. Also, you can use the online lecture notes for more information as the notes become available. You can look at solutions if you miss your first few attempts and are stuck by clicking the "Solution" tab.

Grading Criteria

The instructor will evaluate your assignment using the following criteria. Thus you should check your assignment against these criteria to maximize your score.

Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive. Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.

For information on grading policies, including interpretation of scores, see the syllabus.

Lesson Exercises

  • 2: All lesson exercises attempted and turned in
  • 1: Some lesson exercises completed and turned in
  • 0: No lesson exercises completed or turned in

Programming Projects (x3)

  • 4: Demonstrates mastery of the program
    • Applies concepts from the lessons appropriately
    • Meets all specifications (see above)
    • Runs to completion with no abnormal error conditions
    • Generates correct output given correct input
    • Correct file name
  • 3: Has most of the functionality expected of the program
    • Demonstrates some techniques from the lesson
    • Attempts to meet all but one of the specifications (see above)
    • Implementation seems more complicated than necessary.
    • May have one minor error
  • 2: Has some of the functionality expected of the program
    • Demonstrates some techniques from the lesson
    • Attempts to meet at least 1/2 of the specifications (see above)
    • Implementation seems excessively complicated.
    • May have 2-3 minor errors
  • 1: Serious functional problems but shows some effort and understanding
    • Attempts to meet less than 1/2 of the of the specifications (see above)
    • Has a major error or many minor errors
    • Implementation seems very convoluted
    • Demonstrates few techniques from the lesson
  • 0: Not turned in or uses techniques not covered

Pair Programming Worksheet

  • 4: Student completed and submitted the learning worksheet with masterful effort
  • 3: Student completed and submitted the learning worksheet with substantial effort
  • 2: Student completed and submitted the learning worksheet with minimal effort
  • 1: Student submitted the learning worksheet
  • 0: No learning worksheet submitted

Programming Style

  • 2: Code is well-documented including:
  • 1: Code has some documentation errors
  • 0: No apparent attempt to follow documentation standards or write documentation comments

CodeLab Exercises

Number completed correctly / number exercises * 8 and rounded up to the nearest integer.

README.txt File

  • 2: README.txt file submitted following the instructions
  • 1: README.txt file submitted but some information was missing
  • 0: No README.txt file submitted

Total possible: 30, plus extra credit

Deliverables

Students submit some homework as they work on it like CodeLab. However, students must submit other homework in Canvas following the link to A2-Math and Memory. For detailed instructions see: How To Submit Homework Assignments. Include the following items when submitting to Canvas:

  1. README.txt file prepared by following the instructions for submitting homework.
  2. All the exercise files from Lesson 2
    • hellome.cpp
    • syntax.txt
    • variables.cpp
    • arithmetic.cpp
    • errors.txt
    • erroneous.cpp
  3. mathwork.cpp
  4. distances.cpp
  5. mowing.cpp
  6. pairprogramming.txt
  7. Optionally, xcmathwork.cpp (extra credit)

Note: Make certain your programs compile before you turn them in. When a program does not compile then it does not function either. For all programming projects, you should expect little or no credit if your program does not compile and run. For more information see the Grading Criteria.

You must submit all the files needed to complete your assignment together. Your assignment must work as submitted. Remember to test and double check your files before submitting them. If you make a mistake, you can resubmit up to the deadline. If you resubmit, you must include all your assignment files in the last submission as Canvas hides prior submissions.

Last Updated: March 08 2018 @01:23:44