Sei sulla pagina 1di 4

Academic Year 2019/20

P21387 Introduction to Algorithms and Programming

Final Year Exam

Deadline for Submission: Online via the Moodle submission link by 11:00am on Friday 5th June.

Submission Instructions Submit your full source code and pseudo code to the submission link on
the Moodle page.

Instructions for completing the Please upload your full code in a single text file (.txt). Your code must
assessment: be written in C and compliable in Codeblocks.

Examiners: Dr Josh Robertson


Assignment:

Write a program that requests the user to search for a single word in the text provided below. Your
program MUST perform exactly as detailed and in the order described for the marks.

Part 1: main() 10 marks

1. Require the user to enter the password “ladybird” to gain access to the system
o Use a While Loop which provides the user 3 attempts to gain access to the system.
After 3 unsuccessful attempts, print a message and exit the program.
2. Display a menu-based system which offers the user a choice of 1) start the program or 2) exit
o If the user presses 1
▪ Request the user to confirm they are ready to begin by typing yes or no
• Any input other than “yes”, “YES” or “no”, “NO” should be rejected.
▪ Call the function named wordSearch (see Part 2 below)
o If the user presses 2
▪ Exit the system indicating successful exit status
o If the user presses anything else other than 1 or 2
▪ Print a message to say that input is not allowed
▪ Go to the main menu (step 2)
• You cannot use a goto label

Part 2: wordSearch() 30 marks


3. Complete the function prototype and function header and use the appropriate data type where
the user is not expected to pass any parameters or expect the function to return data.
4. For the logical block of the function, display ALL the “meaningless” text to the console
(provided below)
o You can only use a single print statement which must format the text the same as
below (e.g. over 5 lines)
5. Request the user to search for a word within the “meaningless” text
o You cannot use any additional libraries or functions such as those found in <string.h>
and so you can only use #include <stdio.h> and #include <stdlib.h>
o You must use at least one For Loop in your solution
o If the word is found
▪ Print a message to say it was found, display the location of the word (e.g. the
index number within the text) and how many times it appears in the text if it
appears more than once.
▪ Then, create and assign a local integer value of 1 to a pointer variable named
printFlag
▪ Call the function named printFile (see Part 3) and pass the printFlag
variable (above) by reference.
▪ After executing the above, ask the user if they would like to try another word to
search
o If the word is not found, ask the user to provide another input
o If the word “EXTERMINATE” (all upper case only) is entered, immediately close the
program

Part 3: printFile() 15 marks


6. Complete the function prototype and function header and use the appropriate data type where
the user is expected to pass one pointer variable only.
7. For the logical block of the function,
o Check the printFlag variable has a value of 1
o Prepare to use a file called ‘wordsearch.txt’ in the local directory
▪ You should check if the file exits first, if it doesn’t exist, then create a new file
with the same name ‘wordsearch.txt’. If the file already exists, open and
overwrite the previous contents of that file
o Output the following to the text file:
▪ The searched/matched word the user entered, how many times it was found
and where it appears in the text (the index number within the text)
▪ A message to say, “you are the champion!”
▪ Each component above should be separated by tab sequence
8. After saving to the file successfully, print a message to the console which displays the
message “File Save complete”

The meaningless text is


“AMENFELANGUAGEFERVZ0PIBMOU”
“ZBPOINTERSSKLM12PMNOCOT”
“YCPROGRAMMERWQKNULTHMD”
“UKUNIXFIMWXIZEQZINPUTEX”
“P0DSTRINGGDIWHIMERCERLS”

Part 4: //pseudocode 5 marks

Complete pseudo code of the solution must be written at the top program source code and must
enclosed with source code comments delimiters.

Source code comments are NOT required to explain the implementation.

Pseudo code not properly commented out will be subject to a 2-mark penalty.
Finally:
• The program may be able to be written in different IDEs but must be compliable with
CodeBlocks.
• The code must be written in C and not any other language such as C++
• Please upload ALL your work in one single .txt document to the Moodle submission link by
the deadline.

Potrebbero piacerti anche