Saturday, October 22, 2016

Qbasic Program: Electricity Bill



189. WAP to input number of passengers and their destination. The program should calculate the total bus fare and the discount amount according to the following conditions.
Rates for the different destinations:
Destinations                             Rate
Pokhara                                    450 per person
Butwal                                     500 per person
Chitwan                                   300 per person
Discount Rate
If the number of passenger is 5 or above then discount=5% in the total amount.

CLS
INPUT "ENTER NO. OF PASSENGER"; P
INPUT "ENTER DESTINATIONS"; D$
IF UCASE$(D$) = "POKHARA" THEN
T = P * 450
ELSEIF UCASE$(D$) = "BUTWAL" THEN
T = P * 500
ELSEIF UCASE$(D$) = "CHITWAN" THEN
T = P * 300
END IF
IF P >= 5 THEN D = 5 / 100 * T
F = T - D
PRINT "TOTAL BUS FARE="; F
END

USING SUB PROCEDURE

DECLARE SUB TOTAL(P, D$)
CLS
INPUT "ENTER NO. OF PASSENGER"; P
INPUT "ENTER DESTINATIONS"; D$
CALL TOTAL (P, D$)
END

SUB TOTAL (P, D$)
IF UCASE$(D$) = "POKHARA" THEN
T = P * 450
ELSEIF UCASE$(D$) = "BUTWAL" THEN
T = P * 500
ELSEIF UCASE$(D$) = "CHITWAN" THEN
T = P * 300
END IF
IF P >= 5 THEN D = 5 / 100 * T
F = T - D
PRINT "TOTAL BUS FARE="; F
END SUB

190. WAP to input total number of words and compute telegram charges which are as follows:
For the first 20 words    :           Rs 15
For the next 20 words : Rs 10
Above that for each word:         Re 1

CLS
INPUT "ENTER HOW MANY WORDS"; W
IF W <= 20 THEN
C = 15
ELSEIF W > 20 AND W <= 40 THEN
C = 15 + 10
ELSEIF W > 40 THEN
C = 15 + 10 + (W - 40)
END IF
PRINT "NUMBER OF WORDS="; W
PRINT "TOTAL CHARGE="; C

END

USING SUB PROCEDURE

DECLARE SUB TOTAL(W)
CLS
INPUT "ENTER HOW MANY WORDS"; W
CALL TOTAL(W)
END
SUB TOTAL(W)
IF W <= 20 THEN
C = 15
ELSEIF W > 20 AND W <= 40 THEN
C = 15 + 10
ELSEIF W > 40 THEN
C = 15 + 10 + (W - 40)
END IF
PRINT "NUMBER OF WORDS="; W
PRNT "TOTAL CHARGE="; C
END SUB

191. In order to discourage heavy consumption of electricity, the electricity board charges the following rates:
First 80 units:   Rs 4 per unit
Next 60 units: Rs 6 per unit
Above that :     Rs 7 per unit
Every user has to pay a minimum charge of Rs. 100 irrespective of the total amount of electricity consumed. In case total consumption is more than 300 units an additional charge of 10% is added. WAP to read consumer’s name, units consumed and print out total amount to pay along with name of consumer.

CLS
INPUT "ENTER NAME OF A CUSTOMER"; N$
INPUT "ENTER UNIT CONSUMED"; U
IF U <= 80 THEN
C = U * 4
ELSEIF U >= 81 AND U <= 140 THEN
C = 80 * 4
C1 = (U - 80) * 6
ELSE
C = 80 * 4
C1 = 60 * 6
C2 = (U - 140) * 7
END IF
T = 100 + C + C1 + C2
PRINT "NAME OF CUSTOMER"; N$
PRINT "TOTAL UNIT CONSUMPTION"; U
PRINT "TOTAL AMOUNT"; T
END


USING SUB PROCEDURE

DECLARE SUB TOTAL(N$, U)
CLS
INPUT "ENTER NAME OF A CUSTOMER"; N$
INPUT "ENTER UNIT CONSUMED"; U
CALL TOTAL (N$, U)
END

SUB TOTAL (N$, U)
IF U <= 80 THEN
C = U * 4
ELSEIF U >= 81 AND U <= 140 THEN
C = 80 * 4
C1 = (U - 80) * 6
ELSE
C = 80 * 4
C1 = 60 * 6
C2 = (U - 140) * 7
END IF
T = 100 + C + C1 + C2
PRINT "NAME OF CUSTOMER"; N$
PRINT "TOTAL UNIT CONSUMPTION"; U
PRINT "TOTAL AMOUNT"; T
END SUB

192. WAP to supply percentage from the keyboard and print division using sub – program. Use the following conditions:
Percentage                                Division
Per <40                                     Fail
Per>=40 and P<50                     Third
Per>=50 and P<60                     Second
Per>=60 and P<80                     First
Per>=80 and P<100                   Distinction

CLS
INPUT “ENTER PERCENTAGE”; P
IF P>=80 AND P<=100 THEN
PRINT “DIVISION”
ELSEIF P>=60 AND P<80 THEN
PRINT “FIRST DIVISION”
ELSEIF P>=50 AND P<60 THEN
PRINT “SECOND DIVISION”
ELSEIF P>=40 AND P<50 THEN
PRINT “THIRD DIVISION”
ELSEIF P>=0 AND P<40 THEN
PRINT “FAIL”
ELSE
PRINT “PLEASE ENTER THE NUMBER BETWEEN 0 TO 100”
END IF






No comments:

Post a Comment