[go: up one dir, main page]

0% found this document useful (0 votes)
18 views5 pages

Unit 8 - Com Science Exam - Style Q

The document contains a comprehensive examination on computer science focusing on arrays, procedures, functions, string functions, and file handling. It includes pseudocode examples for linear search, bubble sort, and various string manipulations, along with explanations of algorithms and their purposes. Additionally, it discusses the importance of modular programming and data storage in files.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views5 pages

Unit 8 - Com Science Exam - Style Q

The document contains a comprehensive examination on computer science focusing on arrays, procedures, functions, string functions, and file handling. It includes pseudocode examples for linear search, bubble sort, and various string manipulations, along with explanations of algorithms and their purposes. Additionally, it discusses the importance of modular programming and data storage in files.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Unit 8- Com Science Exam- Style Q

Dakshesh

PART 1 - ARRAYS
Q1.1
(a) Line Numbers for Statements:
- Assignment statement: Line , Line , Line , Line
- Selection statement: Line , Line
- Iteration statement: Line , Line

(b) Errors in Pseudocode:


- Error 1: Line number
Correction: Change `Max ‹ List (Counter)` to `Max ← List (Counter)`.

- Error 2: Line number


Correction: Change `Min + List[Counter)` to `Min ← List(Counter)`.

- Error 3: Line number


Correction: Change `ENDWHILE` to `ENDIF`.

Q1.2
(a) Linear Search Algorithm in Pseudocode:

DECLARE Values : ARRAY[1:50] OF INTEGER


DECLARE MyNumber : INTEGER
DECLARE Found : BOOLEAN
DECLARE Position : INTEGER

INPUT "Enter a number:", MyNumber


Found ← FALSE
FOR Counter ← 1 TO 50
IF Values[Counter] = MyNumber THEN
Position ← Counter
Found ← TRUE
OUTPUT "Number found at position ", Position
BREAK // Exit loop if found
ENDIF
NEXT Counter
IF NOT Found THEN
OUTPUT "Not found"
ENDIF

(b) Bubble Sort Algorithm in Pseudocode:

DECLARE Values : ARRAY[1:50] OF INTEGER


DECLARE Temp : INTEGER

FOR I ← 1 TO 49
FOR J ← 1 TO (50 - I)
IF Values[J] > Values[J + 1] THEN
Temp ← Values[J]
Values[J] ← Values[J + 1]
Values[J + 1] ← Temp
ENDIF
NEXT J
NEXT I

Q1.3
(a) Purpose of the Pseudocode Algorithm:
The purpose of this algorithm is to input a list of names and sort them in ascending order.

(b) Four Processes in the Algorithm:


1. Inputting names from the user.
2. Sorting the names using a bubble sort method.
3. Outputting the sorted names.
4. Using nested loops for sorting.

(c) Meaningful Identifiers Suggestions:


- The array: `Names`
- The variables:
- `T` → `TotalNames`
- `L` → `Index`

(d) Ways to Improve Understandability:


1. Use comments to explain each section of the code.
2. Break down complex operations into smaller functions or procedures.
PART 2 - PROCEDURES & FUNCTIONS
Q2.1
- Parameter

Q2.2
A programmer uses procedures and parameters to:
- Modularize code, making it easier to manage and reuse.
- Pass data between different parts of a program without redundancy.

Q2.3
DIV: The DIV routine performs integer division, returning the quotient without the remainder.
ROUND: The ROUND routine rounds a real number to a specified number of decimal places.

Q2.4
MOD: The MOD routine returns the remainder of integer division between two numbers.
RANDOM: The RANDOM routine generates a random number within a specified range.

Q2.5
When a function is called during program execution:
- The program control is transferred to the function.
- The function executes its statements and may return a value.
- After execution, control returns to the point where the function was called.

PART 3 - STRING FUNCTIONS & FILE HANDLING

Q3.1
(a)

DECLARE FullText : STRING = "Computer Science"


DECLARE Substring : STRING

Substring ← SUBSTRING(FullText, 1, 8) // Extracts "Computer"


OUTPUT Substring

OUTPUT UCASE(FullText) // Outputs "COMPUTER SCIENCE"

(b)

DECLARE FileHandle : FILE

OPEN FileHandle FOR WRITE AS "Subjects.txt"


WRITE FileHandle, Substring // Store substring in file
CLOSE FileHandle // Close text file at end of algorithm

Q3.2

DECLARE Quote : STRING = "Learning Never Exhausts The Mind"


DECLARE Extracted : STRING

Extracted ← SUBSTRING(Quote, 21, 8) // Extracts "The Mind"


OUTPUT Extracted

OUTPUT LCASE(Quote) // Outputs original string in lower case.

Q3.3
(a)

Pseudocode Description Pseudocode Keyword


stores data in a file WRITE
retrieves data from a file READ
displays data on a screen OUTPUT
enters data from a INPUT
keyboard

(b) Reasons for storing data in a file:


1. To preserve data for future use.
2. To share data between different programs or users.

Q3.4
(a)

DECLARE Phrase : STRING = "dhruva"


DECLARE LPhrase : INTEGER

LengthOfPhrase ← LENGTH(Phrase)
OUTPUT LPhrase // Outputs length of string.
OUTPUT UCASE(Phrase) // Outputs string in upper case.
(b) Output should produce:

Length of Phrase is: [number of characters]


DHRUVA

Q3.5
(a)

DECLARE P : STRING
DECLARE Q : CHAR

P ← "The world"
Q ← 'w'

(b)

P ← UCASE(P) // Convert P to upper case.


Position ← FIND(Q IN P) // Find position of 'w' in string P.

(c) After execution, if 'P' is "THE WORLD", Position will hold the value corresponding to 'W'.

Q3.6
(a)

DECLARE Saying : STRING

(b)

INPUT Saying // Allow string input to Saying variable.


OPEN FileHandle FOR WRITE AS "subject.txt"
WRITE FileHandle, Saying // Store content in file.
CLOSE FileHandle // Ensure file is closed at end of algorithm.

You might also like