Maths and String Functions Programming Tasks
ONLY upload your HeAD with Code copied as text and Screenshots of console windows with the code running
Maths Functions
- RoundedUpNumber = math.ceiling(number)
- RoundedDownNumber = math.floor(number)
- RoundedNumber = math.round(number)
- To get Pi = Math.PI
- You can see the full list of maths functions here
- Simple Division:Write a program that divide two inputted numbers and displays the answers to the console in all three ways below:
- Without Rounding
- To 3 Decimal places
- To 0 Decimal places (as an integer)
- Average students:Write a program that finds the average number of students per class. The answer should be an integer
- EASY: Fixed input of 10 classes (Using a for loop)
- Tricky: You ask the user how manny classes then loop that many times (for loop)
- Hard: The user can keep inputing student numbers, and stops by typing 9999 (do until loop)
- Cost of sweets: Write a sweety cost calculator that allows the user to input the Cost per 100g (in the format(0.00), and the mass of sweet purchased in grams (in the format 0.00) and outputs the total cost in the same format..
- EXTENTION: Create a menu of several sweet types with the cost/100g hard coded.. Obviously this program could be applied to anything that you purchase by mass!
- How much Pie? Write a program that asks the user how many decimal places they would like to see Pi to and displays Pi on the screen to that many d.p
- Credit Card Interest:Write a program that calculates the interest payment on a credit card with a monthly rate of 1.34625%. The user should enter in the amount on the card (0.00) and the program returns the interest for the month ROUNDED UP to the nearest pence.
- Number of Slabs Calculator: Write a program that allows the user to enter the length and bredth of a new patio (in meters) and returns the integer number of slabs required (We used square slabs that are 0.609m x0.609m).
- Method1: Find the area; divide by the slab area and round-up
- Method2: Find the minimum number of slabs long by the minimum number of slabs wide
- Hard: As above but also states how many slabs will require cutting.
- TEST your program with the following data:
- Length= 4.5m, Width = 6.7.
- The two methods give different answers. M1=82 slabs; M2=96 slabs; 19 slabs need cutting
String Functions
- LengthofString = Len(string)
- SubString = Mid(string,position,length)
- PositionofSubstring = InStr(string,substring)
- Converting Characters to/from the ascci code ASC(letter), CHR(code)
- A good list of sting functions can be found here
- Write a program that displays the length of a string entered by the user
- Write a length check Validation that only allows the user to enter strings of greater that 5 characters
- Write a program that displays the third, forth and fifth characters of any string entered
- Write a program that displays the position of the first letter "a” in an entered string (use the instr function)
- Write a program that displays the position of the first letter "a” in a string entered by the user (use the instr function)... What gets displayed if there is no "a” in the string?
- Alter the previous program to allow the user to enter a string and the letter they wish to find the first position of....
- Write a Caesar Cypher. The user enters a string. and then a shift. The output is an encrypted string. You should be able to use the same program to decipher using a negative shift. (ext.. create a brute force decipher tool that tries all 25 negative shifts outputting each one.)