0% found this document useful (0 votes)
32 views

Comp Assignment 2

Uploaded by

tRz. Aun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
32 views

Comp Assignment 2

Uploaded by

tRz. Aun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 8
Run vue’ Yate Secion: ee COMPUTER SCIENC ICE - 9618 (A1) — PAPER 2 Assignment #2 Topic: File Handling Deadline: 21" Nov, 2023 01. Toni has a large collection of jazz CDs that are stored in different places. She wants to record where the CDs are stored. She decides to write a program to do this. The program must store the data in a file, HyMusic. (@) () Whyisa file needed? pecmonently eedes...S0 ink heat san ed evdm odber the. commukes oo == i) (Wl) Myttusiic is a text file with the data for each CD as one line of text. Data for a typical CD are: Title: Kind of Green Artist: Miles Coltrane Location: Rlack1-5 The line will be formed by concatenating the three data items. For tho example above, the line stored will be: Kind of GreenMiles ColtraneRack1-5 Deseribe a problem that might occur when organising the data in this way. Describe a possible solution. can be used A Saptcares...owachr.. foe caomels:5. 8... lard.He ‘a (b) Toni must input the data into the file for all of her CDs. A procedure, Input Data, is needed to do this. Toni designs the procedure and chooses the following identifiers: " Identifier | Data type STRING STRING STRING The procedure repeatedly performs the following steps: + input a CD title (A rogue value of “##” is to be used to end the input) + input the artist * input the location * create the text line + write the text line to the file When the rogue value is encountered the file is closed. 02, The information is stored in a text file, s text file is as follows: oreDetails.txt. The format of each line of the + Membershiptumber is a four-digit numeric string + pate is a six-digit numeric string in the format DDMMYY Score is a two-digit numeric string in the range "50" to "99" Aprocedure, AddNewScores (), is being developed. This will allow the user to enter scores for several members on a particular date. The procedure, AddNewscores (), will perform the following actions: 1. Prompt for the date of the scores. 2. Input the date of the scores. 3. Prompt for the membership number. 4. Input the membership number. 5. Ifthe membership number is an emply string then end the procedure. 6. Prompt for the score. 7. Input the score. 8. Validate the score. 9. Ifthe validation fails then repeat from step 6. 0. Form a text string from the data and write this to the ScoreDetails. txt file }1. Repeat from step 3. Write Pseudocode for the AdaNeuscores() procedure. RROLEDURE... KAANew Scones O) DECLARE. Filemaker Koreboka, Member” sui pNumber, Scone: STRING OUTPUT.“ Gnker dake..of scants” INPUA Sere ake. GRENFELL E.* Sore Debebte. txk" FoR APPEND vs eos...“ \veuk membedlp nuwsber” ANC. Sebvedaker momberde pNumber WHILE, aan. Mem borshioNunber £5“ ” OUTCUT, “Canker score” NEON Sen ce eae te AWCeord 2) OUTPUT “Inpuk.. store, behwewn So and. 94% ANQUT Scone ENwowie Fiterla= MembersuaNunbe & Sore bate & Lone, WIRMIEFILE. “Scone bekails-tah", Fienaka. ONO Inp We. meen bees meen lye \NEoL Membershipaumger Qrownhe CLOSEFILE CScorenetails tak) PAO RocEMURE (9) 03. A procedure, count tines (), i being written to count the number of lines in a text fie, The procedure will take a flename asa string parameter ‘count the number of lines in the file ‘output a single suitable message that includes the total number of lines. White pseudocode forte procedure counttines Vpgece wee CounkLines CH Ve Name Shing) DECLARE LineNurs. ANTEC DECURRE umnedeka: STRING LineNun SO OPENTILE. FileName... Fon... PEND. WHILE Nov. Eor CEi\ BERDEILE. Ge Name ,.. Une Dele... FUE ARAL NirdineAed Lina Num CLint Noes) LROWWALE, CLOSE. Filename, OUTRUT “Ne. ok, Uaneb =". Line Nuuen ENvRRocepuce. 6) 04, (a) A concert venue uses a program to calculate admission prices and store information about ticket sales. fanto be inboragn atthe sar ofeach day bere ony tts canbe St The process very ime consuming, (1) Explain how the program could us text les to speed up the process, Dake..coun. Ve. sowed... permanunkly. in. Ges. bulore toabetotser inning ofA. compute ..The dade. coud Not. saad...feor Yne. RLE..anck added... loadk....to ASA CAND VING Hne....NCRO: Or eoeatening. Berke. (2) (i) State the characterise of text fes hat alow them tobe used a explained in pat (() Roako.in...heak Rls is Stored permanently (1) (itl) information about ticket sales will be stored as a booking. The booking requires the following data: + name of person booking + number of people in the group (for example a family ticket or a school party) + event type. ‘Suggest how data relating to each booking may be stored in a text file. Dake. vhems.are..cormbined.\0. form... Single Skeiny ond ave. sapecnker...\oy...0..Checad er.nod sodeds. ys. Mae. dake: 2 (b) Aprocedure Preview () will take the name of a text file as a parameter output e warning message i the fl s empty otherwise output the first five lines from the file (or as many lines as there are in the file if this number is less than five) Write pseudocode forthe procedure Preview) PROCEDURE PrewiewCFieName STRING) DECLARE, LineNum = \NIEGER | DECLARE F lineata: TLRANG _OPEMEILE, Filename, EOR READ \e Eee ( FileName) THEN DVT RYT, Sewarcning Ble is amply”. ELSE. oe LaneNune\ ALLE LineNum © C25 AND. NOR. Core CUWMEIIAD (Serr REROFILE, CW May Main FileName, Ling Daba OULRAH ARMA. 907._. Linedato LineNuwn & LindgNum +) ENWRILE ENn IE. CLOSbFILE, ile Name. ENPROLED ORE.

You might also like