ECS 30 Homework #3 (47 points) Fall Programming (45 points)

Similar documents
Fantasy Baseball Filename: baseball

This test shall be carried out on all vehicles equipped with open type traction batteries.

Getting Started with the LabVIEW Toolkit for LEGO MINDSTORMS NXT

Iteration: while, for, do while, Reading Input with Sentinels and User-defined Functions

Digital Level Control One and Two Loops Proportional and Integral Control Single-Loop and Cascade Control

of 6. Module 5 Ratios, Rates, & Proportions Section 5.1: Ratios and Rates MAT001 MODULE 5 RATIOS, RATES, & PROPORTIONS.

Pegas 4000 MF Gas Mixer InstructionManual Columbus Instruments

NCSS Statistical Software

Summer Calendar for Rising 7 th Grade Students

2012 CALIFORNIA PHYSICAL FITNESS TEST. e-template REFERENCE GUIDE

ASVAB Arithmetic Reasoning

Flow Vision I MX Gas Blending Station

2015 FHSPS Playoff May 16, 2015 Online

Chapter 2 - Displaying and Describing Categorical Data

Chapter 3 - Displaying and Describing Categorical Data

Technical Data Sheet MF010-O-LC

ORF 201 Computer Methods in Problem Solving. Final Project: Dynamic Programming Optimal Sailing Strategies

Final Exam review Course II

Speed Controller ADR 40 Condensing pressure controller SPEED REGULATORS FOR ASYNCHRONOUS SINGLE PHASE MOTORS SERIES ADR 40 ADR 40 ADR 40 PP

Table of Contents. 1 Command Summary...1

Courseware Sample F0

Overview 1. Handicap Overview 12. Types of Handicapping...12 The Handicap Cycle...12 Calculating handicaps...13 Handicap Nomenclature...

Laboratory 2(a): Interfacing WiiMote. Authors: Jeff C. Jensen (National Instruments) Trung N. Tran (National Instruments)

Which linear equation can be used to find x, the additional hourly parking rate? 1) 2) 3) 4)

Histogram. Collection

Active and Green: Healthy Communities Are Sustainable Communities

Scoreboard Operator s Instructions MPC Control

STT 315 Section /19/2014

REASONS FOR THE DEVELOPMENT

Deer Population Student Guide

Computer Integrated Manufacturing (PLTW) TEKS/LINKS Student Objectives One Credit

Valuing Beach Closures: An Application to the Texas Gulf Coast

Background Information. Project Instructions. Problem Statement. EXAM REVIEW PROJECT Microsoft Excel Review Baseball Hall of Fame Problem

2016 American Academy of Actuaries. All rights reserved. May not be reproduced without express permission. ADDITIONAL LIABILITY ASSUMPTION OVERVIEW

WOMEN S NINE HOLE GOLF ASSOCIATION

Valuing Beach Closures in Damage Assessment: An Application to the Texas Gulf Coast

Cover Page for Lab Report Group Portion. Head Losses in Pipes

ROSE-HULMAN INSTITUTE OF TECHNOLOGY Department of Mechanical Engineering. Mini-project 3 Tennis ball launcher

Control System Nur Istianah-THP-FTP-UB-2014

Signal Spacing A Technical Memorandum Prepared by

LEARNING OBJECTIVES. Overview of Lesson. guided practice Teacher: anticipates, monitors, selects, sequences, and connects student work

Operating instructions Safety Rope Emergency Stop Switches ZB0052 / ZB0053 ZB0072 / ZB0073

The ICC Duckworth-Lewis-Stern calculator. DLS Edition 2016

METHOD 25A - DETERMINATION OF TOTAL GASEOUS ORGANIC CONCENTRATION USING A FLAME IONIZATION ANALYZER

Newton s Triple Play Explore

- 2 - Companion Web Site. Back Cover. Synopsis

MP-70/50 Series Scoreboard Controller User Guide

Diagnosis of Fuel Evaporative System

Project 1 Those amazing Red Sox!

Mac Software Manual for FITstep Pro Version 2

This addendum describes the back pressure control implementation if FuelCell Version 4.1a and later.

AN31E Application Note

Elimination of Percent Level H 2 S Calibration Gas from Flare Gas Monitoring Systems Measuring Total Sulfur, H 2 S and BTU.

CALCULATING THE SPEED OF SOUND IN NATURAL GAS USING AGA REPORT NO Walnut Lake Rd th Street Houston TX Garner, IA 50438

Cover Page for Lab Report Group Portion. Pump Performance

(a) PICK 3 is a Draw lottery game (also known as an online lottery game) in which a player selects any threedigit

Microsoft Windows Software Manual for FITstep Stream Version 4

Pythagorean Theorem in Sports

Topic 1 Place Value. Name. Test Date

(a) PICK 5 is a Draw lottery game (also known as an online lottery game) in which a player selects any five-digit

