A6-Programs With Functions

On This Page


Overview

There are three parts to this assignment:

  1. Review Exercises:

    First make sure you have completed and turned in the exercises from lesson 6. Then complete the Review Exercises in CodeLab 6. These exercises will help prepare you for the problem-solving program and should be completed first.

  2. Problem Solving Program:

    Complete the programming projects following the Program Specifications listed below.

  3. Tutorial Exercises:

    Complete the Tutorial Exercises in CodeLab 6 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.

Program Specifications

General

  1. Note that you must complete these programs either by yourself or by working with one other student of this class following the rules of Pair Programming for Homework Assignments.
  2. Remember to follow all the style rules from the last assignments, as well as the new rules we covered, including:
    1. Avoid duplicating code (see textbook page 192)
    2. Function naming conventions (See: Function Names)
    3. Indentation in functions and placement of curly braces (See: Indentation)
  3. Submit your files to Blackboard as explained in the section of this document: What to Turn In.

Counting Vowels

  1. Complete Exercise P5.3 on page 231 of the textbook.
  2. The name of the source code file for this program must be vowels.cpp and all your code must be in this file.

    Be careful of the spelling, including capitalization, as you will lose points for a misspelled name.

  3. The name of your function must be either count_vowels() or countVowels()
  4. Your program must operate like this:
    Enter a word or phrase: Mary had a little lamb
    Your input contains 6 vowels.
    
Hint: Use getline() to read the input.

Counting Words

  1. Complete Exercise P5.4 on page 231 of the textbook.
  2. The name of the source code file for this program must be words.cpp and all your code must be in this file.

    Be careful of the spelling, including capitalization, as you will lose points for a misspelled name.

  3. The name of your function must be either count_words() or countWords()
  4. Your program must operate like this:
    Enter a phrase: Mary had a little lamb
    Your input contains 5 words.
    
  5. You may assume that each word in the entered phrase is separated by a single space.
Hint: Use getline() to read the input.

Reading Doubles

  1. Complete Exercise P5.7 on page 231 of the textbook.
  2. The name of the source code file for this program must be doublefun.cpp

    Be careful of the spelling, including capitalization, as you will lose points for a misspelled name.

  3. The name of your function must be either read_double() or readDouble()
  4. Check cin for failure inside the function and recover from non-numeric input in the function.
  5. Your program must operate like this:
    Enter a floating-point number: one
    Please enter numbers only!
    Enter a floating-point number: 123.45
    You entered: 123.45
    
Hint: You may want to use a Boolean variable as discussed in lesson 5.3.7: Using Boolean Variables.

Extra Credit

The following are worth extra credit points:

  1. Complete the assignment using pair programming. (1 point)
  2. Add a function comment block for all functions in the problem solving programs. (1 point)
  3. Complete Exercise P5.5 on page 231 of the textbook. (2 points)
    1. Download the starter code from Blackboard.
    2. The name of the source code file for this program must be scramble.cpp and all your code must be in this file.
    3. Use the following header exactly for your function that scrambles words:
      string scramble(string word)
    4. Use the following algorithm for the scramble() function:

      if the word length is greater than 3
          r1 = random number between 1 and length of word - 1
          r2 = r1
          repeat while r2 equals r1
              r2 = random number between 1 and length of word - 1
          swap word[r1] with word[r2]
      return word

    5. Your program must operate like this:

      Enter a phrase followed by the Enter key and Ctrl-Z/D.
      I don't give a damn for a man that can only spell a word one way
      I d'not gvie a dman for a man taht can olny sepll a wrod one way

      Also, you can see how the program operates by downloading and running the executable file: scramble.exe.

    Hint: After you have scrambled the words you need to join them back together into one long string using concatenation. For more information on joining strings, see lesson 3.2.4: Joining Strings (Concatenation).

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

Grading Criteria

The instructor will evaluate your assignment using the following criteria. 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 course information page.

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

Problem Solving Programs (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
    • Programs works correctly but did not use functions
    • 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

Problem Solving Programs 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 * 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

What to Turn In

Submit your assignment to Blackboard, in the assignment folder that matches the name of this assignment, following the instructions for submitting homework. Include the following items for grading:

  1. README.txt file
  2. All the exercise files from Lesson 6
  3. vowels.cpp
  4. words.cpp
  5. doublefun.cpp
  6. Optionally, scramble.cpp (extra credit)

You must submit all the files needed to complete your assignment. Your assignment must work as submitted.

Home | Blackboard | Day Schedule | Eve Schedule
Syllabus | Help | FAQ's | HowTo's | Links
Last Updated: April 09 2010 @15:08:18