Question
Write all of these problems in C++ Warm-Up(1) Special Relativity In special relativity, an object that has length L centimeters when at rest with respect
Write all of these problems in C++
Warm-Up(1) Special Relativity In special relativity, an object that has length L centimeters when at rest with respect to the observer has a relativistic length, LR centimeters, given by :
when traveling at velocity v away from the observer. Here c is the speed of light, approximately 3 1010 cm/sec. The is a square root symbol. Write a program that will calculate and display the relativistic length LR of an object of rest length L traveling at velocity v. In your program: Use object type double for L, v, c, and L R . Initialize c to 3 1010 cm/sec. Have the user input values for L and v. Include the file cmath so you can use the sqrt() function.Test your program using L = 32.5 cm and v = 2.2 1010 cm/sec as one of your test cases. When you enter the value of v use e (scientific) notation (like 2.2e10 or see Section 2.3 of the textbook). Also test your program with L = 42.0 cm and v = 3.2 1010 cm/sec (again, enter v using scientific notation). What happens?
Stretch
(1) Basal Metabolic Rate (from the Savitch Ch 2 Programming Projects)
The Harris-Benedict equation estimates the number of calories your body needs to main- tain your weight if you do no exercise whatsoever. This is called your basal metabolic rate, or BMR (note this is a single variable name, not three variables multiplied together). The formula for the calories needed for a woman to maintain her weight is :
BMR = 655 + (4.3 weight in pounds) + (4.7 height in inches) (4.7 age in years).
The formula for the calories needed for a man to maintain his weight is :BMR = 66 + (6.3 weight in pounds) + (12.9 height in inches) (6.8 age in years).
A typical chocolate bar contains approximately 230 calories. Write a program that allows the user to input his or her weight in pounds, height in inches, age in years, and the character M for male or F for female. The program should then output the number of 230 calorie chocolate bars that need to be consumed to maintain ones weight for a person of the input sex, height, weight, and age.
Testing Discussion: You are your partner should separately come up with 3 sets of test data for this program. When both of you have made up your test cases, discuss with your partner why you chose the test cases you did, and, more generally, what makes good test cases for a program like this.
2) Temperature Conversion
For weather reporting, the daily temperature will generally be given in degrees Celsius or Fahrenheit. Write a C++ program that will convert a temperature given in one system of units to the other. For example, if the temperature is given in degrees Fahrenheit convert it to Celsius, and vice versa.
Your program should prompt the user to provide a temperature value (object type double) and a single character (f or c) to indicate if the value is in degrees Fahrenheit or Celsius. Read in the temperature and scale values, then compute and display the corresponding equivalent temperature in the other scale system. Your output message should indicate whether the result is Celsius or Fahrenheit. For example:
Example 1 (underlined values are user inputs):
Enter the temperature: 26.6
Enter Celsius (c) or Fahrenheit (f): c
The temperature in Fahrenheit is 79.88
Example 2 (underlined values are user inputs):
Enter the temperature: 93.2
Enter Celsius (c) or Fahrenheit (f): f
The temperature in Celsius is 34
Use the following conversion formulas:
F = C (9/5) + 32
C = (F 32) (5/9)
[Hint: remember there is a difference between division of integers and division of doubles. Be careful when translating the equations above into C++.]
Test your program using the following values, as well as some other test cases you and your partner think up:
(i) convert 37 degrees Celsius to Fahrenheit;
(ii) convert 98.6 Fahrenheit to Celsius;
(iii) convert 32 Fahrenheit to Celsius;
(iv) convert -40 Fahrenheit to Celsius.
(3) Simple Integer Calculator
Write a simple integer calculator. This should be able to handle +, -, / (integer division), and *. The user should input in the format: [integer][operator][integer]. For example: 2+56 or 5*3 (if you do it right, the code should work whether or not there are spaces before or after the operators). Make your program not crash as long as the input is in this format. Your program should only compute one number then stop. You should display both what the user entered and the numeric result.
Example 1 (underlined values are user inputs): Enter an equation: 7+17+1 = 8
Example 2 (underlined values are user inputs): Enter an equation: 8 / 38/3 = 2
Workout
(1) Payroll (from a Savitch Chapter 2 programming project)
An employee is paid at the rate of $16.78 per hour for the first 40 hours worked in a week. Any hours over that are paid at the overtime rate of one-and-one-half times that. From the workers total pay, 6% is withheld for Social Security tax, 14% is withheld for federal income tax, 5% is withheld for state income tax, and $10 per week is withheld for union dues. If the worker has three or more dependents, then an additional $35 is withheld to cover the extra cost of health insurance beyond what the employer pays. Your task is to write a program that will read in the number of hours worked in a week and the number of dependents as input, and will then output the workers total pay, each withholding amount, and the net take-home pay for the week. Solve this problem in four steps: (i) Problem solving discussion: Both you and your partner should work on it first individually (using a pencil and paper dont start typing yet) for three minutes. This will not be enough time to solve the problem, but will be enough for you to
check if you understand the problem, and to get started on solving it. After three minutes, compare the problem solving approach you are using with your partners approach. Are they similar or different?
(ii) Outline: You and your partner should collaboratively come up with a detailed out- line of the problem. Dont use C++ yet. Instead use an English-like description (pseudocode) to outline all the steps the program will need to do, in the order it will need to do them.
(iii) Code: Once you have the outline written, (collaboratively) turn it into a C++ program.
(iv) Test and revise: Make up test cases, test your program, correct it as needed, and continue testing and revising until your program is correct.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started