0% found this document useful (0 votes)
43 views8 pages

Name: Muhammad Usama Israr

The document contains registration information for a student named Muhammad Usama Israr taking an Operating System Lab course, along with 4 answers the student provided for assignments in the course. The answers include bash scripts, a Python program to calculate loan payments, and code snippets in other languages.

Uploaded by

sakina zaidi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views8 pages

Name: Muhammad Usama Israr

The document contains registration information for a student named Muhammad Usama Israr taking an Operating System Lab course, along with 4 answers the student provided for assignments in the course. The answers include bash scripts, a Python program to calculate loan payments, and code snippets in other languages.

Uploaded by

sakina zaidi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

NAME : MUHAMMAD USAMA ISRAR

REGISTRATION : 49746

COURSE : OPERATING SYSTEM LAB

Instructor: Sania Mariam/Rukhsana Majeed/


Qazi Shahab Azam/Qazi Abdul Samad
ANSWER 01
Here’s the bash script:

#!/bin/sh

n=10

i=0

while [ $i –it $n]

do

read a [$i]

r = a[$i] %2

m = $i%2

it [ $m –eq 0 ]

then

if [$r –ne 0 ]

then

echo “ invalid input”

break

fi

fi

done

ANSWER 02
#!/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"

ANSWER 03
Programming
Challenge
3.17 -
Monthly
Payments

//

// The monthly payment on a loan may be calculated by the following formula:

//

// Rate * (1 + Rate)^N

// Payment = --------------------- * L

// ((1 + Rate)^N - 1)

//

// Rate is the monthly interest rate, which is the annual interest rate divided

// by 12. (12% annual interest would be 1 percent monthly interest.) N is the

// number of payments and L is the amount of the loan. Write a program that asks

// for these values and displays a report similar to:

//

// Loan Amount: $ 10000.00

// Monthly Interest Rate: 1%


// Number of Payments: 36

// Monthly Payment: $ 332.14

// Amount Paid Back: $ 11957.15

// Interest Paid: $ 1957.15

//

// written by Walter Vaughan for CSC 134, section 200, Fall 2014

// at Catawba Valley Community College

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

int main() {

double loanAmt, rate; // input variables

int numPayments;

double monthlyPayment; // output variable

// gather input

cout << "Enter the Loan Amount: ";

cin >> loanAmt;

cout << "Enter the Monthly Interest Rate (as a decimal): ";

cin >> rate;

cout << "Enter the desired number of payments: ";

cin >> numPayments;

// generate the exact amount

monthlyPayment = (rate * pow(1+rate, numPayments))


/ (pow(1+rate, numPayments) - 1)

* loanAmt;

// we need to round up the amount (in cents) because financial companies

// like to pull that shit. If we round down the amount, we could end up

// paying too little to match the total interest amount, and if we don't

// round at all, our payments will not sum to the calculated interest rate.

monthlyPayment = ceil( monthlyPayment * 100.0 ) / 100.0;

// output the financial data

cout << "Loan Amount: $"

<< setw(9) << fixed << setprecision(2) // formatting

<< loanAmt << endl;

cout << "Monthly Interest Rate: "

<< setw(9) << fixed << setprecision(2)

<< rate * 100 << " %" << endl;

cout << "Number of Payments: "

<< setw(9) << numPayments << endl;

cout << "Monthly Payment: $"

<< setw(9) << fixed << setprecision(2)

<< monthlyPayment << endl;

cout << "Amount Paid Back: $"

<< setw(9) << fixed << setprecision(2)

<< monthlyPayment * numPayments << endl;

cout << "Interest Paid: $"

<< setw(9) << fixed << setprecision(2)

<< ( monthlyPayment * numPayments ) - loanAmt << endl;


return 0;

ANSWER 04
Public class main

{
public static void main (string[] args ) {

Boolean res;

System.out.printin(“Perfect numbers between 1 to 1000 are:”);

For(int i=1;i<=1000;i++){

If(isperfectnumber(i))

System.out.printin(i);

Publib static Boolean is perfectnumber (int number){

Int[] factors=new int[1000];

Int j=0,I;

Int sum=0;

For (i=1;i<=number/2;i++){

If(number%i==0){

Factor[j]=I;

J++:

For (int k=0;k<i-1;k++){

Sum+=factors[k];
}

If(sum==number)

Return true;

Else

Return false;

You might also like