Saturday, October 22, 2016

Qbasic Program: Quadratic equation



74.  Calculate distance.[S=UT+1/2(AT2)]
REM CALCULATE DISTANCE
CLS
INPUT “ENTER INITIAL VELOCITY”; U
INPUT “ENTER TIME”; T
INPUT “ENTER ACCELARATION”; A
S = U * T + 1 / 2 * A * T ^ 2
PRINT “DISTANCE TRAVELLED = “; S
END

USING SUB PROCEDURE

DECLARE SUB DISTANCE (U, T, A)
CLS
INPUT “ENTER INITIAL VELOCITY”; U
INPUT “ENTER TIME”; T
INPUT “ENTER ACCELARATION”; A
CALL DISTANCE (U, T, A)
END

SUB DISTANCE (U, T, A)
S = U * T + 1 / 2 * A * T ^ 2
PRINT “DISTANCE TRAVELLED = “; S
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION DISTANCE (U, T, A)
CLS
INPUT “ENTER INITIAL VELOCITY”; U
INPUT “ENTER TIME”; T
INPUT “ENTER ACCELARATION”; A
PRINT “DISTANCE TRAVELLED = “;DISTANCE (U, T, A)
END

FUNCTION DISTANCE (U, T, A)
DISTANCE = U * T + 1 / 2 * A * T ^ 2
END FUNCTION





75.   Calculate potential energy of body. [PE=MGH where G=9.8]

REM CALCULATE POTENTIAL ENERGY OF BODY
CLS
INPUT “ ENTER MASS”; M
INPUT “ENTER HEIGHT”; H
P = M * 9.8 * H
PRINT “POTENTIAL ENERGY OF BODY”; P
END

USING SUB PROCEDURE
DECLARE SUB CALULATE(M, H)
CLS
INPUT “ ENTER MASS”; M
INPUT “ENTER HEIGHT”; H
CALL CALULATE (M, H)
END

SUB CALULATE (M, H)
P = M * 9.8 * H
PRINT “POTENTIAL ENERGY OF BODY”; P
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION CALCULATE (M, H)
CLS
INPUT “ ENTER MASS”; M
INPUT “ENTER HEIGHT”; H
PRINT “POTENTIAL ENERGY OF BODY”; CALCULATE (M, H)
END

FUNCTION CALCULATE (M, H)
CALULATE = M * 9.8 * H
END FUNCTION







76. Ask quantity of pen, copy and pencil and their rate and find out the total amount.
CLS
INPUT “ENTER QUANTITY OF PEN”;QP
INPUT “ENTER RATE OF PEN”; RP
INPUT “ENTER QUANTITY OF COPY”; QC
INPUT “ENTER RATE OF COPY”; RC
INPUT “ENTER QUANTITY OF PENCIL”; QPC
INPUT” ENTER RATE OF PENCIL”; RPC
TA = (QP * RP) + (QC * RC) + (QPC * RPC)
PRINT “TOTAL AMOUNT =”; TA
END
USING SUB PROCEDURE
DECLARE SUB TOTAL ()
COMMON SHARED QP, RP, QC, RC, QPC, RPC
CLS
INPUT “ENTER QUANTITY OF PEN”;QP
INPUT “ENTER RATE OF PEN”; RP
INPUT “ENTER QUANTITY OF COPY”; QC
INPUT “ENTER RATE OF COPY”; RC
INPUT “ENTER QUANTITY OF PENCIL”; QPC
INPUT” ENTER RATE OF PENCIL”; RPC
CALL TOTAL
END
SUB TOTAL
TA = (QP * RP) + (QC * RC) + (QPC * RPC)
PRINT “TOTAL AMOUNT =”; TA
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION TOTAL ()
COMMON SHARED QP, RP, QC, RC, QPC, RPC
CLS
INPUT “ENTER QUANTITY OF PEN”;QP
INPUT “ENTER RATE OF PEN”; RP
INPUT “ENTER QUANTITY OF COPY”; QC
INPUT “ENTER RATE OF COPY”; RC
INPUT “ENTER QUANTITY OF PENCIL”; QPC
INPUT” ENTER RATE OF PENCIL”; RPC
PRINT “TOTAL AMOUNT =”; TOTAL
END
FUNCTION  TOTAL
TA = (QP * RP) + (QC * RC) + (QPC * RPC)
TOTAL = TA
END FUNCTION

