In this lab, you will work on three different projects that make use of decision-making logic. Firstly, you will enhance an already started application that determines if an integer value that represents a year is a leap year. Next, you will work on a project that allows a user to enter two numbers and an arithmetic operator (+, -, * or /), and carry out the operation on the two numbers. Finally, you will create an app that calculates the Body Mass Index (BMI) of a user based on the categories they fall into.
In this lab, you will work on three different projects that make use of looping constructs. Firstly, we will create an app that displays the last 20 seconds of a rocket’s countdown sequence before it takes off from its launch pad. Next, you’ll create an app that calculates the compound interest generated for money placed in a savings account and saved for a number of years. Finally, you will create an app that displays an image of a fir tree made up of asterisks where the height of the tree (the number of rows in the top ‘triangle’) depends on a value input by the user.
In this lab, you will create an array of 5 integers, get the user to input 5 (integer) scores, and store each score in the slots of the array. After the user has input the scores, the app will show them back to the user. Finally, the app will find and show the minimum score, the maximum score, and the average score each calculated by looping through the array.
In this lab, you will tackle two separate projects. In the first, you will write a program that can search a specified directory on disk, looking for all the text files. For each text file found, the app will add the name of the file to a dynamically growing list. After finding all the files, the code will create a new file in the same directory that contains the names of the text files.
In the second project, you will create a program that sets up a dictionary of product names and prices. The code will then loop around, asking the user for the names of products they wish to purchase. The app should search for the products in the dictionary to find their prices and use these to keep a running total of the cost of all the selected items. When the user types ‘end’ for the product name, the app will display the total and terminate.
When writing code, it is very common for the same or similar block of code to be used in a number of different locations. In situations like this, it is always better to place the code in a function that can be called from the various locations rather than duplicate the logic.
In this lab, you will create an application that contains a function called ‘GetInteger’, which takes a prompt as a string, displays the prompt, and takes a response from the user. The function then converts the input string into an integer before returning it. You will then use the function in your main program to ask the user for the price of a bag of sweets and how much money they have to spend (both in pence). The app should then calculate and display the number of bags they can purchase.