Thursday, December 29, 2016

Good Luck !!

All the best for your upcoming Exam!!

Library Function in QBASIC

1. LEFT$:
LEFT$ is a string function that allows us to extract the specific number of characters beginning from the left-most character of the string.

2. RIGHT$:
RIGHT$ is a string function that allows us to extract the specific number o characters beginning from the right-most character of the string.

3. MID$:
MID$ function returns a specific number of characters from a string.

4. LEN:
LEN function returns the number of characters in a string or the number of bytes required by a variable.

5. LCASE$:
LCASE$ function converts all the uppercase characters in lowercase.

6. UCASE$:
UCASE$ function converts string to uppercase.

7. ASC:
ASC function converts a character or a string variable to its corresponding ASC II code. Only the first character of a string is evaluated by ASC function.

8. CHR$:
CHR$ function retrieves the single character represented by the ASC II number.

9. STR$:
STR$ function converts a string expression to its string representation.

10. VAL:
VAL function converts a string expression consisting of digits into numeric value.

11. LTRIM$:
LTRIM$ function removes leading blanks from the left side of the spring expression.               

12. RTRIM$:
RTRI$ function removes trailing blanks from the right side of the string expression .

13. STRING$:
STRING$ function is used with a PRINT statement to display a particular character a specific number of times.

14. INSTR:
INSTR function returns the position of the first occurrence of a string in another string.

15. DATE$:
DATE$ function returns the current system date of the computer and allow to set the current system date.

16. TIME$:
TIME$ function returns the current system time of computer and allows to set the current time.

17. INKEY$:
 INKEY$ function checks the keyboard looking for a pressed key.

18. INPUT$:
INPUT$ function halts execution until a specified number of characters are read from the keyboard or a disk file.

19. ABS:
ABS function is used to obtain the absolute value of a numeric expression.

20. COS:
COS function computes the cosign of an angle.

21. TAN:
TAN function is used to obtain the tangent of x.

22. SIN:
SIN function is used to obtain the sine o an angle.

23. INT:
INT function is used to round the number to the integer value.

24. CINT:
CINT function returns the nearest to the given number.

25. SGN:
SGN function returns the sign of a number.

26. SQR:
SQR function returns the square root  of a number.

27. TAB:
TAB function moves the text cursor to the specified print position.

28. SPC:
The SPC function skips a number of spaces when used with the PRINT and the LPRINT statement.

29. SPACE$:
The SPACE$ function is used to print a specific number of blank spaces.

30. LOCATE:
The LOCATE statement controls the cursor, placing it on the specific row and column on the screen.


File Handling questions with its solutions

1.   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.    
                                                                      
OPEN “EMP.DAT” FOR INPUT AS #1
CLS
PRINT “NAME”, “ADDRESS”, “PHONE NUMBER”
C=0
WHILE NOT EOF(1)
INPUT #1, N$, A$, P#
PRINT N$, A$, P#
C=C+1
WEND
PRINT “TOTAL NUMBER OF RECORDS”; C
CLOSE #1
END

2.   Write a program to store records regarding the information of Book number, Book’s name and Writer’s name in a sequential data file called “Library.dat”.

OPEN “Library.dat” FOR OUTPUT AS #1
 DO
CLS
INPUT “ENTER BOOK’S NUMBER”; BN
INPUT “ENTER BOOK’S NAME”; B$
INPUT “ENTER WRITER’S NAME”; N$
WRITE #1, BN, B$, N$
INPUT “DO YOU WANT TO CONTINUE”; CH$
LOOP WHILE UCASE$(CH$) = “Y”
CLOSE #1
END

3.   Write a program to create a sequential data file “Employee.Dat” to store employees’ name, address, age, gender and salary.

OPEN “Employee.dat” FOR OUTPUT AS #1
DO
CLS
INPUT “ENTER EMPLOYEE’S NAME”; N$
INPUT “ENTER ADDRESS”; A$
INPUT “ENTER AGE”; A
INPUT “ENTER GENDER”; G$
INPUT”ENTER SALARY”; S
WRITE #1, N$, A$, A, G$, S
INPUT “DO YOU WANT TO CONTINUE”; CH$
LOOP WHILE UCASE$(CH$) = “Y”
CLOSE #1
END

4.   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
PRINT “NAME”, “POST”, “SALARY”, “TAX”
WHILE NOT EOF(1)
INPUT #1, N$, P$, S
T = 15 / 100 * S
PRINT N$, P$, S, T
WEND
CLOSE #1
END

5.    A sequential data file called “student.dat” contains some records under the field’s name, English, Nepali and Computer. Write a program to add some more records in the same sequential data file.
     
OPEN “student.dat” FOR APPEND AS #1
DO
CLS
INPUT “ENTER NAME”; N$
INPUT “ENTER MARKS IN ENGLISH”; E
INPUT “ENTER MARKS IN NEPALI”; N
INPUT “ENTER MARKS IN COMPUTER”; C
WRITE #1, N$, E, N, C
INPUT “DO YOU WANT TO CONTINUE”; CH$
LOOP WHILE UCASE$(CH$) = “Y”
CLOSE #1
END

