Spring CS Homework 7 p. 1. CS Homework 7

Similar documents
Spring CS Homework 6 p. 1. CS Homework 6

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

CS Fall Homework 11 p. 1. CS Homework 11

Spring CS Homework 12 p. 1. CS Homework 12

CS Homework 2 p. 1. CS Homework 2

CS Homework 11 p. 1. CS Homework 11

Spring CS Homework 3 p. 1. CS Homework 3

CS Homework 10 p. 1. CS Homework 10

CS Week 14 Lab Exercise

CS Homework 11 p. 1. CS Homework 11

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

CS Homework 10 p. 1. CS Homework 10

CS Final Exam Review Suggestions - Spring 2014

CS Exam 2 Study Suggestions

CS Final Exam Review Suggestions - Fall 2017

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Lab Session # 1 Introduction to C Language. ALQUDS University Department of Computer Engineering

Spring CS Homework 2 p. 1. CS Homework 2. To practice with PL/SQL stored procedures and functions, and possibly exception handling.

GOALS [HTDP/2e Chapters 1 through 3.5]

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

CS 150 Lab 10 Functions and Random Numbers

CS Fall Homework 5 p. 1. CS Homework 5

CS 150 Lab 3 Arithmetic and the Debugger. Lab 3.0 We are going to begin using the Visual Studio 2017 debugger to aid with debugging programs.

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Part I: Written Problems

CS 051 Homework Laboratory #2

COMP 202 Java in one week

Reviewing all Topics this term

Week 8: Operator overloading

BCIS 3630 Dr. GUYNES SPRING 2018 TUESDAY SECTION [JAN version] GRADER COURSE WEBSITE

Initial Coding Guidelines

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

CIS 130 Exam #2 Review Suggestions

CS 170 Java Programming 1. Week 5: Procedures and Functions

San José State University Department of Computer Science CS151, Section 04 Object Oriented Design Spring 2018

Part I: Written Problems

Lab 2.1: Fixing a C++ program

CMSC 201 Spring 2018 Project 2 Battleship

CS Homework 1 p. 1. CS Homework 1

Homework #2: Introduction to Images Due 4 th Week of Spring 2018 at the start of lab CSE 7, Spring 2018

Style and Submission Guide

6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world!

Join the course group CS230-S18! Post questions, answer them if you know the answer!

Lab 3. A Multi-Message Reader

Lab # 2. For today s lab:

Lab 4 CSE 7, Spring 2018 This lab is an introduction to using logical and comparison operators in Matlab.

Chapter 11-D Homework ScalaFX & Eclipse Individual Assignment 10 Points

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

OOP- 5 Stacks Individual Assignment 35 Points

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

Software and Programming 1

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

More on Arrays CS 16: Solving Problems with Computers I Lecture #13

Week 2: Data and Output

Pattern Maker Lab. 1 Preliminaries. 1.1 Writing a Python program

Introduction to Programming

Lab 9 - Classes and Objects Directions

More on Strings in C++ Arrays CS 16: Solving Problems with Computers I Lecture #11

Introduction to Programming for Biology Research

Grade 3. EDM Version 4. Everyday Math: Unit. Measurement and Geometry. Study Guide

OOP- 4 Templates & Memory Management Print Only Pages 1-5 Individual Assignment Answers To Questions 10 Points - Program 15 Points

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018

CS 142 Style Guide Grading and Details

CMSC 201 Spring 2019 Lab 06 Lists

Programming Assignment 8 ( 100 Points )

CMSC 201 Fall 2016 Homework 6 Functions

Homework 3: Relational Database Design Theory (100 points)

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

Chapter 2. The Midpoint Formula:

Claremont McKenna College Computer Science

Introduction to the C++ Programming Language

CS Problem Solving and Object-Oriented Programming

OOP-8-DLList-1-HW.docx CSCI 2320 Initials Page 1

Assignment 2: Temperature Class

COMP26120 Academic Session: Lab Exercise 2: Input/Output; Strings and Program Parameters; Error Handling

BIS1523 Homework Assignments 2.1

Physics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

LECTURE 02 INTRODUCTION TO C++

Please make sure that when you submit your assignment, you submit a single HW6.py file that contains your entire assignment.

February 8 th February 12 th. Unit 6: Polynomials & Introduction to Quadratics

Page 1 of 7. public class EmployeeAryAppletEx extends JApplet

CMSC 201 Spring 2017 Lab 01 Hello World

SUBSTITUTE EMPLOYEE WEB TIME INSTRUCTIONS

Using Eclipse and Karel

Getting started with C++ (Part 2)

coe318 Lab 1 Introduction to Netbeans and Java

Midterms Save the Dates!

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm

Welcome to Lab! Feel free to get started until we start talking! The lab document is located on the course website:

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

Self assessment due: Monday 10/29/2018 at 11:59pm (submit via Gradescope)

Chapter 11-B Homework ScalaFX & Eclipse Individual Assignment 25 Points

HW3: CS 110X C Domain Information. Final Version: 1/29/2014

For this week only, the TAs will be at the ACCEL facility, instead of their normal office hours.

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

CS 170 Java Programming 1. Week 10: Loops and Arrays

