CS 31: INTRODUCTION TO COMPUTER SCIENCE I Computer Science Department University of California, Los Angeles Dr. John A. Rohr January 14, 2009 PROJECT 2 Writing C++ Programs Using Sequential and Selection Statements Objective : Learn to write simple C++ programs which consist of sequential and selection statements and use numerical and string input and output. Background : A block and tackle consists of a set of pulleys configured to lift a load with less force than the weight of the load. To lift a load up by pulling a rope down, the fixed end of the rope is attached to the fixed pulley block if the number of wheels is even and to the movable pulley block if the number of wheels is odd. For a block and tackle having a total of n wheels lifting a load of weight w a distance d , the lift force is w/n and the distance that the rope must be pulled is d*n . Assignment : Write a simple C++ program that will do all of the following. 1. Display a title followed by a blank line. 2. Prompt for and accept a load weight, lift distance, and number of pulleys. 3. Calculate the pull force, pull distance, and fixed end attachment position. 4. Display the pull force, pull distance, and fixed end attachment position. 5. Display a termination message. Grading : 15%: Program design; 15%: Program implementation; 10%: Test data; 60%: Results: 20 tests @ 3% each Due Date : Tuesday January 27, 2009: 9:00 PM : Projects must be submitted electronically. PROJECT 2 Writing C++ Programs Using Sequential and Selection Statements DETAILED SPECIFICATIONS Project Start early. Submit the project every time significant progress is made. Keep backup copies off the disk being used to develop the program. Follow exactly all formats shown in the error messages and sample executions. Procedure Write a complete set of test data. Instantiate a Visual C++ project for this project. Add a C++ .cpp file to the project. Write the initial program comments. Determine the data required for the program. Design the algorithm for the program. Write the #include and using statements following the initial comments. Write all comments for the program. Write the program code within the comments. Build the project. Fix the syntactic errors detected by the compiler. Repeat Steps 10 and 11 until there are no syntactic errors. Run the program with the sample data in the project assignment. Correct any errors detected by running the program. Repeat Steps 13 and 14 until there are no semantic errors. Run the program with the your test data. Correct any errors detected by running the program. Continue to test the program to ensure that there are no additional errors. PROJECT 2 Writing C++ Programs Using Sequential and Selection Statements DETAILED SPECIFICATIONS (Continued) Program Set the output format. Display the title. Display a blank line. Prompt for the load magnitude. Accept the load magnitude as a numerical value. If the load magnitude is invalid, display an error message and exit. Prompt for the load units. Accept the load units as a string . If the load units input is blank, display an error message and exit. Prompt for the distance magnitude. Accept the distance magnitude as a numerical value. If the distance magnitude is invalid, display an error message and exit. Prompt for the distance units. Accept the distance units as a string . If the distance units input is blank, display an error message and exit. Prompt for the number of wheels. Accept the number of wheels as a numerical value. If number of wheels is invalid, display an error message and exit. Display a separator ( "====================") on a line by itself. Determine the rope attachment point. Calculate the pull force. Calculate the pull distance. Report the pull force. Report the pull distance. Report the rope attachment point. Display a termination message ending with endl but no additional output. Error Messages *** Load magnitude must be greater than zero! *** *** Load units must not be blank! *** *** Distance magnitude must be greater than zero! *** *** Distance units must not be blank! *** *** Number of wheels must be greater than one! *** PROJECT 2 Writing C++ Programs Using Sequential and Selection Statements INPUT AND OUTPUT FORMATS Inputs are shown in bold type! Example 1 : BLOCK AND TACKLE CALCULATION PROGRAM Load magnitude: 24 Load units: Pounds Distance magnitude: 2 Distance units: Feet Number of wheels: 3 ==================== Pull force = 8.00 Pounds Pull distance = 6.00 Feet The fixed end of the rope is attached to the movable pulley block. Successful calculation. Example 2 : BLOCK AND TACKLE CALCULATION PROGRAM Load magnitude: 80.8 Load units: Pounds Distance magnitude: 16 Distance units: Feet Number of wheels: 8 ==================== Pull force = 10.10 Pounds Pull distance = 128.00 Feet The fixed end of the rope is attached to the fixed pulley block. Successful calculation. Example 3 : BLOCK AND TACKLE CALCULATION PROGRAM Load magnitude: 1000 Load units: Pounds Distance magnitude :-1 *** Distance magnitude must be greater than zero! ***
STUDYBLUE makes things that make you better at school.
Things like
online flashcards with photos and audio.
Things like personalized quizzes and friendly reminders about when (and what) to study next.
Think of it as a digital backpack™: access to all of your study materials online and on your phone.
STUDYBLUE exists to make studying efficient and effective for every student, for free.
Join us.
“Simply amazing. The flash cards are smooth, there are many different types of studying tools, and there is a great search engine. I praise you on the awesomeness.”
Dennis