6.    Write a program to create a data file ‘teldir.dat’ to store Name, Address and Telephone number of employees according to the need of the user.

OPEN “teldir.dat” FOR OUTPUT AS #1
DO      
CLS
INPUT “ENTER NAME”; N$
INPUT “ENTER ADDRESS”; A$
INPUT “ENTER TELEPHONE NUMBER”; T#
WRITE #1, N$, A$, T#
INPUT “DO YOU WANT TO CONTINUE(Y/N)”; CH$
LOOP WHILE UCASE$(CH$) = ”Y”
CLOSE #1
END

7.   Write a program to create a data file ‘teldir.dat’ to store Name, Address and Telephone number of employees according to the need of the user.

OPEN “teldir.dat” FOR OUTPUT AS #1
DO      
CLS
INPUT “ENTER NAME”; N$
INPUT “ENTER ADDRESS”; A$
INPUT “ENTER TELEPHONE NUMBER”; T#
WRITE #1, N$, A$, T#
INPUT “DO YOU WANT TO CONTINUE(Y/N)”; CH$
LOOP WHILE UCASE$(CH$) = ”Y”
CLOSE #1
END

8.   A sequential data file called “Marks.dat” contains Name, English, Nepali, Maths and Science Fields. Write a program to display all the contents of that data file.      

OPEN “Marks.dat” FOR INPUT AS #1
CLS
PRINT “NAME”, “ENGLISH”, “NEPALI”, “MATHS”, “SCIENCE”
WHILE NOT EOF(1)
INPUT #1, N$, E, N, M, S
PRINT N$, E, N, M, S
WEND
CLOSE #1
END

9.   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.                                                                             

OPEN "Nabil.txt" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, D$, A, T, R
S=(A*T*R)/100
PRINT D$, A, T, R, S
WEND
CLOSE #1
END

10.           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.

OPEN "Nabil.txt" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, D$, A, T, R
S=(A*T*R)/100
PRINT D$, A, T, R, S
WEND
CLOSE #1
END

11.           Write a program to create a sequential data file “RESULT.DAT” to store name, address and marks obtained in 3 different subjects of students.

OPEN “LIB.TXT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter name”; N$
INPUT “Enter address”; A$
INPUT “Enter marks in three subjects”; M1, M2, M3
WRITE #1, N$, A$, M1, M2, M3
INPUT “Do you want to continue?”; CH$
LOOP WHILE UCASE$(CH$) = “Y “
CLOSE #1
END

12.           Write a program to search and display only those records whose percentage is more than 60% from the data file “RESULT.DAT” which contains Student’s Symbol number, Date of Birth, Total Marks, Percentage and Division.                                               

 OPEN  “RESULT.DAT” FOR INPUT AS  #1
CLS
WHILE NOT EOF(1)
INPUT #1 , SN , D$ , M  , P , DV$
IF P> 60 THEN PRINT SN , D$ , M , P ,DV$
WEND
CLOSE #1
END

13.           A data file named “EMP.DAT” contains some records with fields Code, Name, Post and Salary. Write a program to print odd position records of the data file.                     

OPEN “EMP.DAT” FOR INPUT AS #1
CLS
Print “Name”, “Code”,”Post”,”Salary”
C=0
WHILE NOT EOF(1)
INPUT #1, CO, N$, P$, S
C=C+1
IF C MOD 2 = 1 THEN PRINT CO, N$, P$, S
End if
WEND
CLOSE #1
END

14.           A data file named “Staff.dat” contains staff name, Department, Post and Salary of some staffs. Write a program to count and display total number of records   in a file.   

OPEN “STAFF.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$,D$,P$,S
C=C+1
WEND
PRINT “Total Number of Records=”;C
CLOSE #1
END
15.           A sequential data file “Staff.dat” contains the name, address, post and salary of the employees. Write a program to read and display all the records stored in the above data file.

 OPEN “STAFF.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, A$, P$, S
PRINT N$, A$, P$, S
WEND
CLOSE #1
END

16.           Write a program to view those records from “Employee.dat” sequential data file having employee’s name, department, appointment data and salary whose salary is more than Rs.5000.

OPEN “EMPLOYEE.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, D$, AD$, S
IF S > 5000 THEN PRINT N$, D$, AD$, S
WEND
CLOSE #1
END

17.           A sequential data file called ‘MARKS.DAT’ contains ROLL NO, NAME, English, Nepali and Maths fields. Write a program to display all the contents of the data file.

OPEN “MARKS.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, RN, N$, E, N, M
PRINT RN, N$, E, N, M
WEND
CLOSE #1
END

18.           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, N$, A$, P
C=C+1
WEND
PRINT “The total number of records=”; C
CLOSE #1
END

19.           A sequential data file called “Marks.dat” contains roll number, name, English, Nepali, and Maths field. Write a program to display all the content of the data file.

OPEN “MARKS.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, RN, N$, E, N, M
PRINT RN, N$, E, N, M
WEND
CLOSE #1
END

20.             A sequential data file named”rec.dat”contains name,post and salary.  Write a program to display all the records for the employees whose Salary is more than 8000.

OPEN “REC.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, S
IF S>8000 THEN PRINT N$, P$, S
WEND
CLOSE #1
END
-----All the Best-----