A6-Loopy Programs

Table of Contents


Objectives

  • Apply counting loops to display data
  • Use indefinite loops to gather data
  • Develop the ability to find minimum and maximum values
  • Code nested loops

Academic Honesty

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, 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 5 and lesson 6.
  2. Complete the Review Exercises in CodeLab 5 and 6. 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 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 TextPad correctly (see here) or by running a program named astyle (see here).

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

Image
Image source

Project 1: Real or Fake News Detector

Fake, or hoax, news websites deliberately publish made-up stories as news, using social media to drive web traffic and amplify their effect [1]. This is a form of dishonesty known as a scam or swindle, and has been a boon for people trying to make a quick profit. Profit for fake news sites is primarily driven by online advertising revenue made mostly through Facebook and Google [2]. Both Google and Facebook have announced measures to ban web sites that show illegal or misleading content [3][4][5]. Do NOT confuse fake news with opinionated analysis from sites made on the basis of their ideologies.

For this project you are to write a program to help identify fake (made up) news. The instructor is providing you with five (5) "news" samples from the internet for testing your program. Three (3) of the samples are fake news articles and two (2) are real news articles. You must decide which are fake and which are real and write your program to identify them correctly.

Project Specifications
  1. Write a program that scans a "news" article and decides if it is real or fake. The instructor will use the following articles for testing:
    1. abc-paidprotester.txt
    2. abc-solar.txt
    3. cnn.txt
    4. nr.txt
    5. nyt-nuclear.txt
  2. The name of the source code file for this program must be realfake.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. Naming is important in programming.

  3. Your program must run from the command line using redirection of input as follows:
    ./realfake < input.txt
    

    Where input.txt is the news article file to test.

  4. Your program must print out a single word "Real" or "Fake" (without the quote marks) when run, depending on the article scanned, like this:
    ./realfake < input.txt
    Fake
    
  5. Your program must correctly output the word "Fake" on three (3) articles and "Real" on two (2) articles based on the contents of the articles.
  6. After printing the appropriate word, exit the program. Do NOT loop and run again.
  7. Submit this project with the rest of the assignment as described in Deliverables.
Hints:
  • Review lesson 6.1.6: Processing Text Input and choose a way to process text for your approach. Try processing one of the files with both looping techniques and see which one would be easier for you.
  • After viewing the output of both looping techniques, think of the if-statements you will need to find a unique word or line in each of the files. Ideally, make your detector extensible to similar "news" articles.
  • Your final program should have a single while-loop and several if-statements inside the loop.
References
  1. Snopes' Field Guide to Fake News Sites and Hoax Purveyors
  2. Facebook and Google move to kick fake news sites off their ad networks
  3. Google Advertising Policies -- Misrepresentation
  4. Facebook -- Mark Zuckerberg Post 11/18/2016
  5. News Feed FYI: Addressing Hoaxes and Fake News (Facebook)
Resources

Here are some resources to help you get started solving the problem:

These sources may or may not correctly list fake news sites. You must research and decide for yourself.

Image

Project 2: Score Tally

Tallying is way to count and classify scores, votes and other items. In this project we tally the scores of an exam to come up with the count of each grade. For deciding on the grade, use the following table.

Numerical Grade Letter Grade
Greater than or equal to 90 A
Less than 90 but greater than or equal to 80 B
Less than 80 but greater than or equal to 70 C
Less than 70 but greater than or equal to 60 D
Less than 60 F
Project Specifications
  1. Write a program to tally the number of A's, B's, C's, D's and F's based upon a list of scores entered by a user as percentages. Use the above table to decide on the grade.
  2. You must name the source code file scoretally.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. Within a loop, ask the user for a series of numerical scores, and no other input, as shown in the Example Run. Use -1 as a sentinel value to exit the tallying operation. The user may enter numbers with decimal places.
  4. After tallying the scores, display a horizontal bar chart for each letter grade as shown in the Example Run.
  5. After the bar chart, display a set of summary statistics that includes the:
    1. number of scores entered
    2. average (arithmetic mean) score
    3. highest (maximum) score
    4. lowest (minimum) score
  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.
    Score Tally App
    
    Enter a score (%) or -1 to end: 100
    Enter a score (%) or -1 to end: 97
    Enter a score (%) or -1 to end: 83
    Enter a score (%) or -1 to end: 56
    Enter a score (%) or -1 to end: 78.5
    Enter a score (%) or -1 to end: 94.5
    Enter a score (%) or -1 to end: -1
    
    Chart of Scores:
    A's: ***
    B's: *
    C's: *
    D's:
    F's: *
    
    Summary Statistics:
    Number of scores:  6
    Average score: 84.8333
    Highest score: 100
    Lowest score: 56
    

    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.

  7. After displaying the output, exit the program.
  8. Submit this project with the rest of the assignment as described in Deliverables.
