Arab Open University
Faculty of Computer Studies
M150 Data, computing and information
Question 1 [25 marks]
a. Write a function called longestWord that takes an array of Strings as
an argument and returns the longest string in the array (i.e. the word that
has the biggest number of characters).
b. Read from the user 10 words and store them in an array of 10 elements.
c. Print the array elements in the output window.
d. Call the function longestWord and print the result.
e. In your Solution document insert 2 screenshots:
- one showing the program prompting for any of the 10 words, with
you having entered the value but not yet pressed OK;
- one showing the 10 elements of the array and the resulted output.
Question 2 [25 marks]
In unit9, page 21 you were introduced to the methods associated with Date object. In
the same unit, sections 3.2 and 4.2 you learned how to use functions from the
for all the functions in these libraries are in section 3.2 and Appendix 1 of unit 9. You can
Using functions from both the "drawingLibrary.js" and the "dateLibrary.js" and some
a. Draw a colored line.
b. Create a Date object representing your date of birth and display it in the short
form. (e.g. 12/10/1980)
c. Display the month name of your birthday date.
d. Draw a colored arrow.
e. Calculate and print the difference in years and days between the date you've
created and today's date.
f. Draw a colored line.
g. Change the year of the Date object you've created to be 2017. You should not
create a new date. Display the resulted date in the short form.
h. Draw any colored shapes of your choice.
i. Insert a screenshot that shows the resulted output of your program.
Page 3 / 4
Question 3 [25 marks]
You are required to model a new user-defined object type, Cupboard.
The Cupboard object type has the following properties:
color: a string representing the color of the Cupboard.
height: a number that holds the height of the Cupboard, which is a number from 1
to 3 meters.
doors: a number that holds the number of doors of the Cupboard, which is a whole
number from 1 to 8.
The Cupboard object type has the following methods:
setColor(aString): a method that changes the color of the Cupboard to
getColor(): a method that returns the color of the Cupboard.
setHeight(aNumber): a method that sets the height of the Cupboard to
aNumber, which could have any value from 1 to 3 only.
getHeight(): a method that returns the height of the Cupboard.
setDoors(aNumber): a method that sets the number of doors of the Cupboard to
aNumber, which could have any value from 1 to 8 only.
getDoors(): a method that returns the number of doors of the Cupboard.
display():a method that displays the color, height and number of doors of the
Cupboard in an alert window.
a. Write the Cupboard constructor function Cupboard (aColor, aHeight,
b. Implement all the above specified Cupboard methods.
c. Ask the user about the color of the Cupboard and create an instance with the
given color, 2 meters long and having 4 doors.
d. Use appropriate methods to do the following for your Cupboard object:
1) Print information. 2) Change the color to white
3) Change the height to 1.75 m. 4) Print information.
e. In your Solution document insert three screenshots:
- one showing the program prompting for the Cupboard color, with you having
entered the color but not yet pressed OK;
- one showing the first alert window;
- one showing the second alert window.
f. Can you change the height of your Cupboard instance to be 5 meters?
statement(s) you need to use.
- If you answer with 'No': briefly explain why?
Page 4 / 4
Programming style [5 marks]:
In your answers to questions 1, 2 and 3, you should follow good programming style that
helps readability. This includes:
• Using short comments at the beginning of each program stating the purpose of your
• Using spacing and indentation to help making the structure of your program clear.
• Making sure that the programs output include descriptive texts that clearly describe
the resulted output.
• Following the M150 style guidelines when choosing the names of the variables. This
includes: (Refer to section 2.2 of unit 7, page 16)
- Avoid very short identifiers, such as a, b, x, ch, because they are not very
- Avoid the use of $ and _ in identifiers.
- Choose meaningful names, i.e. names which give some indication of the role
played by the variable.
- Start your identifiers with lower-case letters. Where an identifier is composed of
two or more English words use a single upper-case letter to mark the start of
each word after the first.
You should write your solutions to all the questions with the required screenshots in a
single word document. Head the document with your name and your Personal Identifier
End of questions
حلول جميع الواجبات
موبايل – واتس أب
حلول مضمونة لجميع الواجبات ومشاريع التخرج
حلول الواجبات غير مكررة ونسبة التشابه أقل من 10%