Wednesday, October 24, 2018

PABSON KATHMANDU MID TERM EXAM 2075 COMPUTER SCIENCE SOLVED




PABSON, Kathmandu
MID TERMINAL EXAM-2075
Opt II. Computer


Group A
Computer Fundamental (22 marks)

1. Answer the following questions:                           (5×2=10)
a.   What is network operating system? Give examples.
      Ans: Network Operating System is a software program that controls other software and hardware that runs on a network. Examples of network operating systems include UNIX, Windows 2000 server, and Netware.
b.   What is internet? Why is it called network of networks?
      Ans: The Internet is a global system of interconnected computer networks that uses the standard Internet protocol suite (often called TCP/IP, although not all applications use TCP) to serve billions of users worldwide. It is called network of networks because it consists of millions of private, public, academic, business, and government networks, of local to global scope, that are linked by a broad array of electronic, wireless and optical networking technologies.
c.   State two advantages of multimedia technology.
      Ans: The two advantages of multimedia technology are listed below:
a. The use of multimedia can enhance every area in a presentation.
b. Multimedia enhances standard education techniques and makes learning process easier.
d.   What is cyber law? Why is it important?
      Ans: Cyber law refers to all the legal and regulatory aspects of Internet and the World Wide Web. Cyber law is important because it touches almost all aspects of transactions and activities on and concerning the Internet, the World Wide Web and Cyberspace.
e.   What is antivirus software? Name some popular antivirus software.
      Ans: Antivirus software is a program designed to detect and remove viruses from the computer system. Some popular antivirus software available are: Avast, AVG antivirus and Norton Antivirus.
2.   a. Convert as indicated.                                                  (2×1=2)
      i. (105)8 into binary
      Soln:
      Converting Octal into Binary
      1 = 001
      0 = 000
      5 = 101
      (105)8 = (1000101)2

      ii. (357)16 into octal
      Soln:
      Converting hexadecimal into Binary,
      3 = 0011
      5 = 0101
      7 = 0111
      =(1 101 010 111)2
      Now,
      Converting Binary into Octal,
            001 = 1
      101 = 5
      010 = 2
      111 = 7
      (357)16 = (1527)8
b. Perform the binary operation.                                                  (2×1=2)
i. (111 ´ 11) – 111
            Soln:
1 1 1
´ 1 1
1 1 1
         1 1 1´    
       1 0  1  0 1
Now, Subtracting
            1 0 1 0 1
              -   1 1 1
              1  1  1 0
            (111 ´ 11) – 111 = 1110