Hints:

Image

Project 3: Wavy Squares

Using loops, we can draw shapes like squares, triangles and diamonds in C++. In this project, we draw a solid and hollow wavy-square side by side like the one shown in the image.

Project Specifications
  1. Write a program that displays a solid and hollow wavy-square side by side.
  2. You must name the source code file wavysquares.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 size of a side, and no other input, as shown in the Example Run.
  4. After getting the size of a side, display a solid square and a hollow square side-by-side with a single space between them, as shown in the Example Run.
  5. Make the squares "wavy" by drawing a slash "/" character in odd columns and a backslash "\" character in even columns of the square.
  6. 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 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.
    This program prints a filled and hollow wavy square.
    
    Enter the length of a side: 5
    
    /\/\/ /\/\/
    /\/\/ /   /
    /\/\/ /   /
    /\/\/ /   /
    /\/\/ /\/\/
    
    This program prints a filled and hollow wavy square.
    
    Enter the length of a side: 6
    
    /\/\/\ /\/\/\
    /\/\/\ /    \
    /\/\/\ /    \
    /\/\/\ /    \
    /\/\/\ /    \
    /\/\/\ /\/\/\
    

    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.

  7. Your program must display a correct pair of squares for any positive integer length. Do not change the characters displayed or add extra spaces.
  8. After displaying the squares, exit the program.
  9. Submit this project with the rest of the assignment as described in Deliverables.
Hints:
  • Start by reviewing the example on Drawing Squares in lesson 5.2.3: Nested Loop Example: Drawing Squares.
  • Add a second square by adding a second inner loop after the first inner loop. Between the two inner loops, display a single space.
  • For the hollow square, add an if-statement to decide when to draw a character and when to draw a space like the code in Exercise 5.2.
  • To draw "wavy" characters, use an if-statement with a modulus test condition to decide if the column is even or odd.
  • To output hard to print characters see lesson 3.2.4: Output of Hard-to-Print 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. Display fake and real for the actual fake and real news sites. (1 point)
  3. Play the extra credit game: Lightbot 1. (2 points)
    1. Requires flash installed and does NOT work on Chrome.
    2. Complete the game through level 9
    3. Record the message shown at the beginning of level 10 in your README.txt under Extra Credit.
    4. Please do not cheat. If you get stuck, just explain how far you got in the README.txt and record the message for the level you completed.
    5. If you go beyond level 9, make certain to still record the message for the beginning of level 10.
  4. Complete the following extra credit project. (2 points)

Image
Image: The Buttery Bakery

Project 4: Cake Redux

Redo the Cake Orders project from assignment 4, Project 3 keeping the same cakes and codes but with the changes that follow.

Project Specifications
  1. Redo the Cake Orders project from assignment 4, Project 3 such that the program meets all the original specifications except for the changes noted below.
  2. You must name the source code file cakeredux.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. Convert the cake quantity from a string to an integer by adapting the code from Exercise 6.1.
  4. Sum the cakes ordered and display the total cost of the entire order after each addition as shown in the example run. Assume that the cost of each cake is $34.99.
  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 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 Great Cake company!
    
    Enter the cake order code: CM12
    12 Chocolate Mint cakes
    For 12 cakes, order total: $419.88
    Order more? (y/n)) y
    
    Enter the cake order code: PC999
    999 Pumpkin Cheesecakes
    For 1011 cakes, order total: $35374.89
    Order more? (y/n)) y
    
    Enter the cake order code: T1
    1 Tiramisu cakes
    For 1012 cakes, order total: $35409.88
    Order more? (y/n)) n
    

    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.

  6. As before, assume the user enters all the codes with UPPERCASE letters as shown.
  7. Submit this project with the rest of the assignment as described in Deliverables.

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

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 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 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)

  • 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 * 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

How to Submit

Submit your assignment to Canvas, 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 with option extra credit information
  2. All the exercise files from Lesson 5 and Lesson 6
  3. realfake.cpp
  4. scoretally.cpp
  5. wavysquares.cpp
  6. Optionally, cakeredux.cpp (extra credit)

Your assignment files 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, but must resubmit all your assignment files.

Last Updated: March 21 2017 @00:13:01