Level 3 Cambridge Technical in Engineering 05822/05823/05824/05825/05873 Unit 3: Principles of mechanical engineering

MATH 118 Chapter 5 Sample Exam By: Maan Omran

THE NORMAL DISTRIBUTION COMMON CORE ALGEBRA II

Body Stabilization of PDW toward Humanoid Walking

Computer Practical: Gaussian Plume Model Paul Connolly, October 2017

Solution Manual Computer Math Problem Solving for Information Technology 2nd Edition Charles Marchant Reeder

UNIT 10 - GASES. Notes & Worksheets - Honors

Safety Manual VEGAVIB series 60

CHEMICAL ENGINEERING LABORATORY CHEG 239W. Control of a Steam-Heated Mixing Tank with a Pneumatic Process Controller

CHAPTER 1 ORGANIZATION OF DATA SETS

ME 200 Thermodynamics I Spring 2010 (Last) (First) Thermo Number: CIRCLE YOUR LECTURE BELOW

EXPERIMENT XI. Careful!! Improper handling of the vacuum line may result in the release of SO 2 which is an irritating and suffocating gas.

Behavior of Gases Chapter 12 Assignment & Problem Set

Potchefstroom Technical High School

Particularly with regard to CHAPTER 5 MEASURES TO BE TAKEN AGAINST AIR POLLUTION CAUSED BY TWO OR THREE- WHEEL MOTOR VEHICLES

2. Use the following information to find your course average in Mr. Tats class: Homework {83, 92, 95, 90}

(a) PICK 2 is a draw lottery game (also known as an online lottery game) in which a player selects any twodigit

YSC-8330 USER MANUAL XI AN TYPICAL INDUSTRIES CO.,LTD.

Safety Manual OPTISWITCH series relay (DPDT)

Computer Scorekeeping Procedures Page 1

Motion, Forces, and Energy Revision (Chapters 3+4)

Business Cycles. Chris Edmond NYU Stern. Spring 2007

Homework Exercises Problem Set 1 (chapter 2)

Essentials. Week by. Week. Investigations

Experiment. THE RELATIONSHIP BETWEEN VOLUME AND TEMPERATURE, i.e.,charles Law. By Dale A. Hammond, PhD, Brigham Young University Hawaii

Team Manager's Manual

CERTIFICATES OF COMPETENCY IN THE MERCHANT NAVY MARINE ENGINEER OFFICER

SCRATCH CHALLENGE #3

1. If x represents a number, six ubtracted from four times the number can be represented by

General Specifications

ADVANCED. CATIA V5 Workbook. Knowledgeware and Workbenches. Release 16. Knowledgeware. Workbenches. Richard Cozzens. Southern Utah University

Software Manual for FITstep Pro Version 2

Over 20,000 Strain Gage Target flowmeters installed since 1952.

General Specifications

Project Title: Pneumatic Exercise Machine

Public Opinion, Traffic Performance, the Environment, and Safety After Construction of Double-Lane Roundabouts

All AQA Unit 1 Questions Higher

