A4-Making Selections

Objectives

• Make use of exponential notation
• Continue using if-statements to make selections
• Start using logical operators to create more complex test conditions
• Start using simple loops

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

• You are encouraged to work with one other student of this class following the rules of Pair Programming for Homework Assignments. If you choose to pair program, there is a bonus applied.
• You may not give a copy of your code to your designated pair-programming partner if you did not develop the code together.
• You may not show your completed code to another person or look at another person's code until you complete and submit this assignment and the due date has passed, except for code you develop together with your pair-programming partner.
• You may get help from people other than your pair-programming partner if you get stuck, but only if they do not show or tell you the code to type.
• Remember that the instructor performs similarity tests on programming project submissions, and plagiarized code is usually very easy to detect.

Preparation

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

Project Specifications

Your solutions to these projects must only use techniques we have covered so far.

Programming Style

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

1. No magic numbers
2. Indentation in `while` statements and placement of curly braces
3. No tab characters in your code.

You can remove tab characters by either setting up your text editor correctly (see here) or by running a program named astyle (see here).

4. Meaningful variable names and consistent naming style (caps vs. underbars).

Project 1: Clock Logic

Clocks are used everywhere and are incorporated into many devices such as computers, phones, thermostats and televisions. Many of us set a clock, or clock app, to wake us up in the morning and to control various appliances in our homes.

Clocks have a logic all their own which we explore in this project.

Project Specifications

Keep the same filename and add to the existing code to complete the project. Leave the existing code unchanged, except as explained with comments in the code and these instructions. Include all your code in this single file.

2. Add your name and the date to the file comment block at the top of the file.
3. User input is already coded into the worksheet.

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

4. Read the comments in the worksheet file and write the code where indicated by the comments. See the Example Runs to verify the correctness of each computation.
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.
```***** Clock Logic *****

Enter the weekday number (0-6): 1
Enter the hour number (0-23): 7
Enter on-vacation status (true/false): false

***** Appliance Status *****
Lights: off
Television: off
Alarm: on
Thermostat: on
```
```***** Clock Logic *****

Enter the weekday number (0-6): 5
Enter the hour number (0-23): 20
Enter on-vacation status (true-false): false

***** Appliance Status *****
Lights: on
Television: on
Alarm: off
Thermostat: off
```
```***** Clock Logic *****

Enter the weekday number (0-6): 5
Enter the hour number (0-23): 10
Enter on-vacation status (true-false): true

***** Appliance Status *****
Lights: off
Television: off
Alarm: on
Thermostat: on
```

In the above example run, the user entered the values shown in aqua italics (for emphasis) to produce the output. Your program does NOT print the characters in aqua italics, nor does the user input appear in aqua italics. The values in (parentheses) are expected values when entering the example input.

6. After displaying the output, exit the program.
7. Submit the source code file `clocklogic.cpp` with the rest of the assignment as described in Deliverables.

Project 2: Texting to English Converter

Abbreviations, contractions, acronyms and initialisms have long been used to avoid spelling out whole words [1]. These shortened forms of words make writing easier and faster, though often harder to understand.

One such set of abbreviations became popular for texting with mobile phones and other Internet-based communication such as email and instant messaging [2][3][4]. In this project we will look at how to translate a small subset of these texting abbreviations into their full words or phrases.

Project Specifications
1. Write a program that asks the user for a single abbreviation input and translates one of the following common SMS abbreviations into their full words or phrases.
Abbr. Translation
4for
cusee you
l8late
l8rlater
m8mate
rare
uyou
uryou are
wuwhat's up?

Notice that "l8" is the letter "el" followed by an eight, NOT eighteen. The same is true for "l8r".

2. Name the source code file `sms4.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 a single word abbreviation to translate, and no other input, as shown in the Example Run.

Assume the user enters all the abbreviations in lowercase letters as shown.

4. If the word is not on the list, then simply repeat it back to the user as shown.
5. 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 correctly if the inputs are different.
```*** Abbreviation Translations ***

Input the abbreviation: Hey
Hey

Translate another abbreviation? (y/n) y

Input the abbreviation: m8
mate

Translate another abbreviation? (y/n) y

Input the abbreviation: wu
what's up?

