Sei sulla pagina 1di 10

/*******************************************************************************

File -Lab 1(PSEUDOCODE)

Author name -Deepika Sharma (deepika.a.sharma@capgemini.co)

Description -Test the basic programming concept

Version -NA

Last modified date -NA

Change description -NA

*******************************************************************************/

1.1 Rima is working in State Electricity Board Project. She got the following requirement. The
following information has to be accepted from the user to calculate the net electricity bill amount.

• User ID

• User Name

• Last month meter reading

• Current month meter reading

Unit consumed = (Last month meter reading) – (Current month meter reading)

Net Amount = Unit consumed * 1.15 +Fixed Charge

Assume Fixed Charge is always Rs.100.

Write pseudo code to print the electricity bill. The bill should be in the following format

User ID:

User Name:

Unit Consumed:

Net amount:
SOL:

BEGIN

DECLARE userid , LMR , CMR ,unitconsumed , netamt aAS INTEGER

DECLARE username AS STRING

DEclare fixed_charges=100

PRINT "enter user id"

ACCEPT userid

PRINT "enter user name"

ACCEPT username

PRINT "enter user's last month reading"

ACCEPT LMR

PRINT "enter user's current month reading"

ACCEPT CMR

CALCULATE unitconsumed=CMR-LMR

CALCULATE netamt=unitconsumrd*1.15+fixedcharges

DISPLAY "User ID" userid

DISPLAY "User Name" username

DISPLAY "Unit Consumed" unitconsumed

DISPLAY "Net Amount" netamt

END
/***************************************************************************/

1.2 Organization employees are recognized with different tags based on their experience.

Years of Experience Tag Color

0 - <3 Blue

3 - <5 Grey

5 - <10 Yellow

>10 Red

Write pseudo code to accept the experience and display their tag Color.

SOL:

BEGIN

DECLARE empband AS STRING

DECLARE empexp AS INTEGER

DECLARE empdata[n] AS EMPLOYEE ARRAY

PRINT "enter no of experirnce"

FOR index FROM 0 TO n

ACCEPT n

IF empexp>=0 AND <3

PRINT "empband=Blue"

ELSEIF empexp>=3 AND <5


PRINT "empband =Grey"

ELSEIF empexp>=5 AND <10

PRINT "empband=yellow"

ELSE empexp>=10

print "empband=Red"

ENDFOR

END

/***********************************************************************************/

QUES 1.3: Write pseudo code to print the following mathematical series 0 1 1 2 3 5 8 13 21 …. N. Where
N is accepted from the user.

SOL : BEGIN

DECLARE a AS INTEGER

INITIALISE a TO 0

DECLARE b AS INTEGER

INITIALISE b TO 1

DECLARE next AS INTEGER

DECLARE n AS INTEGER

PRINT “enter the term upto which you want to print fibonnaci series”
ACCEPT n

FOR var FROM 0 TO n

IF var <=0

next=var

ELSE

Next=a+b

a=b

b=next

END IF

PRINT next

END FOR

END

/***********************************************************************************/

1.4 Write a pseudo code to accept a number and check whether a given number is an Armstrong
number.For example, 371 is an Armstrong number

since (3*3*3) + (7*7*7) + (1*1*1) = 371.

SOL : BEGIN

DECLARE number , original_number , ramainder , result AS INTEGER


INITIALISE result TO 0

ACCEPT number

CALCULATE original_number=number

WHILE original_number!= 0

CALCULATE remainder = original_number%10

CALCULATE result = remainder*remainder*remainder

CALCULATE original_number=original_number/10

ENDWHILE

IF result==number

PRINT "it is an armstrong number"

ELSEIF result!= number

PRINT "not armstrong no"

ENDIF

END

/***********************************************************************************/

1.5 Write a pseudo code to convert a binary number to decimal. For an Example, if the given input is
00000100(binary number),then the output

should be 4(Decimal number).


SOL : BEGIN

DECLARE binary AS INTEGER

DECLARE decimal AS INTEGER

ACCEPT binary

DECLARE power AS INTEGER

INITIALISE power TO 0

WHILE (binary>0)

DO

CALCULATE DECIMAL+ =(binary%10)*pow(2,power)

CALCULATE power=power+1

CALCULATE binary=binary/10

ENDWHILE

PRINT decimal

END

/***********************************************************************************/

1.6 Write a pseudo code to accept 10 numbers in an array and do the following using a loop.

1.6.1 Display the smallest number.

1.6.2 Display all ODD and EVEN numbers separately


SOL : BEGIN

DECLARE var , array[10] AS INTEGER

INITIALIASE var 0 TO 9

FOR var 0 TO 9

ACCEPT array[var]

ENFFOR

INITIALISE min=array[0]

FOR(var 0 TO 9)

IF (min < array[var])

CALCULATE min = array[var]

ENDIF

ENDFOR

PRINT min="min"

FOR(var 0 TO 9)

IF(array[var] % 2 == 0)

PRINT array[var]

ENDIF

ENDFOR

FOR(var 0 TO 9)

IF(array[var] % 2 != 0)
PRINT array[var]

ENDIF

ENDFOR

END

/***********************************************************************************/

1.7 Modify the below Pseudocode to implement good programming practices. The below
Pseudocode is used to calculate total price of a product

including tax.

BEGIN

Print "Enter price of your product"

Accept p

tc=p*.56

Print "Total price of product is": tc

END

Hint: .56 is the Tax rate.

SOL : BEGIN

DECLARE product_price AS INTEGER


DECLARE total_cost AS INTEGER

DECLARE TAX_RATE AS INTEGER

INITIALISE TAX_RATE = 0.56

PRINT "Enter price of your product"

ACCEPT product_price

CALCULATE total_cost = product_price * TAX_RATE

Print "Total price of product is": total_cost

END

/***********************************************************************************/

Potrebbero piacerti anche