Lab Report 7 - PROGRAMMING - BEE16A - 518331 - IRSA BATOOL
Lab Report 7 - PROGRAMMING - BEE16A - 518331 - IRSA BATOOL
Name CMS
Irsa Batool 518331
1|FOCP
Table of Contents
TASK 1 ………………………………………………………………3
TASK 2 ………………………………………………………………4
TASK 3 ………………………………………………………………7
2|FOCP
TASK 1: FINAL PAY (NET)
#include <iostream>
using namespace std;
double computeSalary(double base, double extra = 0) {
double totalPay, finalPay, deduction = 0;
totalPay = base + extra;
if (base < 59999)
cout << "Error: salary less than 59999";
else if (base >= 59999 && base <= 99999)
deduction = (7.0 / 100) * totalPay;
else if (base >= 100000 && base <= 149999)
deduction = (14.0 / 100) * totalPay;
else if (base >= 150000 && base <= 299999)
deduction = (25.0 / 100) * totalPay;
else if (base >= 300000)
deduction = (35.0 / 100) * totalPay;
else
cout << "Error";
finalPay = totalPay - deduction;
cout << "\nTotal Salary: " << totalPay << endl;
cout << "Tax Deducted: " << deduction << endl;
return finalPay;
}
int main() {
double baseSalary, extraPay;
cout << "Enter the base salary: ";
cin >> baseSalary;
cout << "Enter extra pay (enter 0 if none): ";
cin >> extraPay;
double netPay = computeSalary(baseSalary, extraPay);
cout << "Net Salary: " << netPay << endl;
return 0;
}
3|FOCP
TASK 2: CALCULATOR
include <iostream>
using namespace std;
double addNumbers(double x, double y) {
return x + y;
}
double subtractNumbers(double x, double y) {
return x - y;
}
double multiplyNumbers(double x, double y) {
return x * y;
}
double divideNumbers(double x, double y) {
if (y != 0) {
return x / y;
}
else {
cout << "Error: Division by zero is not allowed.\n";
return 0;
}
}
int findRemainder(int x, int y) {
if (y != 0) {
return x % y;
}
4|FOCP
else {
cout << "Error: Division by zero is not allowed.\n";
return 0;
}
}
double calculateAverage(double x, double y) {
return (x + y) / 2;
}
double findSmallerNumber(double x, double y) {
return (x < y) ? x : y;
}
double findLargerNumber(double x, double y) {
return (x > y) ? x : y;
}
int main() {
double numberOne, numberTwo;
int userChoice;
while (true) {
cout << "Enter two numbers: ";
cin >> numberOne >> numberTwo;
5|FOCP
cout << "Result: " << divideNumbers(numberOne, numberTwo)
<< endl;
break;
case 5:
cout << "Result: " << findRemainder(numberOne, numberTwo)
<< endl;
break;
case 6:
cout << "Result: " << calculateAverage(numberOne,
numberTwo) << endl;
break;
case 7:
cout << "Smaller number: " << findSmallerNumber(numberOne,
numberTwo) << endl;
break;
case 8:
cout << "Bigger number: " << findLargerNumber(numberOne,
numberTwo) << endl;
break;
case 9:
cout << "Exiting program..." << endl;
return 0;
default:
cout << "Invalid choice. Please try again." << endl;
break;
}
}
return 0;
}
6|FOCP
TASK 3: ENCRYPT-DECRYPT
#include <iostream>
using namespace std;
void enc(int p) {
int x = p / 1000;
int y = (p / 100) % 10;
int z = (p / 10) % 10;
int w = p % 10;
x = (x + 7) % 10;
y = (y + 7) % 10;
z = (z + 7) % 10;
w = (w + 7) % 10;
swap(x, z);
swap(y, w);
cout << "Secured: " << x << y << z << w << endl;
}
void dec(int p) {
int x = p / 1000;
int y = (p / 100) % 10;
int z = (p / 10) % 10;
int w = p % 10;
swap(x, z);
swap(y, w);
x = (x + 3) % 10;
y = (y + 3) % 10;
z = (z + 3) % 10;
7|FOCP
w = (w + 3) % 10;
cout << "Original: " << x << y << z << w << endl;
}
int main() {
int p, c;
while (true) {
cout << "1. Encrypt\n2. Decrypt\n3. Exit\nPick: ";
cin >> c;
if (c == 1) {
cout << "Enter PIN: ";
cin >> p;
enc(p);
}
else if (c == 2) {
cout << "Enter Secured PIN: ";
cin >> p;
dec(p);
}
else if (c == 3) {
cout << "Bye!" << endl;
break;
}
else {
cout << "Invalid! Try again." << endl;
}
}
return 0;
}
8|FOCP
9|FOCP