Translate another abbreviation? (y/n) n
```

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

6. Submit the source code file `sms4.cpp` with the rest of the assignment as described in Deliverables.
Hints:

Project 3: Crazy Nuts

Encoding and decoding information can save memory space and speed transmission of data. Businesses often encode orders to reduce writing and speed up customer orders. In this project we will look at decoding orders for a nut company.

Nuts are a healthy snack. The Global Burden of Disease Study [1] calculated that eating more nuts could save 2.5 million lives each year. From another perspective, your life span may be increased by two years by eating nuts regularly [2].

Project Specifications
1. Develop a program that asks a user for a single input where the first one or two characters is a nut in the following shorthand code and the last characters are the number of ounces for the nut type.
Code Nut Variety
AAlmonds
BNBrazil Nuts
CCashews
HNHazelnuts
PPeanuts
PEPecans
PNPine Nuts
PIPistachios
WWalnuts

For example, the code for twelve ounces of Brazil Nuts is `BN12` and seven ounces of Cashews is `C7`. Notice there are no spaces between the code and quantity. The quantity can be any amount greater than or equal to zero.

2. Name the source code file `nuts.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. A single order code like: BN12 (no spaces allowed!!)
2. A 'y' or 'n' (without the quotes) for the repeat loop

Assume the user enters all the codes with UPPERCASE letters as shown.

4. Store the order code in a single `string` variable. Then use `substr()` to analyze and process the input string to print a full description of the nut order.
5. Add a `while` statement that allows the user to repeat the program by entering a 'y' (without the quotes).
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 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.
```Welcome to the Squirrel Nut Company!

Enter the nut order code: BN12
12 oz. Brazil Nuts
Another item? (y/n) y

Enter the nut order code: C7
7 oz. Cashews
Another item? (y/n) y

Enter the nut order code: XY123
We don't have that nut.
Another item? (y/n) n

We will go nuts to get you this order!!
```

In the above example run, the user entered the values shown in aqua italics (for emphasis) to produce the output. Your program does NOT print the characters in aqua italics, nor does the user input appear in aqua italics. The values in (parentheses) are expected values when entering the example input.

7. If the user enters an invalid code, display the message, "We don't have that nut." as shown in the example run.
8. Submit the source code file `nuts.cpp` with the rest of the assignment as described in Deliverables.
Hints:
• Use the `substr()` function to separate the code and quantity into separate variables.
• Remember that we can test string values with relational operators. See lesson 3.3.3: Comparing Characters and Stringss section on Comparing Strings. For example:
```string type = "P9";
if (type.substr(1, 1) < "A") {
// second digit is a number
}
```
• To check for one vs. two letter codes, test if the second character of the input string is less than "A".
• Also recall that we can always extract the last few characters of a string without knowing its length. See lesson 3.2.6: String Functions section on Extracting the Last Characters.

Extra Credit

The following are worth extra credit points:

1. Complete the assignment using pair programming with the same person for all three projects. (2 points)
2. Complete the `nuts.cpp` program with 12 or fewer relational expressions, including the test condition of the `while`-loop, and without using techniques we have not covered. (1 point)

The program must work correctly to get this extra credit.

3. Attend SI (2 points)

Make certain that your `README.txt` file describes any extra credit attempted.

Tutorial Lab

In preparation for next weeks lessons, complete the following:

1. Type the program `invtable.cpp` from the textbook on page 145 into a text editor, and then compile and run the program. Submit your working source code file to Canvas for grading using the file name `invtable.cpp`.
2. Complete the Tutorial Exercises in CodeLab 4 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 attempt by clicking the "Solution" tab.

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)

• 5: 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
• 4: 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
• 3: 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
• 2: 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
• 1: Does not compile or wrong file turned in
• 0: Not turned in or uses techniques not covered

Programming Projects Style

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

CodeLab and Other Tutorial Exercises

• Number CodeLab completed correctly / number exercises * 6 and rounded up to the nearest integer.
• -1 if the tutorial lab file does not compile
• -2 if the tutorial exercise file is not turned in

`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 A4-Making Selections. Include the following items when submitting to Canvas:

1. `README.txt` file
2. All the exercise files from Lesson 4
3. `clocklogic.cpp`
4. `sms4.cpp`
5. `nuts.cpp`
6. `invtable.cpp` from the Tutorial Lab

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 problems, you should expect little or no credit if your program does not compile and run. For more information see the Grading Criteria.

Submit all the files needed to complete your assignment at one time. 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: September 26 2018 @13:17:40