CMSC 201 Spring 2016 Homework 7 Strings and File I/O

Transcription:

Spring 2018 - CS 111 - Homework 7 p. 1 Deadline 11:59 pm on Friday, March 23, 2018 Purpose CS 111 - Homework 7 To practice with some C++ basics, including following design recipe steps for designing and writing simple C++ functions -- now using NetBeans to test and run your functions from Homework 6 -- and also designing some additional functions so you can practice using a string method and using one of your functions in another function. How to submit Submit your main.cpp file for Homework 7 on https://canvas.humboldt.edu (Remember, it is good to submit early and often!) Important notes 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). That said -- remember that, in C++: use C++ type names in the signatures of C++ functions write examples/tests as bool expressions, typically using == or <. For example, my_funct(3) == 27 abs(my_dbl(4.7) - 100.43) < 0.001...and note that these example tests are EXPRESSIONS rather than C++ statements -- do NOT end them with a semicolon! 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 indent your return statement by at least 3 spaces inside your function body! And curly braces go on their own line, lined up as shown in the posted class examples! Homework Program Setup Start NetBeans. From the File menu, select New Project.... You should see a screen that lets you select C/C++ as a Category and C/C++ Application as a Project. Do so, and click Next>.

Spring 2018 - CS 111 - Homework 7 p. 2 Type 111hw7 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.) 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 main.cpp this should open an editor window with the contents of the main.cpp file. REPLACE main.cpp's current contents with the "first main.cpp template" from the CS 111 public course web site, under "References". (You can REMOVE, or just not paste in, the very first "FIRST VERSION" comment.) See the comment that has by: and last modified:? START that comment with: CS 111 - HW 7 Then put your name after by:, and today's date after last modified:. For example: /*--- CS 111 - HW 7 by: Your Name last modified: 2018-03-12 ---*/ Problem 1 In the "first main.cpp template" you pasted into your main.cpp, find the comment: /*--- PUT YOUR SIGNATURES, PURPOSES, and FUNCTION DEFINITIONS HERE ---*/ After this comment, type a blank link, and then type the comment: Problem 1 Remember function rect_perim from Homework 6, Problem 1? Type in or paste your signature, purpose, examples/tests, function header, and function body for rect_perim. Recall the function from Homework 2, Problem 2 that returns the perimeter of a rectangle. Use the design recipe to design a C++ version of this function named rect_perim. (rect_perim expects the length and width of a rectangle, and returns the perimeter of that rectangle.) Then, in the main function, edit:

Spring 2018 - CS 111 - Homework 7 p. 3...so that it says you are testing rect_perim, and includes your examples/tests for rect_perim. Make sure rect_perim runs (Run -> Run Project), and its tests pass! You should see: *** Testing rect_perim *** of rect_perim after these tests, so that you see the value those call(s) return. Problem 2 After Problem 1's rect_perim, type a blank link, and then type the comment: Problem 2 Remember function ask_abt_day from Homework 6, Problem 2? Type in or paste your signature, purpose, examples/tests, function header, and function body for ask_abt_day. Recall the fun C++ fact also noted in the Week 7 Lab Exercise: One of the benefits of the C++ string type is that you can use + to append two string instances together -- or even a string and a char*! (At least ONE of the arguments to + has to be a string instance for this to work!) Recall the function from Homework 2, Problem 3 that asks a given person how their day is going. Use the design recipe to design a C++ version of this function named ask_abt_day. (ask_abt_day expects a person's name, and returns a customized question, How's it going,...that person's name...?, asking how their day is going. As in Homework 2, optionally, you may change the exact wording of the question, as long as it includes the person's name and ends with at least one question mark.) Then, in the main function, AFTER the tests for rect_perim, paste in and edit:...so that it says you are testing ask_abt_day, and includes your examples/tests for ask_abt_day. IMPORTANT: be careful with your expected value expression in ask_abt_day's test expressions; you cannot use + between two char* expressions. This is a case where the expected value expression likely needs to be just the hoped-for resulting literal expression, without any operations. ASK ME if you have questions about this or run into problems related to this. Make sure ask_abt_day runs (Run -> Run Project), and its tests pass! You should see: *** Testing ask_abt_day ***

Spring 2018 - CS 111 - Homework 7 p. 4 of ask_abt_day after these tests, so that you see the value those call(s) return. Problem 3 After Problem 2's ask_abt_day, type a blank link, and then type the comment: Problem 3 Remember function total_feet from Homework 6, Problem 3? Type in or paste your signature, purpose, examples/tests, named constant definition (for FEET_PER_YARD), function header, and function body for total_feet. FOR FULL CREDIT, make sure that you USE the named constant FEET_PER_YARD appropriately within total_feet's function body. Recall the function from Homework 2, Problem 5 that computes the total number of feet in a given number of yards and feet. Use the design recipe to design a C++ version of this function named total_feet. (total_feet expects a number of yards and a number of feet, and returns the total number of feet overall in both of these combined.) Then, in the main function, AFTER the tests for ask_abt_day, paste in and edit:...so that it says you are testing total_feet, and includes your examples/tests for total_feet. (remember: at least ONE of these tests should have 0 as the number of yards argument, at least ONE of these tests should have a number of yards argument greater than 1, (and each of these tests should have a different value for the number of feet argument).) Make sure total_feet runs (Run -> Run Project), and its tests pass! You should see: *** Testing total_feet *** of total_feet after these tests, so that you see the value those call(s) return. Problem 4 After Problem 3's total_feet, type a blank link, and then type the comment:

