Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Monday, March 6, 2023

qbasic sequence structure using function procedure.

 qbasic sequence structure using function procedure.

qbasic sequence structure using function procedure


QBasic is a popular programming language used for developing various kinds of applications. One of the fundamental building blocks of any program is the sequence structure. It helps in executing statements one after the other in a specific order. In this article, we will explore how to create a sequence structure program using function procedure in QBasic.

Function Procedure in QBasic


A function procedure is a block of code that performs a specific task and returns a value. It is a reusable piece of code that can be called multiple times from different parts of the program.

The syntax for creating a function procedure in QBasic is as follows:

FUNCTION <FunctionName>([<ParameterList>])

    <Statements>

    [RETURN <Expression>]

END FUNCTION

Here, <FunctionName> is the name of the function, <ParameterList> is the list of parameters that the function takes, <Statements> are the statements that are executed when the function is called, and <Expression> is the value that the function returns.


Examples of sequence structure using Function procedure

 

1) WAP to input any 2 numbers and display their sum.

DECLARE FUNCTION add(a,b)
CLS
INPUT "Enter any two numbers:-";a,b
t=add(a,b)
PRINT "Sum=";t
END
FUNCTION add(a,b)
s=(a+b)
add=s
END FUNCTION
 
2) WAP to calculate the volume of a cylinder. [Hints: volume=Ï€R2H] 
SLC specification Grid 2065
DECLARE FUNCTION vol(r,h)
CLS
INPUT "Enter Radius and height=";r,h
PRINT "Volume of cylinder=";vol(r,h)
END
FUNCTION vol(r,h)
vol=22/7*r*h
END FUNCTION
 
3) WAP to calculate and print the simple interest.
DECLARE FUNCTION si(p,t,r)
CLS
INPUT "Enter Principal amount=";p
INPUT "Enter time=";t
INPUT "Rate of interest=";r
END
FUNCTION si(p,t,r)
si=(p*t*r)/100
END FUNCTION
 
4) Write a program in QBASIC to find the area of four walls of a room  (Hints=A=2h(l+b))  (SLC 2064)
DECLARE FUNCTION area (l, b, h)
CLS
INPUT "Enter length="; l
INPUT "enter breadth="; b
INPUT "Enter height="; h
PRINT "The area of four walls="; area(l, b, h)
END
FUNCTION area (l, b, h)
a = 2 * h * (l + b)
area = a
END FUNCTION
 
5) WAP to convert Nepali currency into Indian currency.
DECLARE FUNCTION currency (n)
CLS
INPUT "Enter currency in Nepali"; n
s = currency(n)
PRINT "Equivalent Indian currency"; s
END
 
FUNCTION currency (n)
currency = n / 1.6
END FUNCTION
 
6) WAP to calculate distance traveled by a body. [Hints: s=ut+1/2at2]. Where u is initial velocity t is time, s is distance and a is acceleration. (SLC 2065)
DECLARE FUNCTION distance(u,t,a)
INPUT "enter initial velocity=";u
INPUT "enter time=";t
INPUT "enter acceleration";a
PRINT distance(u,t,a)
END
FUNCTION distance(u,t,a)
distance= u*t+1/2*a*t^2
END FUNCTION
 
7) WAP using Function module to calculate and print the volume of a box. (SLC 2066)
DECLARE FUNCTION vol (l, b, h)
INPUT "enter length, breadth, height"; l, b, h
PRINT "The volume of the box="; vol(l, b, h)
END
FUNCTION vol (l, b, h)
v = l * b * h
vol = v
END FUNCTION
 
8.  WAP to calculate the average of three numbers. (SLC 2067 , SEE 2075)
DECLARE FUNCTION avg(a,b,c)
CLS
INPUT "Enter any three numbers=";a,b,c
PRINT avg(a,b,c)
END
FUNCTION avg(a,b,c)
avg=(a+b+c)/3
 
9. WAP to input string in lowercase and display in uppercase.
DECLARE FUNCTION upper$(a$)
CLS
INPUT "Enter any string in lowercase:";a$
upp$=upper$(a$)
PRINT "String in uppercase:";upp$
END
FUNCTION upper$(a$)
upper$=UCASE$(a$)
END FUNCTION
 
10. WAP to input distance in kilo meter and convert it into meter.
DECLARE FUNCTION convert(k)
CLS
INPUT "Distance in kilo meter:-";k
m=convert(k)
PRINT "Distance in meter:-";m
END
FUNCTION convert(k)
me=k*1000
convert=me
END FUNCTION
 
11. WAP to input temperature in centigrade and convert it into Fahrenheit. [Hints: F=9/5*c+32]
DECLARE FUNCTION temp(c)
CLS
INPUT "Enter temperature in Celsius"; c
t=temp(c)
PRINT "Temperature in Fahrenheit:-";t
FUNCTION temp(c)
f=(9/5)*c+32
temp=f
END FUNCTION
 
12. WAP to input length and breadth, calculate area and display it.
DECLARE FUNCTION area(l,b)
INPUT "Enter Length and breadth:-";l,b
a=area(l,b)
PRINT "Area=";a
END
FUNCTION area(l,b)
ar=l*b
area=ar
END FUNCTION
 
13. WAP to print the area of triangle. [Hits: area=1/2×b×h]
DECLARE FUNCTION area(b,h)
CLS
INPUT "Enter base and height of a triangle=";b,h
PRINT "Area of triangle=";area(b,h)
END
FUNCTION area(b,h)
Area=1/2*b*h
END FUNCTION
 
 14. WAP to calculate and print the total surface area of a box. [Hints: a=2(lb+bh+hl)
DECLARE FUNCTION area(l,b,h)
CLS
PRINT "Surface area of a box=";area(l,b,h)
END
FUNCTION area(l,b,h)
area=2*(l*b+b*h+h*l)
END FUNCTION
 
15. Write a program find area of the triangle.
DECLARE FUNCTION AR(B,H)
CLS
INPUT “ENTER BASE”;B
INPUT “ENTER HEIGHT”;H
PRINT “AREA ”;AR(B,H)
END
FUNCTION AR(B,H)
AR=0.5*(B*H)
END FUNCTION
 
16.  WAP to calculate and print the volume of a cylinder .
DECLARE FUNCTION VOL (R, H)
CLS
INPUT “ENTER RADIUS”; R
INPUT “ENTER HEIGHT”; H
PRINT “VOLUME: ”; VOL(R, H)
END
FUNCTION VOL(R, H)
VO = 3.14 * R ^ 2 * H
VOL = VO
END FUNCTION



Conclusion

In this article, we have learned how to create a sequence structure program using function procedure in QBasic. We have seen how function procedures can be used to perform a specific task and return a value. By breaking down our program into smaller, reusable functions, we can create more modular and maintainable code.

 

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages