DOC PREVIEW
MIT 16 070 - Problem Set 3-16.070

This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1 16.070 Introduction to Computers and Programming Due: 28 February Problem Set 3 Spring 2001 All of the homework guidelines should be followed. Be sure to comment your code and make it readable. Points will be deducted if the guidelines are not followed. Indicate the amount of time you spent working on each problem. Problem 1 (10%) Assume that all of the following variables are of type int. Find the value of each of the following statements. In your answers indicate what order the operations are performed in. x = (2 + 3) * 6; x = (12 + 6) / 2 * 3; y = x = (2 + 3) / 4; y = 3 + 2 * (x = 7 / 2); x = (int) 3.8 + 3.3; x = (2 + 3) * 10.5; x = 3 / 5 * 22.0; x = 22.0 * 3 / 5; Turn In: Typed answers to each of the above and the time you spent working on this problem. Problem 2 (15%) Write a program that will calculate the value of πusing the following series expansion: ()444 44 ... 1 ...357 2 1nnπ=−+−++− ++ Your program should prompt the user for the number of terms of the series to evaluate and display the calculated value of πbefore exiting. Implement the program first using a for-loop and then re-implement it using an equivalent while-loop (i.e. two different ways to solve the same problem). Note that n is an index starting at 0 for term 1. Turn In: Your program code (for both cases) and a screen dump of an output run. Also include the time you spent working on this problem. Problem 3 (20%) Write a program for a cash register in Texastan. Texastan charges federal and state sales tax on products depending on their product code or class. The following table indicates the percentage of taxation for each product code: Code Federal Tax State Tax 0 1.5% 0% 1 2% 7% 2 0% 3% 3 0% 0% The cash register should prompt a user for the price and product code of a product, then output the amount of federal and state sales tax to be charged for an item and add up the total cost of a product.2 Typical output: Welcome to Texastan Please Enter Product Code: 0 Please Enter USD Price (before tax): 100.00 Unit Price: 100.0 USD Federal Tax: 1.5 USD State Tax: 0 USD Total: 101.5 USD Press any key Turn In: Printout of source code and screen shot of a sample run for each product code for an item costing 100 USD before tax. Also turn in a flow chart describing your program, and indicate the amount of time you spent working on this problem. Also: Copy your program code as username_PS3_P3.c to \\CDIO-Prime\16.070HW\ps3\p3 , replacing username with your Athena username. Problem 4 (15%) A student writes a short program intended to compute the moment of inertia of a pendulum with mass concentrated at the end of an arm 10 meters long, using the formula: ()2__ _Moment of Inertia mass arm length=× Since various masses can be attached to the pendulum arm, the program prompts a user for an input from the set of numbers 1,2 and 3, signifying masses of 3, 5 and 8kg respectively at the end of the arm. The program then determines the moment of inertia using the selected mass. When running the program though, the moment of inertia printed to the screen always seems to turn out to be 0. Identify the fundamental error that the student made, and explain how you would correct the problem. /******************* * TJ Feb 2001 * * Problem Set 3 * * Question 4 * *******************/ /* This program determines the moment of inertia of a pendulum */ #include <stdio.h> /* Function Prototyping */ void determine_mass_from_configuration(int config, double total_mass); void determine_moment_of_inertia(double total_mass, double pendulum_length); /* Global variables */ float total_mass=0; /* Pendulum mass */ float pendulum_length=10; /* Length of pendulum arm */ double moment_of_inertia; /* Determined moment of inertia */ int main(void) { /* Retrieve config info from operator */ int config; printf("Choose Configuration (1 to 3): "); scanf("%d",&config); /* Determine mass according to configuration data received */ determine_mass_from_configuration(config,total_mass); /* Calculate the moment of inertia */ determine_moment_of_inertia(total_mass, pendulum_length); /* Output results to screen */ printf("\nMoment of Inertia is: %f \n\n",moment_of_inertia);3 } /* end main */ /* Function determines the mass of the pendulum from the configuration setup (a number 1 to 3) */ void determine_mass_from_configuration(int config, double total_mass) { /* Assign a different mass to total_mass acc. to config */ switch (config) { case 1 : total_mass=3.0; break; case 2 : total_mass=5.0; break; case 3 : total_mass=8.0; break; default : total_mass=0.0; } /* end switch */ } /* end of determine_mass_from_config */ /* Function determines the moment of inertia of the pendulum arm, given mass and length */ void determine_moment_of_inertia(double total_mass, double pendulum_length) { moment_of_inertia=(pendulum_length*pendulum_length)*total_mass; } /* end of determine_mom_of_inertia */ Turn In: Typed answer. Problem 5 (40%) The following problem should be considered a requirement specification for a software design problem. You should follow the spiral model of the software development process. Be sure to practice top-down design techniques and follow proper modular programming guidelines. An astronaut needs to pilot a lander module as it descends to Mars. Before he can start using his thrusters he needs to complete the following thruster start-up sequence: 1. Communicate intent to descend to Mars to an orbital platform, by pressing the “c” key, followed by “Enter”, on his keyboard. 2. Enable propulsion electronics, by pressing the “e” key, followed by “Enter”, on his keyboard. 3. Pre-heat hot-gas thrusters, by pressing the “p” key, followed by “Enter”, on his keyboard. Once the start-up sequence has been completed, if the ‘n’ key is pressed, followed by “Enter”, the thrusters must be turned on. If the “o” key is pressed, followed by “Enter”, the thrusters must be turned off. Write a program that will monitor the keyboard for commands. Thrust can only be switched on and off if the start-up sequence was completed in the correct order. Attempts to thrust before completion of the start-up sequence should be met with a suitable error message. Likewise, entering the start-up sequence in an incorrect order should result in an error


View Full Document

MIT 16 070 - Problem Set 3-16.070

Documents in this Course
optim

optim

20 pages

Load more
Download Problem Set 3-16.070
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Problem Set 3-16.070 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Problem Set 3-16.070 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?