Selection Programming Tasks
Console Selection Exercises
You need to complete 5 chips worth of work this week.
You can solve the following using If,Then,Else, Nested If or Case select statements.
I’ve given each one a “chip” rating to gauge the difficulty.
YOU MUST USE sensible variable names and comment your code.
Beginners Tasks
- Biggest Number
Two numbers are to be entered. The console should return which number is biggest (one chip) - Drivers Age
The user should enter there age (as an integer NOT a date), the program should return if they are old enough the drive (one chip) - Currency Calculator
Write a currency calculator for a bank that exchanges 1.5 euros to the pound and charges 2% commission with a minimum of £2 . (2 chip) - Roman Numerals (easy)
Write a program that is the user enters a single character roman numeral the value is outputted. (use a case ststement) (2 chip)
Roman numerals are conventionally defined to represent numbers using seven letters: I=1, V=5, X=10, L=50, C=100, D=500 and M=1000. - A business person is attending a meeting away from home and needs to book overnight accommodation. Their company will only pay expenses if the hotel is less than £60 a night and no more than 5 miles from the meeting venue. Ask the user to enter these the cost and distance. Then display whether their stay will be authorised. (2chip)
- A sports club has three membership categories. Junior (up to 18) pay £60 a year, Seniors (19-49) pay £120 and veterans (50 and over) pay £80. However, if a junior has been a member for 2 or more years then they get a discount of £20. Similarly, an adult qualifies for a £30 discount after 10 years of membership. Write a program that asks for the member’s age and the number of years they have been a member, and outputs their membership category and subscription.
Intermediate Tasks
- Challenge 10 from the Pack of Programming Challenges
- Challange 11 from the Pack of Programming Challenges
- Roman Numerals (Tricky)
Write a program that allows the user to input any Integer between 1 and 50 and the Roman Numeral is outputted.
Roman numerals are conventionally defined to represent numbers using seven letters: I=1, V=5, X=10, L=50, C=100, D=500 and M=1000. Numbers other than these are formed by placing letters together from left to right, in descending order of size, and adding their values. The basic rule is to always use the biggest numeral possible (e.g. 15 is represented as XV, but never as VVV, VX or XIIIII).
Letters may not appear more than three times in a row, so there are six exceptions to these rules - the combinations IV, IX, XL, XC, CD and CM. In these cases a letter is placed before one of greater value, and the smaller value is subtracted from the larger, e.g. CD = 400.
Test Your Program with the following values: 3, 4, 6, 15, 21,29, 37, 49... OR for and extra chip simple loop through every number between 1 and 50 outputting the Numerals in order.
Project Euler Tasks
- At least 2 more problems from the Project Euler Problem set.
- Roman Numerals (Hard)
Write a program that allows the user to input any Integer between 1 and 50 and the Roman Numeral is outputted.
Roman numerals are conventionally defined to represent numbers using seven letters: I=1, V=5, X=10, L=50, C=100, D=500 and M=1000. Numbers other than these are formed by placing letters together from left to right, in descending order of size, and adding their values. The basic rule is to always use the biggest numeral possible (e.g. 15 is represented as XV, but never as VVV, VX or XIIIII).
Letters may not appear more than three times in a row, so there are six exceptions to these rules - the combinations IV, IX, XL, XC, CD and CM. In these cases a letter is placed before one of greater value, and the smaller value is subtracted from the larger, e.g. CD = 400.
Write a program which accepts a number, between 1 and 3999 inclusive, and outputs the same number in Roman numerals.
Test your program with: 99, 1001, 1998, 3500, 3779.
For a bonus Chip
Some Roman numerals have fewer characters than the number of digits in the number they represent, e.g. C (1 character) compared with 100 (3 digits). Similarly some have more characters (e.g. XXIV and 24), and some have the same length (e.g. V and 5). How many of the numbers from 1 to 3999 inclusive have fewer characters in their Roman numeral form, , how many have more haw many have the same?
As always. I want you to upload a single HeAD. You should copy and paste our code AND a screenshot of you program running with the console showing inputs and outputs.
Question 1 Roman Numerals |
In Roman times, numbers were represented using letters. The way of doing this, known as Roman Numerals, is often seen depicting the copyright date on films and television.
Roman numerals are conventionally defined to represent numbers using seven letters: I=1, V=5, X=10, L=50, C=100, D=500 and M=1000. Numbers other than these are formed by placing letters together from left to right, in descending order of size, and adding their values. The basic rule is to always use the biggest numeral possible (e.g. 15 is represented as XV, but never as VVV, VX or XIIIII). Letters may not appear more than three times in a row, so there are six exceptions to these rules - the combinations IV, IX, XL, XC, CD and CM. In these cases a letter is placed before one of greater value, and the smaller value is subtracted from the larger, e.g. CD = 400. |
|
Examples: |
26 XXVI 94 XCIV 555 DLV 1998 MCMXCVIII |
|
1 (a) [20 marks] |
Write a program which accepts a number, between 1 and 3999 inclusive, and outputs the same number in Roman numerals. |
Sample run |
1 (b) [4 marks] |
(i) What is LXIII + XXXVIII? Give your answer in Roman numerals. (ii) What is MCCXLIX + DCXV? Give your answer in Roman numerals. |
1 (c) [6 marks] |
Some Roman numerals have fewer characters than the number of digits in the number they represent, e.g. C (1 character) compared with 100 (3 digits). Similarly some have more characters (e.g. XXIV and 24), and some have the same length (e.g. V and 5). How many of the numbers from 1 to 3999 inclusive have fewer characters in their Roman numeral form, and how many have more? |