CHAPTER 16 %UHDWKLQJ*DV0L[LQJ3URFHGXUHV

LOW PRESSURE EFFUSION OF GASES adapted by Luke Hanley and Mike Trenary

Ranger Walking Initiation Stephanie Schneider 5/15/2012 Final Report for Cornell Ranger Research

Transcription:

ECS 30 Homework #3 (47 points) Fall 2013 Due: Wednesday, October 23 rd. Written: 4pm in 2131 Kemper. Programs: 11:59pm using handin to cs30 p3 directory. Filenames: weight.c, quadrant.c, emissions.c, wireless.c, bread.c., baseball.c Written (2 points): pp. 229-230: 5, 6 #5. Write an if statement that displays an acceptance message for an astronaut candidate if the person s weight is between the values of opt_min and opt_max inclusive, the person s age is between age_min and age_max inclusive, and the person is a nonsmoker (smoker is false). #6 Implement the flow diagram in Fig. 4.14 using a nested if structure. Programming (45 points) All programs should be able to compile with no warnings when compiled with the Wall option. You should put your name(s) in a comment on the first line of each file. The prompts, and output format of each program must match the examples exactly. You will find my executables in ~ssdavis/30/p3 in the CSIF. Remember to a blank line before and after each unindented if statement. 1. p. 231 #2 (5 points, 5 minutes) Filename: weight.c Write a program that calculates the user s body mass index (BMI) and categorizes it as underweight, normal, overweight, or obese, based on the table from the United States Centers for Disease Control: BMI Weight Status Below 18.5 Underwight 18.5 24.9 Normal 25.0-29.9 Overweight 30.0 and above Obese To calculate BMI based on weight in pounds (wt_lb) and height in inches (ht_in), use this formula (rounded to tenths): BMI = 703 wt_lb ht_in2 Prompt the user to enter weight in pounds and height in inches. ssdavis@lect1 p3]$ weight.out Please enter your weight in whole pounds: 110 Please enter your height in whole inches: 60 You have a BMI of 21.5, and your weight status is normal. weight.out Please enter your weight in whole pounds: 95 Please enter your height in whole inches: 61 You have a BMI of 17.9, and your weight status is underweight. weight.out Please enter your weight in whole pounds: 180 Please enter your height in whole inches: 69 You have a BMI of 26.6, and your weight status is overweight. weight.out Please enter your weight in whole pounds: 223 Please enter your height in whole inches: 70 You have a BMI of 32.0, and your weight status is obese. 2. p. 232 #6 (5 points, 8 minutes) Filename quadrant.c Write a program that takes the x-y coordinates of a point in the Cartesian plane and prints a message telling either an axis on which the point lies of the quadrant in which it is found. QII y QI x QIII QIV

ssdavis@lect1 p3]$ quadrant.out Please enter the x and y coordinates: -1.0-2.5 (-1.0, -2.5) is in quadrant III quadrant.out Please enter the x and y coordinates: 0.0 4.8 (0.0, 4.8) is on the y axis quadrant.out Please enter the x and y coordinates: 43.2 57.1 (43.2, 57.1) is in quadrant I quadrant.out Please enter the x and y coordinates: 93.5 0.0 (93.5, 0.0) is on the x axis quadrant.out Please enter the x and y coordinates: 0.0 0.0 (0.0, 0.0) is the origin quadrant.out Please enter the x and y coordinates: -33 47 (-33.0, 47.0) is in quadrant II quadrant.out Please enter the x and y coordinates: 3.9-12 (3.9, -12.0) is in quadrant IV 3. p. 233 #8 (5 points, 7 minutes) Filename: emissions.c Write a program that interacts with the user like this: (1) Carbon monoxide (2) Hydrocarbons (3) Nitrogen oxides (4) Nonmethane hydrocarbons Enter pollutant number>> 2 Enter number of grams emitted per mile>> 0.35 Enter odometer reading>> 40112 Emissions exceed permitted level of 0.31 grams/mile. Use the table of emissions limits below to determine the appropriate message. 1 First 50,000 Miles Second 50,000 Miles Carbon monoxide 3.4 grams/mile 4.2 grams/mile Hydrocarbons 0.31 grams/mile 0.39 grams/mile Nitrogen oxides 0.4 grams/mile 0.5 grams/mile Nonmethane hydrocarbons 0.25 grams/mile 0.31 grams/mile emissions.out (1) Carbon monoxide (2) Hydrocarbons (3) Nitrogen oxides (4) Nonmethane hydrocarbons Enter pollutant number>> 3 Enter number of grams emitted per mile>> 0.45 Enter odometer reading>> 63987 Emissions do not exceed permitted level of 0.50 grams/mile. 1 Adapted from Joseph Priest, Energy: Principles, Problems, Alternatives (Reading, MA.: Addison-Wesley, 1991), p. 164. 4. p. 233 #9 (10 points, 17 minutes) Filename: wireless.c Chatflow Wireless offers customers 600 weekday minutes for a flat rate of 39.99. Night (8pm to 7am) and weekend minutes are free, but additional weekday minutes cost 0.40 each. There are taxes of 5.25% on all charges. Write a program that prompts the user to enter the number of weekday minutes, night minutes, and weekend minutes used, and calculates the monthly bill and average cost of a minute before taxes. The program should display the taxes, and the total bill. Store all monetary values as whole cents (rounding the taxes and average minute cost), and divide by 100 for display of results.

