Wednesday, February 26, 2025

QBASIC File Handling Programming Solutions



TYPE 1: [Store,Write]

1. Create a data file to store the records of few employees having Name, Address, Post, Gender and Salary fields.

OPEN “std.rec” FOR OUTPUT AS #1

CLS

DO

INPUT “Enter Name”; N$

INPUT “Enter Address”; A$

INPUT “Enter Post”; P$

INPUT “Enter gender”; G$

INPUT “Enter Salary”; S

WRITE #1, N$, A$, P$, G$, S

INPUT “Do you want to continue”; CH$

LOOP WHILE UCASE$(CH$) = “Y”

CLOSE #1

END

 

2. Write a program to store Roll no., Name, Class and Address of any five students.

OPEN "Student.dat" FOR OUTPUT AS #1

CLS

FOR I = 1 TO 5
INPUT "Enter Roll No."; R
INPUT "Enter Name"; N$
INPUT "Enter Class"; C
INPUT "Enter Address"; A$
WRITE #1, R, N$, C, A$
NEXT I
CLOSE #1
END

 

3. Create a sequential data file’Price.dat’ to store item name, quantity and Rate also calculate total amount (total=Quantity X Rate). Program should terminate according to the user’s choice. 

OPEN “price.dat” FOR OUTPUT AS #1

CLS

DO

INPUT “Enter Item Name”; N$

INPUT “Enter Quantity”; Q

INPUT “Enter Rate”; R

T = Q * R

WRITE #1, N$, Q, R, T

INPUT “Do you want to continue”; CH$

LOOP WHILE UCASE$(CH$) = “Y”

CLOSE #1

END

 

4. Create a sequential data file’post.dat’ to store name and marks of any three subjects also calculate total and percentages only for 15 students.

OPEN "post.dat" FOR OUTPUT AS #1

CLS

FOR I = 1 TO 15
INPUT "Enter Name"; N$
INPUT "Enter marks in 1st Subject:”; A

INPUT “Enter marks in 2nd Subject:”; B

INPUT “Enter marks in 3rd Subject:”; C
T = A + B + C

P = T / 3

WRITE #1, N$, A, B, C, T, P

NEXT I
CLOSE #1
END

 

Note: TYPE 1: [ADD] Just replace OUTPUT with APPEND

[HW]A sequential data file called “student.dat” contains some records under the fields name, english, nepali and computer. Write a program to add some more records in the same sequential data file.

[HW]A sequential data file “RECORD.DAT” store Name, Address and Salary of employees of an office. WAP to add some more records in the data file “RECODR.DAT”. The program should terminate with user choice.

 

 TYPE 2: [Display,Print,Read,View,Retrive]

1. Students' name, class, section and address are stored in a data file called "STUDENT.DAT" Write a program to print all the records of students.

OPEN “STUDENT.DAT” FOR INPUT AS #1

CLS

WHILE NOT EOF(1)

INPUT #1, N$, C, S$, A$

PRINT “Name:”; N$

PRINT “Class:”; C

PRINT “Section:”; S$

PRINT “Address:”; A$

WEND

CLOSE #1

END

 

Write a program to display the first 10 records from a file named “resource.dat” having fields name, phone and email.

OPEN "RESOURCE.DAT" FOR INPUT AS #1

CLS

FOR I = 1 TO 10

INPUT #1, N$, C, R

PRINT N$, C, R

NEXT I

CLOSE #1

END

 

2. Employee's name, address, gender and salary are stored in the "EMP.DAT" sequential data file. Write a QBASIC program that displays all information about personnel whose salaries exceed 60000.

OPEN "EMP.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

INPUT #1, N$, A$, G$, S

IF S > 60000 THEN

PRINT “Name:” N$

PRINT “Address:” A$

PRINT “Gender:” G$

PRINT “Salary:” S

END IF

WEND

CLOSE #1

END

 

3. A data file, "Salary Dat" contains the information of the employee regarding their Name, Post and Salary. Write a program to display all the information of employee whose salary is greater than 15,000 and less than 40,000.  

OPEN "Salary.dat" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

INPUT #1, N$, P$, S

IF S>15000 AND S<40000 THEN

PRINT “Name:”; N$

PRINT “Post:”; P$

PRINT “Salary:”; S

WEND

CLOSE #1

END

 

4. A data file "PABSON.TXT" contains the records composed of the fields like school, principal, address, contact. Write a program in QBasic to display records of the schools located in either Kathmandu or Palpa

OPEN "PABSON.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

INPUT #1, S$, P$, A$, C

IF UCASE$(A$) = “KATHMANDU” OR UCASE$(A$) = “PALPA” THEN

PRINT “School:”; S$

PRINT “Principal:”; P$

PRINT “Address:”; A$

PRINT “Contact:”; C$

WEND

CLOSE #1

END

 

5. A sequential data file called "Employee.txt" has stored data under the field headings Employee ID, Name, Gender, Department, and Salary. Write a program to display all the information of those employees whose salary is greater than 50,000 and the department is "IT". 

OPEN “Employee.txt” FOR INPUT AS #1

CLS

WHILE NOT EOF(1)

INPUT #1, ID, N$, G$, D$, S

IF S> 50000 AND UCASE$(D$) =”IT” THEN

PRINT “Employee ID:”; ID

PRINT “Name:”; N$

PRINT “Gender:”; G$

PRINT “Department:”; D$

PRINT “Salary:”; S

END IF

WEND

CLOSE #1

END

 

(H/W) A sequential data file called “Record.txt” has stored data under the field heading Roll No., Name, Gender, English, Nepali, Maths and Computer. Write a program to display all the information of those students whose gender is “F” and obtained marks in computer is more than 90.

 

6. A sequential data file "EMP.DAT" contains name, post and salary fields of information about employees. Write a program to display all the information of employees along with tax amount also (tax is 15% of salary).  

OPEN "EMP.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF(1)

INPUT #1, N$, P$, S

T = 15 / 100 * S

PRINT “Name:” N$

PRINT “Post:”; P$

PRINT “Salary:”; S

PRINT “Tax amount:”; T

WEND

CLOSE #1

END  

 

(H/W) A sequential data file called "data.dat" has stored data under the field heading item name, quantity and rate. Write a program to display all the records with total.

(H/W) A sequential data file named “nabil.txt” contains record of clients of a bank including depositor’s name, deposited amount, time and rate of interest. Wap to display detail of all depositors including simple interest.

 

7. A data file "LIB.TXT" consists of Book's name, Author's name and price of books. Write a program to count and display the total number of records present in the file.

OPEN "LIB.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF(1)

INPUT #1, B$, A$, P  

C = C + 1

PRINT “Book's name:”; B$

PRINT “Author's name:”; A$

PRINT “Price of books:”; P

WEND

PRINT "Total number of records:"; C

CLOSE #1

END

 

(H/W) Write a program in QBASIC to open a sequential data file “EMP.DAT”, which contains employees records: Name, address and phone number and display all the records as well as total number of records stored in the file. 

 

8. Write a program which reads records from the file” Result.DAT” having the fields name and marks of three different subjects and display only those records whose percentage is greater than 60 and less than 80. Also count the total number of records presenting in that data files.

OPEN "Result.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF(1)

INPUT #1, N$, S, M, E

C=C+1

T=S+M+E

P=T/3

IF P > 60 AND P < 80 THEN 

PRINT “Name:”; N$

PRINT “Marks in Science:”; S

PRINT “Marks in Math:”; M

PRINT “Marks in English:”; E

PRINT “Total:”; T

PRINT “Percentage:”; P

WEND

PRINT “Total number of records:”;

CLOSE #1

END

 

Only For A+ Students and more practice

1. Store SIDNO, name, address and Telephone number of five students and display the records on monitor in sequential data file “STDINFO”.

OPEN "STDINFO.DAT" FOR OUTPUT AS #1

CLS

FOR I = 1 TO 5

INPUT "ENTER NAME"; N$

INPUT "ENTER ADDRESS"; A$

INPUT "ENTER TELEPHONE"; T$

WRITE #1, N$, A$, T$

NEXT I

CLOSE #1

OPEN "STDINFO.DAT" FOR INPUT AS #1

CLS

FOR I = 1 TO 5

INPUT #1, N$, A$, T$

PRINT N$, A$, T$

NEXT I

CLOSE #1

END

 

2. A sequential data file "Student.dat" has stored data under the field headings: student id, student's name, address and age of some students. Write a program to copy all the records of those students whose age is greater than 15 to another file named as "Record.dat".

OPEN "Student.dat" FOR INPUT AS #1

OPEN "Record.dat" FOR OUTPUT AS #2

WHILE NOT EOF(1)

INPUT #1, ID, N$, A$, AG

IF AG > 15 THEN

WRITE #2, ID, N$, A$, AG

END IF

WEND

CLOSE #1

CLOSE #2

END

 

3. A sequential data file “STD.TXT” contains name and marks in three different subjects of some students. Write a program to display only fail student’s records assuming pass marks 40.

OPEN "STD.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

INPUT #1, N$, A, B, C

IF A < 40 AND B < 40 AND C < 40 THEN

PRINT “Name:”; N$

PRINT “Marks in 1st subject:”; A$

PRINT “Marks in 2nd subject:”; B$

PRINT “Marks in 3rd subject:”; C$

WEND

CLOSE #1

END

 

4. A sequential data file has 100 records having field name, class and roll number. Write a program to display from 50th to 60th records.

OPEN "ABC.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

INPUT #1, N$, C, R

D = D + 1   

IF D >= 50 AND D <= 60 THEN PRINT N$, C, R

WEND

CLOSE #1

END

 

5. A data file name “EMP.DAT”, contains number of records having fields name, post and salary. Write a program to count total number of “Manager” in the data file.

OPEN "EMP.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

INPUT #1, N$, P$, S

IF UCASE$(P$) = “MANAGER” THEN PRINT C = C + 1

WEND

PRINT “Total number of managers:”; C

CLOSE #1

END

 

6. A sequential data file’post.dat’ has few records related to name, address, salary. WAP to display the records whose address begins with ‘S’ or ‘D’

OPEN "POST.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

INPUT #1, N$, P$, S

A$ = UCASE$(LEFT$(N$,1))   

IF A$ = “S” OR A$ = “D” THEN PRINT N$, P$, S

WEND

CLOSE #1

END


8. A sequential data file called "list.dat" has stored data under the field heading items name quantity and rate. Write a program to update all the records by increasing the rate by 10%.

OPEN "list.dat" FOR INPUT AS #1

OPEN "temp.dat" FOR OUTPUT AS #2

WHILE NOT EOF(1)

INPUT #1, item$, quantity, rate

rate = rate + 10/100 * rate

WRITE #2, item$, quantity, rate

WEND

CLOSE #1, #2

KILL "list.dat"

NAME "temp.dat" AS "list.dat"

END

 

9. A sequential data file “marks.dat” contains information such as student’s name, marks obtained in math, science and computer. Write a program that increase the marks of computer by 10 of those students who secured less than 40

OPEN "marks.dat" FOR INPUT AS #1

OPEN "temp.dat" FOR OUTPUT AS #2

CLS

WHILE NOT EOF(1)

    INPUT #1, N$, A, B, C

    IF C > 40 THEN

        WRITE #2, N$, A, B, C

    ELSE

        C = C + 10

        WRITE #2, N$, A, B, C

         END IF

WEND

CLOSE

KILL "marks.dat"

NAME "temp.dat" AS "temp.dat"

END

10. Delete some records from “neps.dat” file where computer ask user to enter the record, which is to be deleted. (Fields are name, address, and telephone number) 

OPEN “NEPS.DAT” FOR INPUT AS #1

OPEN “TEMP.DAT” FOR OUTPUT AS #1

CLS

INPUT “Enter name which is to be deleted”; D$

WHILE NOT EOF(1)

INPUT #1, N$, A$, T

IF UCASE$(D$) <> UCASE$(N$) THEN

WRITE #2, N$, A$, T

ELSE

PRINT “Deleted data:”; N$, A$, T

END IF

WEND

CLOSE #1, #2

KILL “NEPS.DAT”

NAME “TEMP.DAT” AS “NEPS.DAT”

END

Wednesday, February 19, 2025

SOLVED National PABSAN COMPUTER SCIENCE SEE Pre-Board Examination-2081



GROUP 'A'

1. Answer the following questions:

a. What is transmission signal?

A transmission signal is a type of signal (like electrical, light, or radio waves) that carries information from one place to another.

 

b. What is logical threat in cyber field?

A logical threat in the cyber field refers to a type of threat that targets the software, data, or systems of a computer or network.

 

c. Which data type is suitable to store of student name in MS-Access?

In MS-Access, the Text data type is suitable for storing a student's name.

 

d. What is report?

Report is one of the MS-Access database objects used to present information in an effective and organized format that is ready for printing.

 

e. What is formal parameter?

Formal parameters are variables used in a function or procedure to receive values when the function is called.

 

f. Write down two header files use in C language.

The two header files use in C language are stdio.h and conio.h

 

2. Write appropriate technical term for the following:

a. The rule followed by computer in a network for communication. Protocol 

b. Learning through internet. E-learning

 

3. Write the full form of the following:

a. MODEM - Modulator-Demodulator

b. W3C - World Wide Web Consortium

 

GROUP 'B'

4. Answer the following questions:

 

a. Write the difference between client/server and peer to peer network.

Client-Server Network

Peer to Peer Network

In a client-server network, powerful computers called servers provide resources and services, while other computers, known as clients, access these resources and services.

