Specification Journal 001

advertisement
Specification Journal 001
3.1.1.1 Data Types
For this specification point you need to understand the following:
1) The concept of a data type
2) What the following mean and how they are used appropriately
a. Integers
b. real/float
c. Boolean
d. Character
e. String
f. Date/time
g. Records / structures
h. Arrays / lists
3) Define and use user-defined data types based on language-defined (built-in) data types
INCORPORATING –
 3.1.1.3 Arithmetic Operations in a programming language.
 3.1.1.7 String Handling operations in a programming language.
 3.1.1.8 Random number generation in a programming language.
1.1 Key terms to define – Write a detail definition of each term given below. Look into the technical
aspects of each key word.
Term
Data type
Integer
Real
Boolean
Character
String
Date/Time
Record
Array
Definition
Questions to complete – Screenshot your answers below each question.
1.2 Integers and reals.
1) Create a program that asks the user for three numbers and then performs the following
operations on them – multiplication, addition and division and outputs the three results with
appropriate text.
2) Create a program that asks the user for 5 numbers and then works out the average of them
and then outputs the result.
3) Ask the user for a number. Create a program that randomly generates another number (out
of 100). Complete the following maths calculations –
a.
b.
c.
d.
e.
User Num * Random
User Num / Random
User Num + Random
User Num – Random
User Num modulus Random (You will need to investigate how to do this)
1.3 Booleans
1) Create a program that asks the user three questions and they have to answer either true or
false. The program will then relay back to the user the answers that they put in.
1.4 Characters
1) Create a program that asks the user for a letter of the alphabet. Then convert it to its ascii
value. Add 1 to it then convert it back to a char, then display the new letter.
Hint:
(int)lett
- if lett was a char then (int) converts it to ascii
(char)num
- if num was an integer (ascii value) then (char) converts it
back to a character
1.5 Date/Time
1) Create a program that asks the user for their date of birth and then works out how many
days there is until their birthday.
2) Create a program that asks the user for two dates and then uses the datetime compare
function to compare the two dates. Output the result. Depending on the inputs – can you
work out what the return values mean?
3) Create a program that asks the user to enter in a date in the format DD/MM/YYYY and then
converts the date to be displayed like “15th July 2015” for example.
4) Create a program that gets the current time and then displays what that time would be in
Perth Australia.
5) Create a program that gets today’s date. Then ask the user for number. The program will
then work out what the actual day will be that many days after today’s date (e.g. Monday,
Tuesday etc..)
1.6 Strings
The following questions can be answered without IF statements or LOOPS. Although if you want to
use them that is fine as long as you covered the string topics in the specification.
1) Ask the user to enter in 5 letter word and save it in a string. Then show them the string
backwards.
2) Ask the user to enter in their name and address and then create a string to say – “Hello
<name> you live at <address>, how are you today?”
3) Investigate how you change the case of a string. Ask the user for their name and then
output it all in lowercase then in uppercase.
4) Save the sentence “Hello your name is Bob and you are 20 years old” into a string. Extract
the name from that string into another string called “name”. Extract the age from the
sentence as well and save it to an integer variable.
5) As the user to enter in answers to the following questions to make a password out of it.
a. The first and last letters of their name
b. Their age divided by their shoe size rounded up.
c. The first part of their address after the number backwards – for example if
their address was – “102 Summer Street” then the output would be
“remmus”
d. The length of their favourite colour + 5
Concatenate all of above into one string and that is their password.
6) Get the user to enter in details about the following:
a. A name of a person
b. An action
c. A location
d. A name of another person
e. The relation of those people to each other
f. A dialogue that happened between the two.
Once you have all the information use concatenation to build a string that tells a story.
7) Get the user to enter in a 5 letter word and then an offset. Convert each character of the
word into its ASCII equivalent and add the offset to it. Convert each number back to a
character and show the result. This is a Caesar encryption.
Download