Homework 11 Program Setup (with some IMPORTANT NEW STEPS!)

Similar documents
CS Fall Homework 11 p. 1. CS Homework 11

CS Homework 11 p. 1. CS Homework 11

Spring CS Homework 12 p. 1. CS Homework 12

CS Homework 10 p. 1. CS Homework 10

Spring CS Homework 7 p. 1. CS Homework 7

CS Homework 11 p. 1. CS Homework 11

Spring CS Homework 6 p. 1. CS Homework 6

CS Week 14 Lab Exercise

CS Homework 10 p. 1. CS Homework 10

Deadline. Purpose. How to submit. Important notes. CS Homework 9. CS Homework 9 p :59 pm on Friday, April 7, 2017

Spring CS Homework 3 p. 1. CS Homework 3

CS Homework 2 p. 1. CS Homework 2

CS Exam 2 Study Suggestions

EE 109 Lab 8a Conversion Experience

Call-by-Type Functions in C++ Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #5

Lab 2.1: Fixing a C++ program

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4

Week 4 EECS 183 MAXIM ALEKSA. maximal.io

CIS 130 Exam #2 Review Suggestions

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

CS 132 Exam #1 - Study Suggestions

Carleton University Department of Systems and Computer Engineering SYSC Foundations of Imperative Programming - Winter 2012

More Examples Using Functions and Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #6

Programming Assignment 3

Problem Set 1. You might want to read Chapter 12 of the course reader before attempting this problem.

Use the template below and fill in the areas in Red to complete it.

Note: The buy help from the TA for points will apply on this exam as well, so please read that carefully.

pointers + memory double x; string a; int x; main overhead int y; main overhead

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

Getting started with C++ (Part 2)

CS 31 Discussion 1A, Week 4. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m.

Homework Assignment #2 (revised)

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

Local and Global Variables

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

Assignment #1 (50 points; due 11:59 P.M.)

CS 150 Lab 10 Functions and Random Numbers

Lab Instructor : Jean Lai

CS 103 Lab - Party Like A Char Star

Object Oriented Design

Functions. CS111 Lab Queens College, CUNY Instructor: Kent Chin

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?

CSCI 111 First Midterm Exam Spring Solutions 09.05am 09.55am, Wednesday, March 14, 2018

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

Computer Science II Lecture 2 Strings, Vectors and Recursion

CS 106B, Lecture 1 Introduction to C++

Week 5: Files and Streams

The American University in Cairo Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009

C++ Lab 02 - Command Line Arguments and Strings

EE 355 Lab 4 - Party Like A Char Star

C++ basics Getting started with, and Data Types.

Declaring a 2D Array

Assignment #1 Simple C++

Function. Mathematical function and C+ + function. Input: arguments. Output: return value

CS 103 Lab 6 - Party Like A Char Star

CS 051 Homework Laboratory #2

CSCI 102L - Data Structures Midterm Exam #2 Spring 2011

Reviewing all Topics this term

Lecture 7. Log into Linux New documents posted to course webpage

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.7. User Defined Functions II

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection

Lecture 3. Input and Output. Review from last week. Variable - place to store data in memory. identified by a name should be meaningful Has a type-

CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.6

Operator overloading

Designing Loops and General Debug Pre-Defined Functions in C++ CS 16: Solving Problems with Computers I Lecture #6

Functions & Libraries

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Review. Modules. CS 151 Review #6. Sample Program 6.1a:

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

Ch 6. Functions. Example: function calls function

My First Command-Line Program

CSCI 102 Fall 2010 Exam #1

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.5. for loop and do-while loop

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

The following program computes a Calculus value, the "trapezoidal approximation of

Lab#5 Due Wednesday, February 25, at the start of class. Purpose: To develop familiarity with C++ pointer variables

COP Programming Assignment #7

Introduction to C++ Dr M.S. Colclough, research fellows, pgtas

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Week 8: Operator overloading

True or False (12 Points)

CS Final Exam Review Suggestions - Spring 2014

Carleton University Department of Systems and Computer Engineering SYSC Foundations of Imperative Programming - Winter 2012

CE221 Programming in C++ Part 1 Introduction

Pre- Defined Func-ons in C++ Review for Midterm #1

Sample Final Exam. 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc.