Spring 2018 - CS 111 - Homework 7 p. 5 Problem 4 Remember function order_cost from Homework 6, Problem 4? Type in or paste your signature, purpose, examples/tests, named constant definitions (for COFFEE_PRICE_PER_LB, SHIP_PRICE_PER_LB, and SHIP_COST_FIXED), function header, and function body for order_cost. FOR FULL CREDIT, make sure that you USE the named constants COFFEE_PRICE_PER_LB, SHIP_PRICE_PER_LB, and SHIP_COST_FIXED appropriately within order_cost's function body. Recall the function from Homework 2, Problem 6 that computes the total price for an order of Tasty-Waking coffee. Use the design recipe to design a C++ version of this function named order_cost. (order_cost expects the number of pounds of coffee in an order, and returns the total price of that order, including shipping) Then, in the main function, AFTER the tests for total_feet, paste in and edit:...so that it says you are testing order_cost, and includes your examples/tests for order_cost. Make sure order_cost runs (Run -> Run Project), and its tests pass! You should see: *** Testing order_cost *** of order_cost after these tests, so that you see the value those call(s) return. Problem 5 After Problem 4's order_cost, type a blank link, and then type the comment: Problem 5 Remember function cels_to_fahr from Homework 6, Problem 5? Type in or paste your signature, purpose, examples/tests, function header, and function body for cels_to_fahr. Recall the function from Homework 3, Problem 2 that computes computes the equivalent Fahrenheit temperature for a given Celsius temperature. Use the design recipe to design a C++ version of this function named cels_to_fahr. (cels_to_fahr expects a temperature given in Celsius, and returns the equivalent Fahrenheit temperature)

Spring 2018 - CS 111 - Homework 7 p. 6 Then, in the main function, AFTER the tests for order_cost, paste in and edit:...so that it says you are testing cels_to_fahr, and includes your examples/tests for cels_to_fahr. Make sure cels_to_fahr runs (Run -> Run Project), and its tests pass! You should see: *** Testing cels_to_fahr *** of cels_to_fahr after these tests, so that you see the value those call(s) return. Problem 6 After Problem 5's cels_to_fahr, type a blank link, and then type the comment: Problem 6 Now for a new function! For some more practice using a string class method: Recall, from the Week 8 Lab Exercise, that the C++ string class includes a substring method named substr, that expects a starting position and a length, and returns the string starting at that position and going that many characters in the calling string instance (or until the end of that calling string instance, whichever comes first). And, interestingly, the position of the 1st character in a string is 0! That is, for: const string CHEER = "hip, Hip, HOORAY!";...this is a expression: CHEER.substr(5, 3) == "Hip" Use the design recipe to design a C++ function monogram that expects a first name, middle name, and last name, and returns an appropriate "monogram" for that name (a string combining the initials of that first, middle, and last name). For example, monogram("ava", "Marie", "DuVernay") would return "AMD", and monogram("grace", "Murray", "Hopper") would return "GMH". Remember to include a signature, purpose, function header, examples/tests, and then completed function body for monogram. (HINT: Note that, for this particular function, you should use the string class's substr method, which returns a string, instead of the string class's at method, which returns a char.) Then, in the main function, AFTER the tests for cels_to_fahr, paste in and edit:

Spring 2018 - CS 111 - Homework 7 p. 7...so that it says you are testing monogram, and includes your examples/tests for monogram. Make sure monogram runs (Run -> Run Project), and its tests pass! You should see: *** Testing monogram *** of monogram after these tests, so that you see the value those call(s) return. Problem 7 After Problem 6's monogram, type a blank link, and then type the comment: Problem 7 Recall the Week 8, Lecture 2 example function ring_area, that called circ_area in its function body to help do its desired action. For one more new function -- and a chance to call some of the functions you designed in previous problems -- imagine that you wanted a jaunty little function casual_ask that expected a person's first name, middle name, and last name, and returns a string asking about that person's day, but using their initials instead of their name. That is, this should be a expression: casual_ask("ava", "Marie", "DuVernay") == "How's it going, AMD?" (Consider: how could you use a careful combination of monogram and ask_abt_day to get the desired result? What does monogram return? What does ask_abt_day expect?) Use the design recipe to design this C++ function casual_ask. Remember to include a signature, purpose, function header, examples/tests, and then completed function body for casual_ask. FOR FULL CREDIT, make sure that you use monogram and ask_abt_day appropriately within casual_ask's function body. Then, in the main function, AFTER the tests for monogram, paste in and edit:...so that it says you are testing casual_ask, and includes your examples/tests for casual_ask. Make sure casual_ask runs (Run -> Run Project), and its tests pass! You should see: *** Testing casual_ask *** of casual_ask after these tests, so that you see the value those call(s) return.