Computer Science, asked by usamasarwer11, 4 months ago

QUESTION NO 01                            05 Marks


Write bash script which takes array as an input of size 10 bind its even indexes to accept even values and odd indexes to accept odd numbers only. Print invalid input if given input is not valid. 




QUESTION NO 02                            10 Marks


Write a bash script for an ABC organization fulfilling the following requirements 

Takes an Employee’s Name , designation, age, years of service and salary, extra working hours as an input

Calculates remaining years of service. An Employee retires at the age of 60

Check if the Employee is valid for salary appraisal. If an employee has been working for more than an year he deserves to be given an appraisal of 10% 

If an employee has given extra working hours within a month to the organization calculate bonus amount. Per hour amount varies depending upon the designation. See the given table to calculate bonus according to designations. 


Designation

Per hour-amount

Higher-Management

1K

Lower-management

800PKR

Other staff

500 PKR

             

Print the Employee’s information along with bonus and appraisal amount















QUESTION NO 03                            05 Marks


The monthly payment for a given loan pays the principal and the interest. The monthly interest is computed by multiplying the monthly interest rate and the balance (the remaining principal).The principal paid for the month is therefore the monthly payment minus the monthly interest. Write bash script that lets the user enter the loan amount, number of years, and interest rate, and then displays the amortization schedule for the loan.

Sample output:

Enter annual interest rate: 5.75

Enter no of years: 5

Enter loan amount: 1000

Interest rate    monthly payment    total payment 

5%        188.8            11322.74   



QUESTION NO 04                            05 Marks


An integer number is said to be a perfect number if its factors, including1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6 =1 + 2 + 3. Write bash script that prints all the perfect numbers between 1 and 1000. Print the factors of each perfect number to confirm that the number is indeed perfect. Challenge the power of your computer by testing numbers much larger than 1000.



Answers

Answered by sanaullahsattar122
1

Answer:

Q 2

#!/bin/bash

read -p "Enter employee name: " ename

read -p "Enter designation: " designation

read -p "Enter age: " age

read -p "Enter years of service: " years

read -p "Enter salary: " salary

read -p "Enter extra working hours: " hours

years_remaining=$(( 60-age ))

#code to calculate appraisal

if [ "$years" -gt 1 ]

then

appraisal=$(( salary/10 ))

else

appraisal=0

fi

#code to calculate the bonus

if [ "$designation" = "Higher-Management" ]

then

bonus=$(( 1000*hours ))

elif [ "$designation" = "Lower-management" ]

then

bonus=$(( 800*hours ))

elif [ "$designation" = "Other staff" ]

then

bonus=$(( 500*hours ))

else

bonus=0

fi

echo "Employee name: $ename"

echo "Age: $age"

echo "Designation: $designation"

echo "Years of service: $years"

echo "Salary: $salary"

echo "Extra working hours: $hours"

echo "Bonus: $bonus"

echo "Appraisal: $appraisal"

Similar questions