Chapter Four: Loops. Slides by Evan Gallagher. C++ for Everyone by Cay Horstmann Copyright 2012 by John Wiley & Sons. All rights reserved

CMSC 201 Fall 2016 Homework 6 Functions

Do not turn to the next page until the start of the exam.

(b) Write a statement that prints the length of the string s (apply appropriate function!):

Exercise: Inventing Language

Scientific Computing

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:

C++ For Science and Engineering Lecture 2

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

Transcription:

Spring 2018 - CS 111 - Homework 11 p. 1 Deadline 11:59 pm on Friday, April 27, 2018 Purpose To practice with loops, arrays, and more! How to submit CS 111 - Homework 11 Submit your main.cpp (or it may be renamed as well, as long as it ends in.cpp) file for this lab on https://canvas.humboldt.edu. (Remember, it is good to submit early and often!) (It is not REQUIRED for this homework -- but if you would LIKE to write any of the non-main functions in their own.h and.cpp files, as demonstrated with function cheer during Week 13 Lecture 2, you may! Just be sure to submit all of your lab's.h and.cpp files in that case.) Important notes IF you would like: FEEL FREE to include additional cout's of endl or spacing or headings between testing calls of different problems if you would like to have more-readable program output! You are still expected to follow the Design Recipe for all functions that you design/define. Remember, you will receive significant credit for the signature, purpose, header, and examples/tests portions of your functions. Typically you'll get at least half-credit for a correct signature, purpose, header, and examples/tests, even if your function body is not correct. (and, you'll lose at least half-credit if you omit these or do them poorly, even if your function body is correct). Be especially careful to include at least two examples/tests for every function, including at least one specific example/test for each "kind"/category of data, and (when there are boundaries) for boundaries between data. You can lose credit for not doing so. Be sure to follow class coding standards! Homework 11 Program Setup (with some IMPORTANT NEW STEPS!) Start NetBeans. From the File menu, select New Project.... Select Category of C/C++ and Project of C/C++ Application, and click Next>. Type 111hw11 in the Project Name box, and use Browse... to direct the Project Location folder to your desired location. (REMEMBER: in an HSU lab, this needs to be to the U: drive or to a flash drive.) You can rename the main.cpp file if you would like -- all other options should remain as they are. Then select "Finish". In the left-side window, expand the Source Files section, then double-click on the name of the file containing your main function this should open an editor window with the contents of that file. REPLACE its current contents with the "first main.cpp template" from the CS 111 public course web site, under "References".

Spring 2018 - CS 111 - Homework 11 p. 2 (You can REMOVE, or just not paste in, the very first "FIRST VERSION" comment.) Find the comment that has by: and last modified: START that comment with: CS 111 - HW 11 Then put your name after by:, and today's date after last modified:. For example: /*--- CS 111 - HW 11 by: Your Name last modified: 2018-04-21 ---*/ On the course Canvas site, on the Homework 11 assignment link, you will find links to some provided header and source code files for some functions you are to use in this homework assignment. ADD them to this project by doing the following: From Canvas, go to the Homework 11 assignment link, click on each of the links for each of these listed files, and DOWNLOAD each into the project folder for your project 111hw11: char_list.h char_list.cpp is_vowel.h is_vowel.cpp pig_lite.h pig_lite.cpp starline.h starline.cpp get_worth.h get_worth.cpp Now, in NetBeans, in the Project window on the left, for EACH of the following files, right-click on the Header Files folder for project 111hw11, select "Add Existing Item...", highlight THAT file from the 111hw11 folder, and click the "Select" button to add it to the header files for your project: char_list.h is_vowel.h pig_lite.h starline.h get_worth.h Then, in NetBeans, in the Project window on the left, for EACH of the following files, right-click on the Source Files folder for project 111hw11, select "Add Existing Item...", highlight THAT file from the 111hw11 folder, and click the "Select" button to add it to the source files for your project:

Spring 2018 - CS 111 - Homework 11 p. 3 char_list.cpp is_vowel.cpp pig_lite.cpp starline.cpp get_worth.cpp Now, open the file containing your main function, and where you see: #include <cstdlib> #include <iostream> #include <string> #include <cmath> using namespace std; now ADD the following #includes BEFORE the using namespace std; line as shown: #include <cstdlib> #include <iostream> #include <string> #include <cmath> #include "char_list.h" #include "is_vowel.h" #include "pig_lite.h" #include "starline.h" #include "get_worth.h" using namespace std; Now you should be able to use any of the functions provided in these files in all of the functions, including the main function, in this file! COME to office hours EARLY in the week if you would like help with the above! Problem 1 In the main function, put a blank line followed by a comment: /*=== Problem 1 ===*/ The purpose of this problem is to write a while loop that is NOT a count-controlled loop. Consider Homework 9 - Problem 2's function pig_lite, which uses is_vowel, first, and rest, and which expects a word and returns a Pig-Latin-ish version of that word. (Remember, you copied the needed files for is_vowel, first, rest, and pig_lite into your 111hw11 project as part of the Homework 11 setup above.) An interactive front end for function pig_lite might be interesting -- so, in your main function, include statements that do the following (I am giving you pseudocode for a question-controlled while loop here): ask the user to enter y if they would like to "piggify" a word read in their answer while their answer is "y", ask the user to enter a word containing NO blanks they would like to see a Pig-Latinish version of read in the word they enter print to the screen, on its own line, the result of calling pig_lite with whatever the user enters ask the user to enter y if they would like to "piggify" ANOTHER loop read in their answer

Spring 2018 - CS 111 - Homework 11 p. 4 Make sure the above runs successfully. Problem 2 Find the comment: /*--- PUT YOUR SIGNATURES, PURPOSES, and FUNCTION DEFINITIONS HERE ---*/ After this comment, type a blank link, and then type the comment: /*=== ===*/ Problem 2 Now for some for loop practice. Consider -- what would you see on-screen if you called Week 12 Lab Exercise's function starline repeatedly? Remember, starline expects a desired number of stars/asterisks, has the side-effect of outputting a line of that many asterisks to the screen, and returns the number of asterisks printed to the screen. (Also note, you copied the needed files for starline into your 111hw11 project as part of the Homework 11 setup above.) Using the design recipe, write a C++ function starbox that expects a desired number of rows and a desired number of asterisks per row, has the side-effect of printing to the screen that many rows of asterisks, each with that many asterisks per row, and returns the total number of asterisks printed out. This function must appropriately use a for loop. This function must appropriately call starline. For example, starbox(3, 5) == 15 and has the side-effect of causing the following to be printed to the screen: * * * And, starbox(4, 2) == 8 and has the side-effect of causing the following to be printed to the screen: And, since starbox has side-effects, you should write tests for starbox in your main function that include a DESCRIPTION of what side-effects should be seen, along with the hoped-for true result from comparing the actually-returned value to the expected returned value. That is, for EACH of its examples/tests: it should first print a message saying that what follows should be a box of stars with <num> rows and <num> columns, followed by true, and then put that example/test in its own separate cout statement, such that the result of that test will be printed on its own line.

Spring 2018 - CS 111 - Homework 11 p. 5 Make sure starbox runs, and its tests pass! Problem 3 After Problem 2's starbox, (before your main function), type a blank link, and then type the comment: /*=== Problem 3 ===*/ The purpose of this problem is to provide more for loop practice, along with keeping track of a running total during a loop. On Homework 9, Problem 4, one of the options was to use recursion to write a function total_worth to compute the value of a string of "coin characters". Here, you will do this task using a for loop instead. Recall that, in Homework 8, Problem 5, you wrote a function get_worth that expects a character representing a coin: 'Q' or 'q' -- quarter 'D' or 'd' -- dime 'N' or 'n' -- nickel 'C' or 'c' or 'P' or 'p' -- cent/penny...and it returns the decimal worth of that coin. (Note that you copied what you need for get_worth into your 111hw11 project as part of the Homework 11 setup above.) Also recall the string class method at, that expects the position of a desired character in that string, and returns the char at that position in the string (remembering, also, that it considers the position of the first character in the string to be position 0, not 1). Think about this -- Do you see that you could use a count-controlled for loop with this at method to do something with each char within a string? (Hint: consider Week 12 Lecture 2's function vertical, that uses a count-controlled loop and the at method to "grab" each character in a string and output it on its own line (thus outputting it in a "vertical" style).) Likewise, consider Week 12 Lecture 1's function sum_pos_ints, that shows how you can use a count-controlled loop to sum all of the integers from 1 to a given integer. NOW consider: what if you had a string whose characters were coin values? For example: "qdnncdqpn" Using the design recipe, write a function sum_worth that expects a string of coin characters, and returns the sum of the decimal worths of the coin characters in that string. For example, sum_worth("qdnncdqpn") == 0.25 +.10 +.05 +.05 +.01 +.10 +.25 +.01 +.05 sum_worth("qn") == 0.30 For full credit, sum_worth must also: appropriately call and use get_worth appropriately use a for loop Make sure you have at least the required number of tests for this function, and make sure you include them