77. Calculate total saving of a man if he earns Rs. 10,000 per month and spends 20% on food, 15% on children’s education, 10% on entertainment and 20% on rent.
REM CALCULATE TOTAL SAVINGS OF A MAN
CLS
LET S = 10000
F = 20 / 100 * S
C = 15 / 100 * S
E = 10 / 100 * S
R = 20 / 100 * S
T = S – (F + C + E + R)
PRINT “ TOTAL SAVING =”; T
END
USING SUB PROCEDURE
DECLARE SUB SAVING ( S)
COMMON SHARED F, C, E, R
CLS
F = 20 / 100 * S
C = 15 / 100 * S
E = 10 / 100 * S 
R = 20 / 100 * S
CALL SAVING(S)
END
SUB SAVING(10000 )
T = S – (F + C + E + R)
PRINT “ TOTAL SAVING =”; T
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION SAVING ( S)
COMMON SHARED F, C, E, R
CLS
LET S = 10000
F = 20 / 100 * S : C = 15 / 100 * S
E = 10 / 100 * S
R = 20 / 100 * S
PRINT SAVING(S)
END
FUNCTION SAVING( S)
T = S – (F + C + E + R)
SAVING = T
 END FUNCTION



78. Input sales amount and rate of commission then calculate commission and return nt sales. [ns=sa-c)
REM PROGRAM TO CALCULATE NET SALES
CLS
INPUT “ENTER SALES AMOUNT”; A
INPUT “ENTER COMMISSION RATE”; R
C = R / 100 * A
NS = A - C
PRINT “NET SALES=”; NS
END
USING SUB PROCEDURE
DECLARE SUB SALES(A, R)
CLS
INPUT “ENTER SALES AMOUNT”; A
INPUT “ENTER COMMISSION RATE”; R
CALL SALES (A, R)
END
SUB SALES(A, R)
C = R / 100 * A
NS = A - C
PRINT “NET SALES=”; NS : END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION SALES(A, R)
CLS
INPUT “ENTER SALES AMOUNT”; A
INPUT “ENTER COMMISSION RATE”; R
PRINT “NET SALES=”; SALES (A, R)
END
FUNCTION SALES(A, R)
C = R / 100 * A
NS = A - C
SALES = NS
END FUNCTION










79. An organization pays its employees allowance at the rate of 10% of basic salary. WAP to input the salary of the employees and calculate the allowances.

CLS
INPUT “ENTER BASIC SALARY”; S
A = 10 / 100 * S
PRINT “ALLOWANCE=”; A
END

USING SUB PROCEDURE
DECLARE SUB ALLOWANCE (S)
CLS
INPUT “ENTER BASIC SALARY”; S
CALL ALLOWANCE (S)
END
SUB ALLOWANCE (S)
A = 10 / 100 * S
PRINT “ALLOWANCE=”; A
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION ALLOWANCE (S)
CLS
INPUT “ENTER BASIC SALARY”; S
PRINT “NET SALES=”; ALLOWANCE (S)
END

FUNCTION ALLOWANCE (S)
A = 10 / 100 * S
ALLOWANCE = S
END FUNCTION














80. Solve a quadratic equation ax2+bx+c=0 on the basis of the coefficient values a, b, and c.
REM SOLVE A QUADRATIC EQUATION
CLS
INPUT "ENTER VALUE FOR A"; A
INPUT "ENTER VALUE FOR B"; B
INPUT "ENTER VALUE FOR C"; C
D = (B * B - 4 * A * C) ^ (1 / 2)
X = (-B + D) / 2 * A
Y = (-B - D) / 2 * A
PRINT "SOLUTION OF QUADRATIC EQUATION ARE"; X; Y
END
USING SUB PROCEDURE
DECLARE SUB EQUATION (A, B, C)
CLS
INPUT "ENTER VALUE FOR A"; A
INPUT "ENTER VALUE FOR B"; B
INPUT "ENTER VALUE FOR C"; C
CALL EQUATION(A, B, C)
END
SUB EQUATION (A, B, C)
D = (B * B - 4 * A * C) ^ (1 / 2)
X = (-B + D) / 2 * A
Y = (-B - D) / 2 * A
PRINT "SOLUTION OF QUADRATIC EQUATION ARE"; X; Y
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION EQUATION (A, B, C)
COMMON SHARED X
CLS
INPUT "ENTER VALUE FOR A"; A
INPUT "ENTER VALUE FOR B"; B
INPUT "ENTER VALUE FOR C"; C
PRINT "SOLUTION OF QUADRATIC EQUATION ARE"; X; EQUATION(A, B, C)
END
FUNCTION EQUATION (A, B, C)
D = (B * B - 4 * A * C) ^ (1 / 2)
X = (-B + D) / 2 * A
Y = (-B - D) / 2 * A
EQUATION =Y
END FUNCTION


No comments:

Post a Comment