Additional specification: You must use constant macros for all constants given in the above paragraph. You should store 39.99 and 0.40 as cents rather than dollars. Note that since you are dividing by 100, and not 100.0, you will have to cast your int variables to doubles in your printf statements before dividing by CENTS_PER_DOLLAR. Read more about casting on pp. 76-77. Since you have been asked to round the taxes and average cost, and converting from doubles to ints simply truncates, you will need to add 0.5 to produce the desired integer value, where x is a double. wireless.out Please enter the number of weekday minutes, night minutes: 600 50 Please enter the number of weekend minutes: 150 Weekday minutes: 600, night minutes: 50, weekend minutes: 150 Average minute cost: $0.05 Pretax bill: $ 39.99 Taxes: $ 2.10 Total bill: $ 42.09 wireless.out Please enter the number of weekday minutes, night minutes: 2348 1221 Please enter the number of weekend minutes: 348 Weekday minutes: 2348, night minutes: 1221, weekend minutes: 348 Average minute cost: $0.19 Pretax bill: $739.19 Taxes: $ 38.81 Total bill: $778.00 wireless.out Please enter the number of weekday minutes, night minutes: 1328 47 Please enter the number of weekend minutes: 147 Weekday minutes: 1328, night minutes: 47, weekend minutes: 147 Average minute cost: $0.22 Pretax bill: $331.19 Taxes: $ 17.39 Total bill: $348.58 5. pp. 233-234 #10 (15 points, 25 minutes) Filename bread.c Write a program to control a bread machine. Allow the user to input the type of bread as W for White, and S for Sweet. Ask the user if the loaf size is double, and if the baking is manual. The following table details the time chart for the machine for each bread type. Display a statement for each step. If the loaf size is double, increase the baking time by 50 percent. If baking is manual, stop after the loaf-shaping cycle and instruct the user to remove the dough for manual baking. Use functions to display instructions to the user and to compute the baking time. Bread Time Chart Operation White Bread Sweet Bread Primary kneading 15 mins 20 mins Primary rising 60 mins 60 mins Secondary kneading 18 mins 33 mins Secondary rising 20 mins 30 mins Loaf shaping 2 seconds 2 seconds Final rising 75 mins 75 mins Baking 45 mins 35 mins Cooling 30 mins 30 mins Additional specifications: All three input variables must be chars. The user may enter either capital or lowercase letters, but will not enter invalid letters. The display_instructions() function will NOT calculate the total baking time.

The calc_baking_time will compute and print the total baking time. You should read the section on Undetected Errors on pp. 95-98 before writing your scanf() calls. For debugging, I recommend that you add the line printf("%c %c %c\n", type, loaf_size, manual); after your scanfs() to ensure that their values are correct. Extra credit (5 points): My calc_baking_time function uses only five ifs. If you can write a calc_baking_time function that uses five or fewer ifs (without using a switch statement), then you will earn five points extra credit. bread.out Are you making white or sweet bread (w or s)? w Is this a single or double loaf (s or d)? S Are you going to bake manually (y or n)? y Primary kneading: 15 minutes Secondary kneading: 18 minutes Secondary rising: 20 minutes You should remove the dough for manual baking. For a total baking time of 113 minutes and 2 seconds. bread.out Are you making white or sweet bread (w or s)? S Is this a single or double loaf (s or d)? d Are you going to bake manually (y or n)? n Primary kneading: 20 minutes Secondary kneading: 33 minutes Secondary rising: 30 minutes Final rising: 75 minutes Baking: 52 minutes 30 seconds Cooling: 30 minutes For a total baking time of 300 minutes and 32 seconds. bread.out Are you making white or sweet bread (w or s)? W Is this a single or double loaf (s or d)? s Are you going to bake manually (y or n)? N Primary kneading: 15 minutes Secondary kneading: 18 minutes Secondary rising: 20 minutes Final rising: 75 minutes Baking: 45 minutes 0 seconds Cooling: 30 minutes For a total baking time of 263 minutes and 2 seconds.

6. p.290 #12 (7 minutes, 5 points) Filename baseball.c A baseball player s batting average is calculated as the number of hits divided by the official number of at-bats. In calculating official at-bats, walks, sacrifices, and occasions when hit by the pitch are not counted. Write a program that takes an input file containing player numbers and batting records. Trips to the plate are coded in the batting record as follows: H hit, O out, W walk, S sacrifice, P hit by pitch. The program should output for each player the input data followed by the batting average. (Hint: Each batting record is followed by a newline character.) You will find information about command line parameters on pp. 682-685 of the text. From the command line parameters, you will only need to use argv[1]. You will use argv[1] as the name of the file in your fopen() function call. cat baseball1.txt 12 HOOOWSHHOOHPWWHO 4 OSOHHHWWOHOHOOO 7 WPOHOOHWOHHOWOO [ssdavis@lect1 p4]$ baseball.out baseball1.txt Player 12's record: HOOOWSHHOOHPWWHO Player 12's batting average: 0.455 Player 4's record: OSOHHHWWOHOHOOO Player 4's batting average: 0.417 Player 7's record: WPOHOOHWOHHOWOO Player 7's batting average: 0.364 cat baseball2.txt 24 HOOHHHWWOHOPWWHHOOHOWHOOOH 1 OOWOOOOOOH 4 OOWWPWWPPOOOOPWP 25 HHWWHHWOWWOWWWOOHOHOH 44 HOOOWOHOOHOOOHPPWO [ssdavis@lect1 p4]$ baseball.out baseball2.txt Player 24's record: HOOHHHWWOHOPWWHHOOHOWHOOOH Player 24's batting average: 0.500 Player 1's record: OOWOOOOOOH Player 1's batting average: 0.111 Player 4's record: OOWWPWWPPOOOOPWP Player 4's batting average: 0.000 Player 25's record: HHWWHHWOWWOWWWOOHOHOH Player 25's batting average: 0.538 Player 44's record: HOOOWOHOOHOOOHPPWO Player 44's batting average: 0.286