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

Programming tasks 3-3-2025

The document contains a series of programming questions and solutions, primarily focused on basic file operations, loops, conditionals, and functions in a pseudocode format. Each question demonstrates different programming concepts such as reading from and writing to files, iterating through arrays, and implementing basic logic for user input. Overall, it serves as a practical guide for understanding fundamental programming constructs.

Uploaded by

bilawalimran313
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)
5 views

Programming tasks 3-3-2025

The document contains a series of programming questions and solutions, primarily focused on basic file operations, loops, conditionals, and functions in a pseudocode format. Each question demonstrates different programming concepts such as reading from and writing to files, iterating through arrays, and implementing basic logic for user input. Overall, it serves as a practical guide for understanding fundamental programming constructs.

Uploaded by

bilawalimran313
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/ 8

Q1.

DECLARE str1 : STRING

OPENFILE "NumberFile.txt" FOR READ

WHILE NOT EOF("NumberFile.txt")

READFILE "NumberFile.txt", str1

OUTPUT str1

ENDWHILE

CLOSEFILE "NumberFile.txt"

Q2.

PROCEDURE Print100

DECLARE count : INTEGER

FOR count <- 1 TO 100

OUTPUT count

NEXT count

ENDPROCEDURE

Q3.

FUNCTION Multiply(a : INTEGER, b : INTEGER) RETURNS INTEGER

return a * b

ENDFUNCTION

Page 1 of 8
Q4.

DECLARE searchVal : STRING

DECLARE count : INTEGER

DECLARE found : BOOLEAN

DECLARE DataArray : ARRAY[1:5] OF CHAR

DataArray <- ["A","B","C","D","E"]

OUTPUT "Enter letter to search"

INPUT searchVal

found <- FALSE

FOR count <- 1 TO LENGTH(DataArray)

IF DataArray[count] = searchVal

THEN

found <- TRUE

ENDIF

NEXT count

IF found

THEN

OUTPUT "Letter is in array"

ELSE

OUTPUT "Letter not in array"

ENDIF

Page 2 of 8
Q5.

DECLARE Number : ARRAY[1:10] OF INTEGER

DECLARE count : INTEGER

OPENFILE "NumberFile.txt" FOR WRITE

FOR count <- 1 TO LENGTH(Number)

WRITEFILE "NumberFile.txt", Number[count]

NEXT count

CLOSEFILE "NumberFile.txt"

Q6.

DECLARE count : INTEGER

FOR count <- 10 TO 1 STEP -1

OUTPUT count

NEXT count

OUTPUT "Blast off!"

Page 3 of 8
Q7.

DECLARE mark : INTEGER

OUTPUT "Please enter student mark"

INPUT mark

IF mark >= 90

THEN

OUTPUT "Grade A"

ELSE

IF mark >= 80

THEN

OUTPUT "Grade B"

ELSE

IF mark >= 70

THEN

OUTPUT "Grade C"

ELSE

IF mark >= 60

THEN

OUTPUT "Grade D"

ELSE

OUTPUT "Grade U"

ENDIF

ENDIF

ENDIF

ENDIF

Page 4 of 8
Q8.

FUNCTION TotalValues RETURNS INTEGER

DECLARE Total : INTEGER

Total <- 0

FOR X <- 1 TO 50

Total <- Total + Array[X]

NEXT X

RETURN Total

ENDFUNCTION

Total <- TotalValues()

Page 5 of 8
Q9.

DECLARE num, count, less, more, inputVal : INTEGER

OUTPUT "Enter number of integers to input:

INPUT num

count <- 0

less <- 0

more <- 0

WHILE count < num

OUTPUT "Input the number"

INPUT inputVal

IF inputVal = 0

THEN

count <- num

ENDIF

IF inputVal < 100

THEN

less <- less + 1

ELSE

more <- more + 1

ENDIF

ENDWHILE

Page 6 of 8
Q10.

DECLARE num : INTEGER

REPEAT

OUTPUT "Enter num"

INPUT num

UNTIL num = 10

Q11.

DECLARE str1 : INTEGER

str1 <- ""

WHILE str1 <> "stop"

OUTPUT "Enter word"

INPUT str1

ENDWHILE

Q12.

DECLARE file : STRING

OUTPUT "Please enter filename"

INPUT file

OPENFILE file FOR WRITE

WRITEFILE file, "house"

CLOSEFILE

Page 7 of 8
Q13.

DECLARE str1 : STRING

OPENFILE "dataStore.txt" FOR READ

READFILE "dataStore.txt", str1

CLOSEFILE "dataStore.txt"

OUTPUT str1

Page 8 of 8

You might also like