Topics

Search This Blog

Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Friday, March 21, 2025

Important Points: Computer Programming

Computer Programming/Modular Programming/File Handling

  1. Modular Programming: Process of writing program in multiple modules
  2. Main Module: The main part of the program inside which several sub modules are created
  3. Sub program: A group of statements written in a separate module to perform one or more tasks
  4. Formal Parameter: Parameter used while declaring and defining sub-program or user-defined functions 
  5. Actual Parameter: Parameter used while calling sub-procedure or user defined function 
  6. Local Variable: The variable which is recognized only inside the module where it is declared 
  7. Global Variable: The variable which can be accessed from all the modules.
  8. File Handling: File handling is a mechanism to work with file so that we can read and write data from and into a disk file through QBASIC program.
  9. Output Mode: Output mode creates a new file and opens it to store data.
  10. Append Mode: Append mode opens an existing file to add records.
  11. Input Mode: Input mode opens and existing file to read records.
  12.  File management command: File management command operates various task in a program. (Ex. FILES, MKDIR, CHDIR, RMDIR, NAME...AS, KILL and SYSTEM)

Thursday, March 20, 2025

Terminology of Programming

Important terminologies:

  • Variable: A storage location for data in a program.
  • Loop: A command to repeat actions in a program.
  • If-Else Statement: A structure for decision-making in programming.
  • Function: A reusable block of code to perform a specific task.
  • Debugging: Finding and fixing errors in code.

Monday, March 17, 2025

PRACTICE QUESTIONS: 'DEBUG'

 PRACTICE QUESTIONS: 'DEBUG'

Re-write the following programs after correcting the bugs: 

Question no. 1 

CLS 

OPEN "Marks.dat" FOR INPUT AS #1 

DO WHILE EOF(1) 

    INPUT #2, Name$, Subject$, Marks 

    IF Marks > 80 THEN 

    PRINT Name$ 

LOOP 

CLOSE 

END 

 

Question no. 2 

CLS 

OPEN "Student.dat" FOR INPUT #1 

WHILE NOT EOF(1) 

    INPUT ROLL, NAME$, CLASS 

    PRINT ROLL, NAME, CLASS 

LOOP 

CLOSE #1 

END 

 

Question no. 3 

CLS 

DISPLAY "Staff.dat" FOR APPEND AS #1 

INPUT "Enter name"; NAME$ 

INPUT "Enter post"; POST 

PRINT #1, NAME$, POST$ 

CLOSE 1 

END 


Question no. 4 

DECLARE SUB SQUARE(N) 

CLS 

INPUT "Enter a number"; N 

CALL SQUARE(N) 

END 

SUB SQUARE(N) 

SQR = N x N 

PRINT "Square is"; SQR 

END 

 

Question no. 5 

DECLARE SUB FACTORIAL(N) 

CLS 

INPUT "Enter a number"; N 

CALL FACTORIAL(A) 

END 

SUB FACTORIAL(N) 

F = 1 

FOR I = 1 TO N 

F = F x n 

NEXT 

PRINT "Factorial is"; F 

END 


Question no. 6 

DECLARE FUNCTION SQUARE(N) 

DECLARE SUB SQUAREROOT(N) 

CLS 

INPUT "Enter a number"; N 

PRINT "Square is"; SQUARE(N) 

CALL SQUAREROOT(N) 

FUNCTION SQUARE(N) 

SQUARE = N * 2 

END FUNCTION 

SUB SQUAREROOT(N) 

PRINT "Square root is"; SQUARE(N) 

END SUB 


Question no. 7 

DECLARE SUB SI(P, R, T) 

CLS 

REM "Enter Principal, Rate, and Time"; P, R, T 

CALL SUB SI(P, R, T) 

END 

SUB SI(P, R, T) 

SIMPLEINTEREST = (P * R * T) ÷ 100 

PRINT "Simple Interest is"; SIMPLEINTEREST 

END 


Questions no. 8 

REMARK to display Employee Records 

OPEN "Employee.dat" FOR OUTPUT AS #1 

WHILE NOT EOF(1) 

INPUT #1, ID, NAME$, SALARY$ 

PRINT ID, NAME$, SALARY 

LOOP 

CLOSE #1 

END 

 

Question no. 9 

OPEN "Employee.dat" FOR APPEND AS #1 

DO WHILE NOT EOF(1) 

    INPUT #1, ID, NAME$, SAL 

    PRINT "ID:"; ID; "Name:"; NAME$; "Salary:"; SALARY 

WEND 

CLOSE #2 

STOP 

 

Question no. 10 

REM to write Student Marks to a File 

OPEN "Marks.dat" FOR INPUT AS #1 

INPUT "Enter name": NAME$ 

INPUT "Enter marks"; MARKS 

WRITE NAME$, MARKS 

CLOSE 1 

END 

 

Question no. 11 

REM Calculate Factorial 

DECLARE SUB FACTORIAL(N) 

CLS 

READ "Enter a number"; N 

CALL FACTORIAL(N) 

END 

SUB FACTORIAL(N) 

F = 1 