Spring 2018 - CS 111 - Homework 11 p. 6 in the main function, also. Make sure sum_worth runs, and its tests pass! Problem 4 In the main function, after your tests of Problem 3's sum_worth, put a blank line followed by a comment: /*=== Problem 4 ===*/...followed by a blank line. This problem's purpose is simply to serve an an array warm-up -- to allow you to try creating an example array and then do something with its contents. Here are the requirements: decide on how big an array you would like -- any size larger than 5 is acceptable. Declare an appropriately-named named constant whose value is this size. decide what type of value you would like for your array to contain. declare an array of that type and size, and initialize it to values of your choice. then write a for loop to do something to/with each value in your array. You can choose -- it can be as simple as simply printing each value in the array, or something more elaborate (you can modify each value, call some function of your choice for each value, etc.) Whatever you choose, make sure it has some output/result printed to the screen. Make sure the above runs successfully. Problem 5 After Problem 3's sum_worth, (before your main function), type a blank link, and then type the comment: /*=== ===*/ Problem 5 The purpose of this problem is to write a function whose parameters include an array and its size. Consider, again, function starline, that expects the number of asterisks/stars to output, and it returns that number, but also has the side-effect of printing that many asterisks on one line to the screen (if <=0, no stars are output). You could use this to create a kind of horizontal bar chart, calling it for each of a set of values. And what is an array but a set of values? Using the design recipe, write a C++ function bar_chart that expects an array of integers and its size, returns the number of rows in the resulting bar chart (that is, the array's size...!), and has the side-effect of printing to the screen a horizontal bar chart with the help of starline, printing a line of *'s the length of each array value. This function must appropriately call starline And, it must use an appropriate for loop. For example, for:

Spring 2018 - CS 111 - Homework 11 p. 7 const int NUM_MSRS = 7; int measures[num_msrs] = {3, 1, 6, 2, 8, 4, 5}; bar_chart(measures, NUM_MSRS) == NUM_MSRS...and has the side-effect of causing the following to be printed to the screen: * * * Since bar_chart has side-effects, you should write tests for bar_chart in your main function that include a DESCRIPTION of what side-effects should be seen, along with the hoped-for true result from comparing the actually-returned value to the expected returned value. That is, for EACH of its examples/tests: it should first print a message saying that what follows should rows of stars of lengths <list them>, followed by true, and then put that example/test in its own separate cout statement, such that the result of that test will be printed on its own line. Make sure bar_chart runs, and its tests pass! Problem 6 After Problem 5's bar_chart, (before your main function), type a blank link, and then type the comment: /*=== ===*/ Problem 6 The purpose of this problem is to write another function whose parameters include an array and its size. Using the design recipe, write a C++ function how_many that expects a desired string, an array of strings, and the array's size, and returns the number of times the desired string appears in that array. It is required to appropriately use a for loop. (suggestion: during the design recipe, after making your specific examples/tests, develop pseudocode for how you figured out how many times your example string appeared in your example array -- how did you know when a match was found? how do you keep track of how many you've seen so far?) (hint: for this one there had better be more than one example call! What are the different cases you should check? But as an additional hint -- if you design it well, you can probably use the same example array for more than one example call. What should be different in those calls, then?) how_many does not have side-effects, but remember that, when you write its tests in your main function, you need to also declare and initialize at least one appropriate array to use as argument for its tests, also declaring a named constant for its size. and then you can put each example/test in its own separate cout statement, such that the result will be printed on its own line.

Spring 2018 - CS 111 - Homework 11 p. 8 Make sure how_many runs, and its tests pass!