In a peer-to-peer network, all computers have equal roles and can both provide and request resources without a centralized server.

Security and data management are handled by the server. Network administrator manages and enforces security policies.

Security is managed individually on each peer. Each peer is responsible for its own security and data.

 

 

 

b. What is computer UPS?

UPS is a battery supported power protection device which controls the electric voltage and supplies clean and continuous power to the computer system even during power failures.

 

c. What is cryptography?

Cryptography is the practice of using techniques to secure and protect information by converting it into a coded format ensuring that only authorized users can access or understand it.

 

d. What is e-commerce? Write down advantages of it.

E-commerce, or electronic commerce, refers to the buying and selling of goods and services over the internet.

Advantages of E-commerce

·       Faster buying/selling procedure, as well as easy to find products.

·       There are no geographical limitations, can deliver service globally.

 

e. What are the common models of e-commerce?

The common models of e-commerce are:

a)     Business to Consumer (B2C):
The most common type of E-Commerce is Business-to-Consumer. B2C establishes the electronic business relationships between a business organization (merchant) and final consumers.

(e.g. We buy a pair of shoes from an online retailer)

Amazon. com is a good example of B2C e-commerce.

b)     Business to Business (B2B):
Business-to-Business (B2B) e-commerce is conducted between companies. Individual customer cannot buy from this type of e-commerce. Producers and wholesalers typically operate with this type of electronic commerce.

(e.g. A business sells software-as-a-service for other businesses to use)

Alibaba.com is a good example of B2B e-commerce.

c)     Consumer to Consumer (C2C):
Consumer-to-Consumer (C2C) type of e-commerce is conducted between consumers.

These transactions are conducted through a third party, which provides the online platform where the transactions are actually carried out.

(e.g. You sell your old furniture on hamrobazar to another consumer)

Hamrobazaar.com is a good example of C2C website in Nepal.

d)     Consumer to Business (C2B):
When a consumer sells their own products or services to a business or organization

(e.g. An influencer offers exposure to their online audience in exchange for a fee, or a photographer licenses their photo for a business to use).

 

f. Write the difference between update query and select query.

 

Select Query

Update Query

- A select query is the most common category which is used to extract specific information from one or more tables in a database.

- The Select query is used to select data from a database.

- Update query is a type of action query which makes global changes to a group of records in one or more tables.

- The Update query is used to update existing records in a table.

 

 

g. What is sorting? Write down two advantages of it.

The process of arranging all the records in a table either ascending or descending order based on field or fields is known as sorting. Sorted data is easier to handle than unsorted data.

The advantages of sorting are:

·       Sorting helps to organize data and make it easier to find and retrieve specific information.

·       Sorting can save time and improve efficiency by allowing users to quickly access the data they need.

 

 

h. What is table? Which view use to create table?

Tables are the primary building block of database which stores and manages large volume of data into rows and column.

Design view is used to create table.

 

i. What is data type? Give examples.

Data type is an attribute for a field that determines the type of data that can be stored in that field.

Examples of data type are: text, memo, Date/Time, Yes/No etc.

 

5. Write down the output of the given program:

DECLARE SUB SERIES ( )

CALL SERIES

END

SUB SERIES

N$ = “*”

FOR 1 TO 5

FOR J=1 TO I

PRINT N$;

NEXT J

PRINT

NEXT I

END SUB

Dry Run Table

N$

FOR 1 TO 5

J=1 TO I

PRINT N$

*

1 TO 5 Yes

1 TO 1 Yes

*

 

 

2 TO 1 No

 

 

2 TO 5 Yes

1 TO 2 Yes

*

 

 

2 TO 2 Yes

**

 

 

3 TO 2 No

 

 

3 TO 5 Yes

1 TO 3 Yes

*

 

 

2 TO 3 Yes

**

 

 

3 TO 3 Yes

***

 

 

4 TO 3 No

 

 

4 TO 5 Yes

1 TO 4 Yes

*

 

 

2 TO 4 Yes

**

 

 

3 TO 4 Yes

***

 

 

4 TO 4 Yes

****

 

 

5 TO 4 No

 

 

5 TO 5 Yes

1 TO 5 Yes

*

 

 

2 TO 5 Yes

**

 

 

3 TO 5 Yes

***

 

 

4 TO 5 Yes

****

 

 

5 TO 5 Yes

*****

 

 

6 TO 5 No

 

 

6 TO 5 No

Loop Exits

 

 

The output of the Program is:

*

**

***

****

*****

6. Re-write the given program after correcting the bugs:

DECLARE FUNCTION SQ$ (N)

CLS

FOR I=1 TO 10

DISPLAY SQ (N)

NEXT N

END

FUNCTION SQ (N)

SQ=N^2

END FUNNCTION

 

Debugged Program

DECLARE FUNCTION SQ (N)

CLS

FOR N=1 TO 10

PRINT SQ (N)

NEXT N

END

 

FUNCTION SQ (N)

SQ=N^2

END FUNCTION

 

7. Study the following program and answer the given questions: 2x1=2

DIM N (10)

DECLARE SUB MIN (N ( ))

CLS

FOR I=1 TO 10

INPUT "ENTER A NUMBER"; N (I)

NEXT I

CALL MIN (N ( ))

END

SUB MIN (N  ())

S=N (1)

FOR 1=2 TO 10

IF SN > N(I) THEN S=N (I)

NEXT I

PRINT "THE SMALLEST NUMBER=”;S

END SUB

 

a. Which is array variable in above program?

The array variable in above program is N.

 

b. Which is control statement in above program?

The control statement in the program are:

·       FOR...NEXT loop

·       IF...THEN statement

 

 

 

 

 

 

 

 

Convert/Calculate as per the instruction:

a. (165)10 = (?)2

 

Divide by the base 2 to get the digits from the remainders:

Division
by 2

Quotient

Remainder

(Digit)

(165)/2

82

1

(82)/2

41

0

(41)/2

20

1

(20)/2

10

0

(10)/2

5

0

(5)/2

2

1

(2)/2

1

0

(1)/2

0

1

= (10100101)2

(165)10  = (10100101)2

 

 

 

b. (101111)2=(?)8

 

Convert every 3 binary digits (from bit0) to octal digit:

101111

5= 101

7 =111

= 5 7

(101111)2=(57)8

 

с. (101001) x (101)

 

 

1

0

1

0

0

1

 

 

 

 

x

1

0

1

 

 

1

0

1

0

0

1

 

0

0

0

0

0

0

x

1

0

1

0

0

1

x

x

1

1

0

0

1

1

0

1

(101001) x (101) = (11001101)

 

d. (1101110) / (1101)

1101)

1

1

0

1

1

1

0

(1000

 

1

1

0

1

 

 

 

 

 

0

0

0

0

1

1

0

 

 

 

 

 

 

 

 

0

 

 

 

 

 

 

1

1

0

 

 

 

 

 

 

 

 

 

 

Q=1000

R=110

 

9. Answer the following questions:

a. Write a program in QBASIC that asks length in meter then display length in centimeter by using FUNCTION. END FUNCTION and length in millimeter by using SUB.. END SUB.

[Hint 1 meter = 100 Centimeters 1 meter= 1000 Millimeters]

 

 

 

 

DECLARE FUNCTION MTC(M)

DECLARE SUB MTM(M)

CLS

INPUT "Enter Length in meter: "; M

PRINT "Length in centimeter: "; MTC(M)

CALL MTM(M)

END

 

FUNCTION MTC(M)

    CM = M * 100

MTC = CM

END FUNCTION

 

SUB MTM(M)

    MM = M * 1000

    PRINT "Length in millimeter : "; MM

END SUB

 

b. Write a program to read records from file name "Rec.dat" and display all the records those post is manager. File contains field names are employees Name, Post, Date of birth, e-mail address and Salary.

OPEN “Rec.dat” FOR INPUT AS #1

CLS

PRINT “Name”, “Post”, “Date of Birth”, “E-Mail”, “Salary”

WHILE NOT EOF(1)

INPUT #1, N$, P$, D$, E$, S

IF UCASE$(P$) = “MANAGER” THEN PRINT N$, P$, D$, E$, S

WEND

CLSOE #1

END

 

10. Write a program in C-language that ask length, breadth and height then display volume of box. 4

[Hint: volume=LxBxH]

 

#include <stdio.h>

int main( )

{

    float length, breadth, height, volume;

    printf("Enter the length of the box: ");

    scanf("%f", &length);

    printf("Enter the breadth of the box: ");

    scanf("%f", &breadth);

    printf("Enter the height of the box: ");

    scanf("%f", &height);

    volume = length * breadth * height;

    printf("The volume of the box is: %.2f\n", volume);

    return 0;

}

 

Or

Write a program in C-language to display the series 5, 10, 15, 20, 25 up to 10th term.

 

#include <stdio.h>

int main( )

{

    int i, term;

 

    for (i = 1; i <= 10; i++) {

        term = 5 * i; 

        printf("%d ", term); 

    }

    printf("\n"); 

    return 0;

}