CSP2151 Workshop 2 Assignment
Edith Cowan University School of Science
CSP2151 Workshop 2
Design or evaluate as appropriate
- When is each of these expressions true?
5< x && x<=10
5< x && x<=10 || 15< x && x<=20
month==4 || month==6 || month==9 || month==11
year%4==0 && (year%100!=0 || year%400==0)
- What is the value of this expression?
1 + 2 * 3 && 4 - 5 || 6 <= 7 % 8 != ! 9 / 10 > 11
- Under Australian taxation law, annual income between $6,000 and $20,000 is taxed at 17.0 cents in the dollar; income between $20,000 and $50,000 at 30.0 cents in the dollar; and income between $50,000 and $60,000 at 42.0 cents in the dollar. Any further income is taxed at 47.0 cents in the dollar. In addition, a Medicare levy of 1.5 cents in the dollar is applied to all income. For a given gross income, what net income will be received?
- Write a for loop that calculates the sum of the numbers from one to a hundred.
- Write a nested for loop that calculates and prints the sum of the factors of n (not including n itself), for each value n from one to a hundred.
- Write a while loop that calculates [log2x] for a double value x≥1, by counting how many times x can be halved before it becomes less than one.
- Without looking at the program in Figure 1.2 on page 8, can you write a program that computes the sum (and mean?) of a set of input numbers, supplied one per line?
Design and Implement the following:
- Write a program that reads a date in dd/mm/yyyy format and prints, in the same format, the date that it will be tomorrow. (Remember, start with a very simple program, and then expand it incrementally.)
- Write a program that shows how, for interest rates of 2%, 3%, 4%, 5%, 6%, and 7%, a regular savings amount of $100 per month grows over periods of 1 to 7 years.
- Write a program that reads in 2 numbers from the console, offers a choice of mathematical operation and then displays the result of the requested operation. The program should ask if the user wishes to quit and repeat until it gets a set value.
- Extend the program to read in 4 numbers and then apply a mathematical operation in order. ie: Apply the operation to the first two numbers. Then to the result of the first operation and the third number. Then finally to the result of the second operation and the fourth number. Bonus: Ask for and apply a different mathematical operation at each step!
1) Design with either pseudocode or flowcharts and implement a program to do the following:
If you land at more than 10ft/sec, you should crash!
If you reach within 5ft of the surface and you are moving at less than 10ft/sec, you should accept that as a landing.
If the altitude at any time is less than 0ft, you should crash!
YOU ARE LANDING ON THE MOON AND HAVE TAKEN OVER MANUAL CONTROL 500 FEET ABOVE A GOOD LANDING SPOT. YOU HAVE A DOWNWARD VELOCITY OF 50 FT/SEC. 120 UNITS OF FUEL REMAIN.
HERE ARE THE RULES THAT GOVERN YOUR SPACE VEHICLE:
- AFTER EACH SECOND, THE HEIGHT, VELOCITY, AND REMAINING FUEL WILL BE REPORTED.
- AFTER THE REPORT, A ‘?’ WILL BE TYPED. ENTER THE NUMBER OF UNITS OF FUEL YOU WISH TO BURN DURING THE NEXT SECOND. EACH UNIT OF FUEL WILL SLOW YOUR DESCENT BY 1 FT/SEC.
- THE MAXIMUM THRUST OF YOUR ENGINE IS 30 FT/SEC/SEC OR 30 UNITS OF FUEL PER SECOND.
- WHEN YOU CONTACT THE LUNAR SURFACE, YOUR DESCENT ENGINE WILL AUTOMATICALLY CUT OFF AND YOU WILL BE GIVEN A REPORT OF YOUR LANDING SPEED AND REMAINING FUEL.
- IF YOU RUN OUT OF FUEL, THE ‘?’ WILL NO LONGER APPEAR, BUT YOUR SECOND BY SECOND REPORT WILL CONTINUE UNTIL YOU CONTACT THE LUNAR SURFACE.
2) The Fibonacci sequence is a sequence of numbers where, after the first two initial numbers, the next number in the sequence can be found by adding the preceding two numbers.
Design with either pseudocode or flowcharts, a program that:
- Takes a number from the console
- Prints every number from 1 to that number
- If the number happens to be a Fibonacci number, do not print the number and instead print “Fibonacci!”
- Assignment Help
- Homework Help
- Writing Help
- Academic Writing Assistance
- Editing Services
- Plagiarism Checker Online
- Research Writing Help