Posts

Showing posts from January, 2014

Write output

1.       Write the output of the following program CLS N=115 P=0 WHILE N<>0 R=N MOD 2 S=S+R*10^P P=P+1 N=N\2 WEND PRINT S END a.         CLS N=123 P=0 WHILE N<>0 R=N MOD 8 S=S+R*10^P P=P+1 N=N\8 WEND PRINT S END b.         CLS X=7 FOR  C=1 TO 10 PRINT X; IF X MOD 2=0 THEN X=X/2 ELSE X=3*X+1 END IF NEXT C END c.          d.         CLS N=115 P=0 DO WHILE N<>0 R=N MOD 2 S=S+R*10^P P=P+1 N=N\2 LOOP PRINT S END e.         CLS N=115 P=0 DO UNTIL N=0 R=N MOD 8 S=S+R*10^P P=P+1 N=N\8 LOOP PRINT S END f.           2.       Read the following program and answer the questions: a.       CLS N=115 WHILE N<>0 R=N MOD 8 S=S+R*10^P P=P+1 N=N/8

Question collections of SUB Procedure

Image
1.       Write a program to input base and height of the triangle from user. The program should calculate and display the area of the triangle using SUB END SUB statement. 2.       Write a Sub program to print area of cylinder, if radius and height of cylinder are given by the user in main module and pass them as parameter list when Sub program is called. 3.       Write a sub procedure to find the solution of quadratic equation ax 2 +bx+c=0. The program should ask the value a, b and c from user in main module and pass them as parameter list when a Sub Program is called. 4.        Write a Sub Program to display the acceleration of car. The program should ask initial velocity, final velocity and time taken by the car from user in main module and pass them as parameter list when a Sub Program is called. 5.       Write a Sub Program to check whether an input number is “Positive” or “Negative” or “Zero”. The program should ask a number from user in main module and passes it as par

Question collections of FUNCTION Procedure

1.       Write a function procedure to print the distance travelled by a car. The program should ask initial velocity, final velocity and time taken by the car and the program should pass them as parameter list when a function procedure is called. 2.       Write a function program to check whether an input number is “positive” or “negative” or zero. The program should ask a number from user in main module and pass it as parameter list when a function program is called. 3.       Write a function program to decide whether an input number is even or odd. The program should ask a number from user in main module and pass it as parameter list. 4.       Write a function procedure to print square of first 10 natural numbers. 5.       Write a function procedure to display the sum of digits in an input number. The program should ask a number from user in main module and pass it as parameter list when a function is called. 6.       Write a function procedure to display sum of even dig

Solution of FUNCTION Procedure2

1. Using FUNCTION...END FUNCTION , write a program to calculate distance travelled by a body.[Hint: S=ut+1/2at^2] DECLARE FUNCTION distance (u, t, a) CLS INPUT "Enter an initial velocity"; u INPUT "Enter time taken"; t INPUT "Enter acceleration"; a PRINT "The distance travelled is "; distance(u, t, a) END FUNCTION distance (u, t, a) distance = u * t + 1 / 2 * a * t ^ 2 END FUNCTION 2. Write a program using Function module to calculate and print the volume of a box. DECLARE FUNCTION volume (l, b, h) CLS INPUT "Enter length"; l INPUT "Enter breadth"; b INPUT "Enter height"; h PRINT "The volume of box is "; volume(l, b, h) END FUNCTION volume (l, b, h) volume = l * b * h END FUNCTION 3. Write a program using FUNCTION...END FUNCTION to find the average of any two numbers given by the users. DECLARE FUNCTION average (a, b) CLS INPUT "Enter first number"; a INPUT &

Solution of FUNCTION Procedure1

1. Write a program to declare a user defined function to return sum of any digits of number by using FUNCTION...END FUNCTION. DECLARE FUNCTION sum(N) CLS INPUT "Enter a number";N PRINT "Sum of digits of a number is ";sum(N) END FUNCTION sum(N) WHILE N<>0 R=N MOD 10 S=S+R N=N\10 WEND sum=S END FUNCTION 2. Write a program to count total number of alphabet "A" occurred in a string, where string is passed as a parameter by using FUNCTION...END FUNCTION. DECLARE FUNCTION countA(S$) CLS INPUT "Enter a string";S$ PRINT "Total number of A occurred in a string is ";countA(S$) END FUNCTION countA(S$) FOR I=1 TO LEN(S$) IF UCASE$(MID$(S$,I,1))="A" THEN c=c+1 END IF NEXT I countA=c END FUNCTION 3. Write a program to print Armstrong number between 1 to 2000 by using FUNCTION....END FUNCTION. DECLARE FUNCTION display( ) CLS v=display END FUNCTION display FOR I=1 TO 2000 S=0 N=I WHILE N<

Solution of FUNCTION Procedure

1. Write a program to calculate the volume of a cylinder using FUNCTION...END FUNCTION. DECLARE FUNCTION volume(r,h) CLS INPUT "Enter radius of a cylinder";r INPUT "Enter height of a cylinder";h PRINT "Volume of a cylinder is ";volume(r,h) END FUNCTION volume(r,h) v=22/7*r^2*h volume=v END FUNCTION 2. Write a program to declare user defined function to count total number of  alphabet 'A' occurred in a  given string where string is passed as a parameter.[use FUNCTION...END FUNCTION.] DECLARE FUNCTION countA(S$) CLS INPUT "Enter a string";S$ PRINT "Total number of alphabet  A is " ;countA(S$) END FUNCTION countA(S$) FOR I=1 TO LEN(S$) C$=UCASE$(MID$(S$,I,1)) IF C$="A" THEN c=c+1 END IF NEXT I countA=c END FUNCTION 3. Write a program to print the middle number among the three different number using FUNCTION...END FUNCTION. DECLARE FUNCTION middle(A,B,C) CLS INPUT "Enter a first nu

Solution of File's Question2 of QBASIC

1. Write a program to create a sequential data file "Employee.dat" to store employee's name, Address, Age, Gender and salary. OPEN "Employee.dat" FOR OUTPUT AS #1 CLS INPUT "Enter name";N$ INPUT "Enter Address";A$ INPUT "Enter Age";Age INPUT "Enter Gender";G$ INPUT "Enter Salary";S WRITE #1, N$,A$,Age,G$,S CLOSE #1 END 2. A data file "LIB.TXT" consists of Book's name, Author 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,BN$,AN$,P PRINT BN$,AN$,P c=c+1 WEND CLOSE #1 PRINT "Total number of records is ";c END 3. A sequential data file "EMP.DAT" contains name, post and salary 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

Questions collection of file of QBASIC

1.       WAP to create a sequential data file “std.dat” to store Name and Mark obtained in English,Math and Science subjects for a few students. 2.       WAP to create a data file “PERSON.DAT” to store person’s Name, Address, Telephone number  and district of N different students. 3.       WAP to create a serial file having variable length records of name, department and telephone number. Telephone number should be in between 2000000 to 9999999. 4.       WAP to create a data file STD.DAT which stores Roll number,Name,Class and age of 10 different students. Age of students must be in between 15 to 19. 5.       WAP to create a data file named “store.dat” which stores the following data: Serial number, Book name, Author name and ISBN number.Add the data as user’s choice. 6.       WAP to create a data file named “store.dat” which stores the following data: Roll number, name and class of N number of students. 7.       WAP to create  a data file (MARK.DAT) and store a name, add