ii. 1101 + 101 ¸ 110
            Soln:
            1 1 0 1
            + 1 0 1
             10010
            Now, Dividing
            110) 10010 ( 11
                     -110
                       110
                      -110
                        000
            Quotient = 11
            Remainder = 0
3. Match the following.                                                                      (4 x 0.5 = 2)
Group A                           Group B
a.     Microwave                 i. Multimedia
b.     Web browser              ii. Protocol
c.      Sound Card                 iii. Unguided Media
d.     TCP/IP                        iv. Microsoft Edge
v. Guided Media
Ans:
Group A                           Group B
a. Microwave                    i. Unguided media
b. Web browser                ii. Microsoft Edge 
c. Sound card                    iii. Multimedia
d. TCP/IP                          iv. Protocol
4. Choose correct answer.                                        (4 x 0.5 = 2 )
      a. In which topology are network devices connected through hub?
      i. Ring topology                ii. Bus topology         
      iii. Star topology              iv. None of the above
      b. Which is not related to internet?
      i. ISP         ii. TCP/IP        iii. WWW       iv. UPS
      c. ______ is a device that protects your PC from computer virus.
      i. UPS        ii. Voltage regulator   iii. NAV                      iv. None of them
      d. The route of virus transmission is ___________.
      i. Pen drive                       ii. Microphone            iii. Printer       iv. Mouse

5. Give the appropriate technical terms of the following:   2                                  (4×0.5=2)
a. A virus that damages documents created in Ms-Word and Ms-Excel.
Ans: Macro Virus
b. A technology that will enhance multimedia by supporting real time, interactive, three-dimensional graphics.
Ans: Virtual Reality
c. Protocol used by e-mail client to download e-mails from e-mail server.
Ans: POP
d.     Requires less media than others topology.
Ans: Bus Topology

6. Write the full forms of the followings.                             (4X 0. 5 = 2)
SPX  : Sequenced Packet Exchange
CDMA: Code Division Multiple Access
SIM     : Subscriber Identification Module
MUK : Multimedia  Upgraded Kits
Group ‘B’
[Database Management System - 10 Marks]
7. Answer the following questions:                                       (3×2=6)
a.   What is primary key? What is the purpose of primary key?
      Ans: A primary key is a field that uniquely identifies each record. A primary key prevents duplicate records from being entered in the table and is used to control the order in which records display in the table. This makes it faster for databases to locate records in the table and to process other operations. The primary key is also used to create a link between tables in a database.
b.   What is a data type? What are the different data types that can be stores on Access data field?
Ans: A data type is an attribute for a field that determines what type of data it can contain.
The different data types that can be stored on Access data field are: numeric, text, currency, date/time, AutoNumber, Yes/No, OLE object, Hyperlink and Lookup Wizard.
c.   What is a query? What is the purpose of the query in MS-Access?
Ans: A query is a database object that creates a datasheet of selected fields and records from one or more tables. You use queries to view data in different ways, analyze data, and even to change existing data.
8. Choose the correct answer:                                                        (4×0.5=2)
a. A database is the collection of __________.
i. Hardware                       ii. Software     iii. Record      iv. None of these
b. Which of the following is not a Microsoft Access database object?
i. Tables    ii. Queries       iii. Forms        iv. Sorting
c. The storage size of date and time is ___________.
i. 4 Bytes   ii. 6 Bytes       iii. 8 Bytes      iv. 10 Bytes
d. A collection of record for a single subject, such as all of the customer records.
i. Field      ii. Record        iii. Table         iv. Data

9. Match the following.                                                                  (4 x 0.5 = 2)
      Group A                           Group B
      Data type                          Field property
      Format                              Relationship
      Form                                 Referential Integrity
      One-to-one                                    Database object
                                                Memo
     
      Group A                           Group B
      Data type                          Memo
      Format                              Field property
      Form                                 Database object
      One-to-one                                    Relationship

Group C
[Programming-18 marks]
10. Answer the following questions.
a.   What is procedure? What are the two types of procedure used in QBASIC?

      Ans: Procedure is a small, logical and manageable functional part of the program. There are two types of procedure: SUB procedure and FUNCTION procedure.
b.   What is a modular programming?
Ans: A modular programming is the process of breaking down a problem into smaller tasks. These tasks can then be broken down into sub modules.
c.   Write the function of the following statements.
      i. CALL:  Used to transfer control to another procedure, a BASIC SUB program.
      ii. PRINT: Display result on the screen, 
11.  Find the output of the given program.                           2
     
      DECLARE SUB SER (P)
      P = 15
      CALL SER (P)
      END

      SUB SER (P)
      M = 3
      WHILE M < 10
      PR = M * P
      PRINT PR,
      M = M + 2
      WEND
      END SUB

      Ans: Output is:     45        75                    105                  135

12. Rewrite the given program after correcting the bugs.                         2

DECLARE FUNCTION REV$ (ST$)
CLS
INPUT “Enter string”, S$
LET R$= REV$(st$)
PRINT "The reverse string is :"; R$
END
===========================
FUNCTION REV$(ST$)
FOR I = LEN(ST$) TO 1
RV$= RV$+ MID$(ST$, 1, I)
NEXT I
RV$=REV$
END FUNCTION


Debugged program:
DECLARE FUNCTION REV$ (ST$)
CLS
INPUT “Enter string”, S$
LET R$= REV$(S$)
PRINT "The reverse string is :"; R$
END
===========================
FUNCTION REV$(ST$)
FOR I = LEN(ST$) TO 1 STEP - 1
RV$= RV$+ MID$(ST$, I, 1)
NEXT I
REV$=RV$
END FUNCTION
13.       Study the following program and answer the following questions that follow:                                                                                   2
DECLARE SUB OT (N$)
N$ = "Computer Science"
CALL OT(N$)
END
=========
SUB OT (N$)
B = LEN(N$)
c = 1
WHILE c <= B
m$ = MID$(N$, c, 1)
PRINT m$;
c = c + 2
WEND
END SUB
a. What is the value of B in the above program?
Ans: The value of B is 16 in the above program.
b. How many parameters are used in the above sub proevdure?
Ans: Only one parameter is used in the above program.
14.
a.   Write a program to create a procedure using SUB...END SUB to input the value of length, breadth and height of a box. The program should calculate the area and volume of the box.                                                           3
Solution:
DECLARE SUB area (l!, b!)
DECLARE SUB vol (l!, b!, h!)
INPUT “Enter a length of a box”; l
INPUT “Enter a breadth of a box”; b
INPUT “Enter a height of a box”; h
CALL area(l, b)
CALL vol(l, b, h)
END
SUB area (l, b)
a = l * b
PRINT “Area of a box:::”; a
END SUB
SUB vol (l, b, h)
v = l * b * h
PRINT “Volume of a box:::”; v
END SUB
b. Write a function procedure to count the number of words in an input string.                                                                                                   3
Solution:
DECLARE FUNCTION count! (s$)
INPUT “Enter a string:::”; s$
PRINT “No. of words in a sentence:::”; count(s$)
END
FUNCTION count (s$)
c = 1
FOR i = 1 TO LEN(s$)
a$ = MID$(s$, i, 1)
IF a$ = “ “ THEN c = c + 1
NEXT i
count = c
END FUNCTION
c. Write a program by SUB procedure to display following series.            3
                  1, 2, 3, 5, 8, 13, 21…… up to 10th terms.
     
DECLARE SUB PAT( )
CLS
CALL PAT
END
      SUB PAT
      A= 1
      B= 2
FOR I = 1 TO 10
PRINT A
C= A+B
A=B
B=C
NEXT I
END SUB
óóó
Source: Answer Key Pabson

Saturday, October 6, 2018

QBASIC PROGRAM - Debugging Programs - Computer Science [SLC / SEE] with answers



QBASIC PROGRAM - Debugging Programs - Computer Science [SLC / SEE] with answers


1.      DECLARE SUB correct( )
CLS
REM to calculate the area of rectangle
CALL SUB correct
END

SUB Correct
INPUT “enter length”;L
INPUT “enter breadth”;B
A= LENGTH* BREADTH
PRINT “area of rectangle=”;Area
SUB END

DECLARE SUB correct( )
CLS
REM to calculate the area of rectangle
CALL correct
END

SUB Correct
INPUT “enter length”;L
INPUT “enter breadth”;B
A= L*B
PRINT “area of rectangle=”; A
END SUB

2.      Rem program to find the cube of the cube of a given number
DECLARE FUNCTION CUBE(R)
ENTER R
DISPLAY CUBE(R)
END

FUNCTION CUBE(R)
S=R^3
PRINT S
COMPLETE

Rem program to find the cube of the cube of a given number
DECLARE FUNCTION CUBE(R)
INPUT R
PRINT CUBE(R)
END

FUNCTION CUBE(R)
S=R^3
CUBE = S
END FUNCTION
3.      [SLC 2065]
DECLARE FUNCTION SUM(a,b)
REM Program to sum given two numbers
Input ”Enter first number”; x
Input “Enter second number; y
PRINT SUM(a,b)
END

FUNCTION SUM(x,y)
SUM=a+b
END

[SLC 2065]
DECLARE FUNCTION SUM(a,b)
REM Program to sum given two numbers
Input ”Enter first number”; x
Input “Enter second number”; y
PRINT SUM(x, y)
END

FUNCTION SUM(a, b)
SUM=a+b
END FUNCTION

4.      [SLC 2072]
FUNCTION SUM (m,n)
Rem to print sum of two numbers
a= 6
b= 7
DISPLAY SUM (a, b)
END

FUNCTION SUM (m,n)
S = m +n
S = SUM
END SUM

[SLC 2072]
DECLARE FUNCTION SUM (m,n)
Rem to print sum of two numbers
a= 6
b= 7
PRINT SUM (a, b)
END

FUNCTION SUM (m,n)
S = m +n
SUM = S
END FUNCTION



5.      [SLC 2068]
CREATE FUNCTION Square(A)
Rem to print square of a number
CLS
Get “a number”; A
CALL square(A)
END

FUNCTION square(A)
Ans=A^2
Square=Ans
END Square(A)

[SLC 2068]
DECLARE FUNCTION Square(A)
Rem to print square of a number
CLS
INPUT “a number”; A
PRINT square(A)
END

FUNCTION square(A)
Ans=A^2
Square=Ans
END FUNCTION

6.      DECLARE FUNCTION AREA (X)
CLS
REM TO FIND THE AREA OF CIRCLE
INPUT “ENTER THE VALUE OF RADIUS”;R
CALL  AREA (R)
END

FUNCTION AREA (X)
 AR=    (22/7)* R^2
AR=AREA
FUNCTION END

DECLARE FUNCTION AREA (X)
CLS
REM TO FIND THE AREA OF CIRCLE
INPUT “ENTER THE VALUE OF RADIUS”;R
PRINT  AREA (R)
END

FUNCTION AREA (X)
 AR=    (22/7)* X^2
AREA=AR
END FUNCTION





7.      [SLC 2064] [SLC 2067 S]
DECLARE SUB Series()
CLS
EXECUTE Series
END
SUB Series()
REM program to generate  3 3 4 9 15 upto 20th terms.
A=3
B=3
FOR ctr= 10 to 1
DISPLAY A;B;
A=A+B
B=A+B
NEXT ctr
END Series()

DECLARE SUB Series()
CLS
CALL Series
END
SUB Series()
REM program to generate  3 3 4 9 15 upto 20th terms.
A=3
B=3
FOR ctr= 10 to 1 STEP-1
PRINT A;B;
A=A+B
B=A+B
NEXT ctr
END SUB

8.      [SLC 2066]
DECLARE SUB Fibonic ()
REM *Fibonic series*
CALL SUB Fibonic
END
SUB Fibonic
A=1
B=1
FOR x=1 to 10
DISPLAY a;
a=a+b
b=a+b
END Fibonic

  [SLC 2066]
DECLARE SUB Fibonic ()
REM *Fibonic series*
CALL Fibonic
END
SUB Fibonic
A=1
B=1
FOR x=1 to 10
PRINT a; b;
a=a+b
b=a+b
NEXT x
END SUB
9.      [SLC 2070]
DECLARE SUB Series(.)
CLS
EXECUTE Series
END
SUB Series
REM  to generate 2 2 4 6 10….. upto 10th term
P=2
Q=2
FOR           Ctr=1 TO 5
DISPLAY P,Q,
P=P+Q
Q=P+Q
WEND
END Series()

[SLC 2070]
DECLARE SUB Series(.)
CLS
CALL Series
END
SUB Series
REM  to generate 2 2 4 6 10….. upto 10th term
P=2
Q=2
FOR ctr=1 TO 5
PRINT P,Q,
P=P+Q
Q=P+Q
NEXT ctr
END SUB


10.   [SEE 2073]
DECLARE SUB SUM (N)
INPUT "Any Number"; N
PRINT SUM (N)
END

SUB SUM (N)
S = 0
WHILE N = 0
R = R MOD 10
S = S+R
N = N/10
WEND
PRINT "Sum of digits"; s
END





[SEE 2073]
DECLARE SUB SUM (N)
INPUT "Any Number"; N
CALL SUM (N)
END

SUB SUM (N)
S = 0
WHILE N < > 0
R = N MOD 10
S = S+R
N = N\10
WEND
PRINT "Sum of digits"; s
END SUB


11.   REM To find the sum of even digits of multi digits number
DECLARE FUNCTION SUM (N)
CLS
INPUT “ENTER MULTI-DIGITS NUMBER  ; N
PRINT “SUM  = ” ; SUM(N)
END

FUNCTION SUM(N)
WHILE N=0
R= N MOD 10
IF R MOD 2 = 1 THEN S=S+R
N = N / 10
WEND
SUM (N) =S
END FUNCTION

REM To find the sum of even digits of multi digits number
DECLARE FUNCTION SUM (N)
CLS
INPUT “ENTER MULTI-DIGITS NUMBER  ; N
PRINT “SUM  = ” ; SUM(N)
END

FUNCTION SUM(N)
WHILE N < > 0
R= N MOD 10
IF R MOD 2 = 0 THEN S=S+R
N = N \ 10
WEND
SUM  =S
END FUNCTION




12.   DECLARE FUNCTION arm (n)
INPUT” enter number”; n
FOR I = 1 TO n
a = I
b = arm (a)
IF b = I THEN
PRINT b
NEXT J
END

FUNCTION arm (n)
S = 0
WHILE a <> 0
r = n MOD 10
s = s + r ^ 3
n = n \ 10
up
arm = a
END FUNCTION

DECLARE FUNCTION arm (n)
INPUT” enter number”; n
FOR I = 1 TO n
a = I
b = arm (a)
IF b = I THEN
PRINT b
NEXT I
END

FUNCTION arm (n)
S = 0
WHILE n < > 0
r = n MOD 10
s = s + r ^ 3
n = n \ 10
WEND
arm = s
END FUNCTION

13.   DECLARE SUB ARM(NN)
CLS
INPUT “ENTER A NUMBER”; N
CALL ARM(N)
END

SUB ARM(A)
A = NN
WHILE A < > 0
R = A MOD 10
ACC = ACC + R ^ 10
A = A \ 3
WEND
IF ACC = A THEN PRINT “ARMSTRONG” ELSE PRINT “NOT ARMSTRONG”
END SUB

DECLARE SUB ARM(A)
CLS
INPUT “ENTER A NUMBER”; N
CALL ARM(N)
END

SUB ARM(A)
NN = A
WHILE A < > 0
R = A MOD 10
ACC = ACC + R ^ 3
A = A \ 10
WEND
IF ACC = NN THEN PRINT “ARMSTRONG” ELSE PRINT “NOT ARMSTRONG”
END SUB

14.   DECLARE GREAT SUB(a,b,c)
CLS
INPUT "ENTER 3 NUMBER";X,Y,Z
PASS GREAT (a,b,c)
END

SUB GREAT (a,b,c)
IF a>b and a>c THEN
g=a
ELSEIF b>a and b>c THEN
b=g
ELSE
g=c
END IF
PRINT g
SUB END

15.   DECLARE GREAT SUB(a,b,c)
CLS
INPUT "ENTER 3 NUMBER"; X,Y,Z
CALL GREAT (a,b,c)
END
SUB GREAT (a,b,c)
IF a>b and a>c THEN
g=a
ELSEIF b>a and b>c THEN
g=b
ELSE
g=c
END IF
PRINT g
END SUB
16.   [SLC 2074]
REM TO find the factorial of a given number.
DECLARE FUNCTION FACTO (N$)
CLS
INPUT "Enter a number", X
PRINT "The Factorial is: ", FACTO (N)
END
FUNCTION FACTO (N)
F = 1
WHILE N = 0
F = F*N
N = N - 1
WEND
F = FACTO
END FUNCTION

REM TO find the factorial of a given number.
DECLARE FUNCTION FACTO (N)
CLS
INPUT "Enter a number", X
PRINT "The Factorial is: ", FACTO (X)
END
FUNCTION FACTO (N)
F = 1
WHILE N < > 0
F = F*N
N = N - 1
WEND
FACTO = F
END FUNCTION

17.   DECLARE SUB FACT (N)
CLS
REM PRINT FACTORS OF INPUT NUMBER WITH SUB PROCEDURE
INPUT “ENTER NUMBER:”, A
CALL FACT(N)
END

SUB FACT (N)
FOR K=1 TO N
IF N MOD K =1 THEN
PRINT K
IF END
END FUNCTION

DECLARE SUB FACT (N)
CLS
REM PRINT FACTORS OF INPUT NUMBER WITH SUB PROCEDURE
INPUT “ENTER NUMBER:”, A
CALL FACT(A)
END
SUB FACT (N)
FOR K=1 TO N
IF N MOD K =0 THEN
PRINT K
END IF
END SUB
18.   DECLARE FUNCTION factor(N)
CLS
GET “Enter a number”; X
LET S = factor(X)
PRINT “Frequency of factor is” ; S
END Function

FUNCTION factor(N)
FOR I = 1 to N
G = N MOD I
IF G = 0 THEN
F=F+1
NEXT I
F = Factor
END FUNCTION

DECLARE FUNCTION factor(N)
CLS
GET “Enter a number”; X
LET S = factor(X)
PRINT “Frequency of factor is” ; S
END

FUNCTION factor(N)
FOR I = 1 to N
G = N MOD I
IF G = 0 THEN
F=F+1
END IF
NEXT I
Factor = F
END FUNCTION

19.   REM to check whether the supplied no is odd or even
DECLARE SUB TEST(N)
CLS
INPUT”ENTER THE NUMBER;”;N$
CALL TEST(N)
END

SUB TEST(N)
Y=2
R=Y MOD N
IF R=1 THEN
PRINT”EVEN”
OR
PRINT”ODD”
END
END SUB



REM to check whether the supplied no is odd or even
DECLARE SUB TEST(N)
CLS
INPUT”ENTER THE NUMBER;”;N
CALL TEST(N)
END

SUB TEST(N)
Y=2
R=N MOD Y
IF R=0 THEN
PRINT”EVEN”
ELSE
PRINT”ODD”
END IF
END SUB


20.   REM TO FIND LONGEST NAME
DECLARE FUNCTION LONGETS$(A$, B$, C$)
INPUT A$, B$, C$
PRINT LONGEST(A$, B$, C$)
END

FUNCTION LONGEST$(A$, B$, C$)
A = LEN$(A$)
B = LEN(B$)
C = LEN(C$)
IF A > B OR A > C THEN
A$ = L$
ELSEIF B > A OR B > C THEN
L$ = B$
ELSE
L$ = C$
END IF
LONGEST$(A$, B$, C$) = L$
FUNCTION END

REM TO FIND LONGEST NAME
DECLARE FUNCTION LONGETS$(A$, B$, C$)
INPUT A$, B$, C$
PRINT LONGEST$(A$, B$, C$)
END

FUNCTION LONGEST$(A$, B$, C$)
A = LEN(A$)
B = LEN(B$)
C = LEN(C$)
IF A > B AND A > C THEN
L$ =A$
ELSEIF B > A AND B > C THEN
L$ = B$
ELSE
L$ = C$
END IF
LONGEST$ = L$
END FUNCTION

21.   DECLARE SUB CHECK(N$,W$)
INPUT”ENTER A STRING:::”;N$
CHECK CALL (N$,W$)
END

SUB CHECK(N$,W$)
FOR K=1 TO LEN(W$)
A$=MID$(N$,1,K)
W$=W$+A$
NEXT K
IF W$=N$ THEN
PRINT “NOT PALINDROME”
ELSE
PRINT”PALINDROME”
END IF
END SUB

DECLARE SUB CHECK(N$,W$)
INPUT”ENTER A STRING:::”;N$
CALL CHECK (N$,W$)
END

SUB CHECK(N$,W$)
FOR K= LEN(W$) TO 1 STEP-1
A$=MID$(N$,K, 1)
W$=W$+A$
NEXT K
IF W$=N$ THEN
PRINT “PALINDROME
ELSE
PRINT” NOT PALINDROME
END IF
END SUB
22.   [SLC 2069]
Rem program to reverse the string or word
DECLARE SUB REV(W$)
CLS
INPUT “Enter a word”;W$
CALL REV(W$)
END

SUB REV(W$)
FOR I=LEN(W$) to 1 step -1
C$=LEFT$(W$,I,1)
S$=D$+1
LOOP
PRINT “Reverse string is:”; D$
CLOSE SUB

[SLC 2069]
Rem program to reverse the string or word
DECLARE SUB REV(W$)
CLS
INPUT “Enter a word”;W$
CALL REV(W$)
END

SUB REV(W$)
FOR I=LEN(W$) to 1 step -1
C$=MID$(W$,I,1)
S$=S$+C$
NEXT I
PRINT “Reverse string is:”; S$
END SUB

23.   DECLARE FUNCTION REV$(ST$)
CLS
INPUT “Enter a string”; S$
LET R$=REV$(S$)
PRINT “The string in reverse is”; R$
END

FUNCTION REV$(ST$)
FOR I = LEN(ST$) TO 1 STEP-1
RV$=RV$+MID$(ST$,I,1)
NEXT I
REV$= RV$
END FUNCTION

24.   REM test if user input character is alphabet or digit using sub procedure
DECLARE SUB TEST(C$)
ENTER “Supply a character”; T$
CALL TEST(C$)
END
SUB TEST(C$)
SELECT CASE T$
CASE “A” TO “Z” OR “a” TO “z”
PRINT “Alphabet”
CASE “0” TO “9”
PRINT “Digit”
SELECT END
END SUB

REM test if user input character is alphabet or digit using sub procedure
DECLARE SUB TEST(C$)
INPUT “Supply a character”; T$
CALL TEST(T$)
END
SUB TEST(C$)
SELECT CASE T$
CASE “A” TO “Z” , “a” TO “z”
PRINT “Alphabet”
CASE “0” TO “9”
PRINT “Digit”
END SELECT
END SUB


25.   DECLARE FUNCTION dec(N)
INPUT”ENTER ANY BINARY NUMBER:’;n
PRINT”DECIMAL EQUIVALENT”;dec(n)
END

FUNCTION dec(N)
P=1
WHILE N<>0
R= N MOD 10
S=S+R*10^P
P=P+1
N=N/10
WEND
S=DEC
END FUNCTION

DECLARE FUNCTION dec(N)
INPUT”ENTER ANY BINARY NUMBER:’;n
PRINT”DECIMAL EQUIVALENT”;dec(n)
END

FUNCTION dec(N)
P=0
WHILE N<>0
R= N MOD 10
S=S+R*2^P
P=P+1
N=N\10
WEND
DEC=S
END FUNCTION


26.   REM do display the reverse of the supplied number
DECLARE FUNCTION rev(n)
CLS
INPUT n
PRINT rev(n)
END

FUNCTION rev(n)
WHILE n = 0
R = n MOD 10
D$ = STR$(R) + D$
n = n / 10
WEND
Rev = ASC(D$)
END FUNCTION



REM do display the reverse of the supplied number
DECLARE FUNCTION rev(n)
CLS
INPUT n
PRINT rev(n)
END

FUNCTION rev(n)
WHILE n < > 0
R = n MOD 10
D$ = D$ + STR$(R)
n = n \ 10
WEND
Rev = VAL(D$)
END FUNCTION

27.   DECLARE FUNCTION userlen (a$)
REM length of sting without LEN function
CLS
INPUT “Type any string value: ”; b$
PRINT “Length of the string: “; userlen(a$)
END

FUNCTION userlen (a$)
c=1
aa:
b$ = MID$(a$, p, 1)
IF b$ = “THEN”
p=p+1
c=c+1
GOTO aa
END IF
userlen = c
END FUNCTION

DECLARE FUNCTION userlen (a$)
REM length of sting without LEN function
CLS
INPUT “Type any string value: ”; b$
PRINT “Length of the string: “; userlen(b$)
END

FUNCTION userlen (a$)
c=1
aa:
b$ = MID$(a$, c, 1)
IF b$ < > “”
p=p+1
c=c+1
GOTO aa
END IF
userlen = p
END FUNCTION

28.   REM to print odd numbers from 32 to 12
DECLARE SUB SHOW ( )
CLS
CALL SHOW ( )
END

SUB SHOW ( )
N = 12
WHILE N <= 32
IF N MOD 2 = 0 THEN PRINT N;
N = N-1
NEXT N
END SUB

REM to print odd numbers from 32 to 12
DECLARE SUB SHOW ( )
CLS
CALL SHOW
END

SUB SHOW ( )
N = 32
WHILE N >= 12
IF N MOD 2 = 0 THEN PRINT N;
N = N-1
WEND
END SUB

29.   REM to remove odd digits from a supplied numbers
DECLARE FUNCTION remodd(n)
CLS
INPUT “any number”; a
PRINT “Even digits only”; remodd(n)
END
FUNCTION remodd(n)
p = 0
WHILE n < > 0
R = n MOD 10
IF r MOD 2 = 1 THEN
s = s + r ^ p
p = p * 10
END IF
N = n \ 10
WEND
S = remodd
END FUNCTION





REM to remove odd digits from a supplied numbers
DECLARE FUNCTION remodd(n)
CLS
INPUT “any number”; a
PRINT “Even digits only”; remodd(a)
END
FUNCTION remodd(n)
p = 1
WHILE n < > 0
R = n MOD 10
IF r MOD 2 = 0 THEN
s = s + r * p
p = p * 10
END IF
N = n \ 10
WEND
 remodd = s
END FUNCTION

30.   DECLARE SUB CHECK(N)
CLS
INPUT”ENTER A NUMBER”;NUM
C=CHECK(N)
END
SUB CHECK(A)
FOR I=2 TO N/2
IF N MOD 1=0 THEN
C=C+2
END IF
WEND
IF C>0 THEN
PRINT”IT IS COMPOSITE”
ELSE
PRINT”IT IS PRIME”
END IF
END SUB
DECLARE SUB CHECK(N)
CLS
INPUT”ENTER A NUMBER”;NUM
CALL CHECK(NUM)
END
SUB CHECK(N)
FOR I=2 TO N/2
IF N MOD I=0 THEN
C=C+1
END IF
NEXT I
IF C>0 THEN
PRINT”IT IS COMPOSITE”
ELSE
PRINT”IT IS PRIME”
END IF
END SUB
31.   REM to check the number is prime or not
DECLARE SUB CHECK(N)
CLS
INPUT N
CALL CHECK(N)
END

SUB CHECK(N)
I=3
DO
IF N MOD I = 0 THEN
PRINT “ NOT PRIME
END
END IF
I = I + 1
LOOP UNTIL I >N – 1
PRINT “PRIME”
END SUB

32.   REM to display those records whose name starts from “A”.
OPEN “Employee.dat” FOR OUTPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #, N$, P$, S#
C$=MID$(N$, 1, 1)
IF C$=”A” THEN
PRINT #1, N$, P$, S#
END IF
LOOP       
CLOSE #1
END

REM to display those records whose name starts from “A”.
OPEN “Employee.dat” FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, N$, P$, S#
C$=MID$(N$, 1, 1)
IF C$=”A” THEN
PRINT N$, P$, S#
END IF
WEND      
CLOSE #1
END
33.   REM to display records from 2nd position to 6th position.
OPEN record.txt FOR INPUT AS #2
DO WHILE EOF(2)
INPUT #1, N$, Add$, DOB$
C=C+1
IF C<=2 AND C>=6 THEN
PRINT N$, Add$, DOB$
END IF
LOOP
CLOSE #2
END

REM to display records from 2nd position to 6th position.
OPEN “record.txt” FOR INPUT AS #2
DO WHILE NOT EOF(2)
INPUT #2, N$, Add$, DOB$
C=C+1
IF C>=2 AND C<=6 THEN
PRINT N$, Add$, DOB$
END IF
LOOP
CLOSE #2
END

34.   REM display all data if post is manager or officer
OPEN “info.dat” FOR INPUT AS #1
CLS
PRINT “Name”, “Post”, “Dept”, “Salary”
DO WHILE NOT EOF(10)
INPUT N$, P$, D$, S
IF P$ = “MANAGER” AND P$ = “OFFICER” THEN
PRINT N$, P$, D$, S
END IF
WEND
CLOSE
END


35.   REM display all data if post is manager or officer
OPEN “info.dat” FOR INPUT AS #1
CLS
PRINT “Name”, “Post”, “Dept”, “Salary”
DO WHILE NOT EOF(1)
INPUT #1, N$, P$, D$, S
IF P$ = “MANAGER” OR P$ = “OFFICER” THEN
PRINT N$, P$, D$, S
END IF
LOOP
CLOSE
END

36.    [SLC 2067]
REM to display all the records from sequential data file ABC.DAT
OPEN “ABC.DAT” FOR OUTPUT AS # 1
DO WHILE NOT EOF(“ABC.DAT”)
INPUT # 1,N$,A
PRINT N$,A
CLOSE 1
END

[SLC 2067]
REM to display all the records from sequential data file ABC.DAT
OPEN “ABC.DAT” FOR INPUT AS # 1
DO WHILE NOT EOF(1)
INPUT # 1,N$,A
PRINT N$, A
LOOP
CLOSE # 1
END

37.   [SLC 2068 S]
Rem to display the contents of a data file.
OPEN “Marks.dat” FOR OUTPUT AS #1
CLS
WHILE EOF(1)
            INPUT #1, Name$, Age, Add$
            DISPLAY Name$, Age, Add$
WEND
CLOSE 1
END

[SLC 2068 S]
Rem to display the contents of a data file.
OPEN “Marks.dat” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
            INPUT #1, Name$, Age, Add$
            PRINT Name$, Age, Add$
WEND
CLOSE #1
END

38.   [SLC 2069]
REM display Records of students From Data File
OPEN “STDREC.DAT” FOR INP AS #1
PRINT “ROLL”,”NAME”,”ADDRESS”,”CLASS”,”SECTION”
DO WHILE NOT EOF
               INPUT #1,RN,N$,AD$,CL,S$
               PRINT RN,N$,AD$,CL,S$
NEXT
CLOSE #1
               END

[SLC 2069]
REM display Records of students From Data File
OPEN “STDREC.DAT” FOR INPUT AS #1
PRINT “ROLL”, “NAME”, “ADDRESS”, “CLASS”, “SECTION”  
DO WHILE NOT EOF(1)
               INPUT #1, RN, N$, AD$, CL, S$
               PRINT RN, N$, AD$, CL, S$
LOOP
CLOSE #1
               END
39.   REM Program to store data in a sequential data file.
DO
CLS
OPEN “Address.txt” FOR INPUT AS #1
INPUT “Name”; N$
INPUT “Address”; A$
INPUT “Age”; A
INPUT “Phone”; P$
WRITE N$,A$,A,P$
INPUT “Do you want some more….”; ans$
LOOP WHILE UCASE(ans$)=”Y”
CLOSE #1
END

REM Program to store data in a sequential data file.
OPEN “Address.txt” FOR OUTPUT AS #1
DO
CLS
INPUT “Name”; N$
INPUT “Address”; A$
INPUT “Age”; A
INPUT “Phone”; P$
WRITE #1, N$, A$, A, P$
INPUT “Do you want some more….”; ans$
LOOP WHILE UCASE$(ans$)=”Y”
CLOSE #1
END
40.   [SLC 2066 S]
REM To store Name, post and salary
OPEN “EMP.DOC” FOR OUT AS #1
INPUT” Enter name”;N
INPUT” Enter post”;P$
INPUT “Enter salary”;S
WRITE #2, N$,P$, S
CLOSE #1
END
[SLC 2066 S]
REM To store Name, post and salary
OPEN “EMP.DOC” FOR OUTPUT AS #1
INPUT” Enter name”;N$
INPUT” Enter post”;P$
INPUT “Enter salary”;S
WRITE #1, N$, P$, S
CLOSE #1
END

41.   REM To add records in existing data file which contains some records
OPEN “Directory.txt” FOR INPUT AS #2
DO
INPUT “ENTER Name “; N$
INPUT “ENTER Address “; A$                                              
INPUT “ENTER Telephone”; T
ADD #2, N$, A$, T
INPUT “Do you want to add more records (Y/N)” ; ANS
LOOP WHILE UCASE(ANS$) = Y
CLOSE
END

REM To add records in existing data file which contains some records
OPEN “Directory.txt” FOR APPEND AS #2
DO
INPUT “ENTER Name “; N$
INPUT “ENTER Address “; A$                                              
INPUT “ENTER Telephone”; T
WRITE #2, N$, A$, T
INPUT “Do you want to add more records (Y/N)” ; ANS$
LOOP WHILE UCASE$(ANS$) = “Y”
CLOSE
END


42.   REM to add records in “marks.dat” sequential data file
OPEN “A”, 2, “mark.dat”
DO
INPUT “Roll Number, Name, Class”; R, N$, C
WRITE#1, R, N$, C
INPUT “Want to continue(Y?N)”; H$
LOOP UNTIL UCASE$(H$) < > “Y”
TERMINATE
END

REM to add records in “marks.dat” sequential data file
OPEN “A”, #2, “mark.dat”
DO
INPUT “Roll Number, Name, Class”; R, N$, C
WRITE #2, R, N$, C
INPUT “Want to continue(Y?N)”; H$
LOOP UNTIL UCASE$(H$) < > “Y”
CLOSE #2
END
43.   REM to update the salary by 10%
CLS
OPEN "EMP.DAT" FOR INPUT AS #1
OPEN "TEMP.DAT" FOR OUTPUT AS#1
WHILE NOT EOF(1)
INPUT NM$, POST$, S
LET  NS = S + S*10/100
WRITE NM$, POST$, S
WEND
KILL "EMP.DAT"
CLOSE #1,#2
NAME "TEMP.DAT" AS "EMP.DAT"
END

REM to update the salary by 10%
CLS
OPEN "EMP.DAT" FOR INPUT AS #1
OPEN "TEMP.DAT" FOR OUTPUT AS#2
WHILE NOT EOF(1)
INPUT #1, NM$, POST$, S
LET  NS = S + 10/100*S
WRITE #2, NM$, POST$, S
WEND
KILL "EMP.DAT"
CLOSE #1,#2
NAME "TEMP.DAT" AS "EMP.DAT"
END
44.   CLS
REM copy the data of ‘mark.dat’ file to ‘update.dat’ file.
OPEN "MARK.DAT" FOR OUTPUT AS #1
OPEN “UPDATE.DAT” FOR OUTPUT AS #2
DO UNTIL EOF (1)
INPUT #2, RollNumber, N$, Age
WRITE #2, RN, N$, Age
CLOSE #1, 2
LOOP
END

CLS
REM copy the data of ‘mark.dat’ file to ‘update.dat’ file.
OPEN "MARK.DAT" FOR OUTPUT AS #1
OPEN “UPDATE.DAT” FOR OUTPUT AS #2
DO UNTIL EOF (1)
INPUT #1, RN, N$, Age
WRITE #2, RN, N$, Age
LOOP
CLOSE #1, #2
END

45.   REM COPY THE DATA OF “SRC.INF” TO “DEST.INF”
OPEN “SRC.INF” FOR INPUT AS #1
OPEN “DEST.INF” FOR OUTPUT AS #2
CLS
WHILE NOT EOF( )
INPUT #2, NM$, RN, AGE
WRITE #1, NM$, RN, AGE
CLOSE #1, #2
END

REM COPY THE DATA OF “SRC.INF” TO “DEST.INF”
OPEN “SRC.INF” FOR INPUT AS #1
OPEN “DEST.INF” FOR OUTPUT AS #2
CLS
WHILE NOT EOF( 1)
INPUT #1, NM$, RN, AGE
WRITE #2, NM$, RN, AGE
WEND
CLOSE #1, #2
END

***