Write Programs Using Integer Numbers

Added on - 16 Sep 2019

  • Dissertation

    type

  • 2

    pages

  • 966

    words

  • 76

    views

  • 0

    downloads

Showing pages 1 to 1 of 2 pages
Coursework 1.1List processingIn this section you will be asked to write programs that ask from the user to enter a list ofinteger numbers (let us give the list nameA) and then analyse the list as specified in thefollowing three subsections.In order to obtain the listA, the program first asks the user to enter the number ofelements of the list and then asks to enter these individualnelements in a loop lastingniterations (standard procedure of entering lists to be considered in the class of week 4).Let me stress again that this way of obtaining lists applies toallthe three tasks below.Please feel free to assume that the input is entered correctly. No marks will be added forcorrectness checking of the input and, accordingly, no marks will be reduced for not doingsuch a check.1.1List containing the given set of elements (25 marks)Write a program that prints ”YES” ifAcontains numbers 1,2,3 (all of them) in an arbitraryorder and ”NO” otherwise. For instance, the program should print ”YES” ifA=[10,2,4,15,3,6,1] and ”NO” ifA= [1,17,2,45] (because number 3 is missing).1.2List containing the given set of elements in the given order (25 marks)Write a program that prints ”YES” ifAcontains all the numbers 1,2,3 occurringin the orderthey are listed(but not necessarily consecutive) and ”NO” otherwise. For instance theprogram prints ”YES” ifA= [45,1,5,2,77,3] and ”NO” ifA= [45,1,3,77,2] (incorrect order).Clearly, the program should also print ”NO” if one of 1,2,3 is missing inA.The tricky part of this task are cases of multiple occurrences of 1,2,3. For instance theprogram should print ”YES” ifA= [3,2,1,2,3] becausethere areoccurrences of 1,2,3appearing in the correct order while ”NO” should be printed forA= [3,3,2,2,1,2] becausethere are no such occurrences.The marking scheme for this exercise is the following.The solutions working for all cases (including repeated occurrences) will receive fullmark (25 marks).1The solution working only for cases without repeated occurrences of 1,2,3 will receive15 marks provided that the ‘NO REPEATED OCCURRENCES’ statement is explicitlyprovided as a comment to the program.The solutions working only for cases without repeated occurrences of 1,2,3 and notwarning the user about this in the comments will receive 5 marks.
desklib-logo
You’re reading a preview
card-image

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Unlock This Document