FOR I = 1 TO N 

    F = F * 1 

NEXT I 

PRINT "Factorial is"; F 

FACTORIAL=F 

END 

 

Question no. 12 

REM Display Even Numbers Between 1 to 20 

DECLARE SUB EVEN NUMBERS() 

CLS 

CALL EVEN_NUMBERS 

END 

SUB EVEN_NUMBERS() 

FOR I = 1 TO 20 

    IF I MOD 0 = 2 THEN PRINT I 

NEXT  

END 

 

Question no. 13 

REM Calculate Cube of a Number 

DECLARE FUNCTION CUBE(N) 

CLS 

INPUT "Enter a number"; N 

R=CUBE 

PRINT "Cube is"; CUBE(R) 

END 

FUNCTION CUBE(N) 

CUBE = N * 3 

END  


Question no. 14  

REM Calculate Area of a Circle 

DECLARE FUNCTION AREA(R) 

CLS 

INPUT "Enter radius"; Radius 

PRINT "Area of circle is"; AREA(R) 

END 

FUNCTION AREA(R) 

ARE = 3.14 * R * 2 

FUNCTION 


Question no. 15 

REM Calculate Square and Square Root 

DECLARE FUNCTION SQUARE(N) 

DECLARE SUB SQUAREROOT(N) 

CLS 

INPUT "Enter a number"; N 

PRINT "Square is"; SQR(N) 

CALL SQUAREROOT(N) 

END 

FUNCTION SQUARE(N) 

SQR = N * 2 

END FUNCTION 

SUB SQUAREROOT 

PRINT "Square root is"; SQR(N) 

END SUB 


Question no. 16:  

REM Calculate Simple Interest Using Sub Procedure 

DECLARE SUB SI(P, R, T) 

CLS 

INPUT "Enter Principal, Rate, and Time"; P, R, T 

SI(P, R, T) 

END 

SUB SI(P, R, T) 

SIMPLEINTEREST = (P * R * T) / 100 

PRINT "Simple Interest is"; SI 

END

Programming: QBASIC, Modular programming, File Handling, C programming

VERY SHORT ANSWER (KEYWORDS ONLY):

Programming: QBASIC, Modular programming, File Handling, C programming


1.       What is QBASIC?

Beginners' programming language

2.       Which command is used to clear the screen in QBASIC?

CLS

3.       Which statement is used to take input from the user?

INPUT

4.       Which statement is used to display output on the screen?

PRINT

5.       What is the use of the LET statement in QBASIC?

Assigns values to variables

6.       Which loop executes a block of code multiple times?

FOR...NEXT, WHILE...WEND, DO...LOOP

7.       What is the function of the INT() function in QBASIC?

Returns the integer part of a number

8.       Which operator is used for exponentiation in QBASIC?

^ (Caret)

9.       Which keyword is used to define a subprocedure in QBASIC?

SUB

10.   Which command is used to terminate the program execution?

END

11.   What is modular programming?

Dividing a program into smaller modules

12.   What are the two main modular programming structures?

Subroutines and Functions

13.   Which keyword is used to define a subroutine in QBASIC?

SUB

14.   Which keyword is used to define a function in QBASIC?

FUNCTION

15.   What is a module?

A self-contained program block

16.   What is the main advantage of modular programming?

Code reusability

17.   What is the difference between a function and a subprocedure?

Function returns a value; subprocedure does not

18.   Which programming technique does modular programming support?

Top-down approach

19.   Which command is used to call a function in QBASIC?

CALL function_name

20.   What is a library in modular programming?

A collection of reusable modules

21.   What is file handling?

Reading and writing files

22.   Which statement is used to open a file in QBASIC?

OPEN

23.   Which mode is used to read a file?

INPUT

24.   Which mode is used to write to a file?

OUTPUT

25.   Which mode is used to add data to an existing file?

APPEND

26.   Which statement is used to read data from a file?

INPUT #

27.   Which statement is used to write data to a file?

PRINT #

28.   Which function checks the end of a file in QBASIC?

EOF()

29.   Which statement is used to close a file in QBASIC?

CLOSE

30.   What is the purpose of a sequential data file?

Stores data in a continuous sequence

31.   What is structured programming?

Organizing code using functions and loops

32.   Which are the main control structures in structured programming?

Sequence, Selection, Iteration

33.   What is the main advantage of structured programming?

Better code readability and maintenance

34.   Which symbol is used to terminate a statement in C?

Semicolon (;)

35.   Which function is used to display output in C?

printf()

36.   Which function is used to take input in C?

scanf()

37.   Which loop is used for definite iteration in C?

for loop

38.   What is a function in C?

A reusable block of code

39.   Which keyword is used to define a function in C?

void, int, float, etc.

40.   What is recursion in C?

A function calling itself

Map of Nepal

 नेपालको विभिन्न भूगोलसँग सम्बन्धित नक्साहरू नेपालको नक्सा: नेपालको नक्सा: नेपालको नक्सा: नेपालको नक्सा: नेपालको नक्सा: नेपालको नक्सा:

Most viewed!