0% found this document useful (0 votes)
4 views9 pages

Lab Report 7 - PROGRAMMING - BEE16A - 518331 - IRSA BATOOL

The document outlines a programming lab assignment for CS-107, focusing on functions in C++. It includes three tasks: calculating final pay with deductions, implementing a basic calculator, and creating encryption/decryption functions for a PIN. Each task is accompanied by code examples and user interaction prompts.

Uploaded by

marif.bee24seecs
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)
4 views9 pages

Lab Report 7 - PROGRAMMING - BEE16A - 518331 - IRSA BATOOL

The document outlines a programming lab assignment for CS-107, focusing on functions in C++. It includes three tasks: calculating final pay with deductions, implementing a basic calculator, and creating encryption/decryption functions for a PIN. Each task is accompanied by code examples and user interaction prompts.

Uploaded by

marif.bee24seecs
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/ 9

CS-107

Department of Electrical Engineering


Computer Programming
Lab 07: Functions
BEE-16A

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;

cout << "\nChoose an operation:" << endl;


cout << "1. Addition" << endl;
cout << "2. Subtraction" << endl;
cout << "3. Multiplication" << endl;
cout << "4. Division" << endl;
cout << "5. Modulus (for integers)" << endl;
cout << "6. Average" << endl;
cout << "7. Smaller number" << endl;
cout << "8. Bigger number" << endl;
cout << "9. Quit" << endl;
cout << "Enter your choice (1-9): ";
cin >> userChoice;
switch (userChoice) {
case 1:
cout << "Result: " << addNumbers(numberOne, numberTwo) <<
endl;
break;
case 2:
cout << "Result: " << subtractNumbers(numberOne, numberTwo)
<< endl;
break;
case 3:
cout << "Result: " << multiplyNumbers(numberOne, numberTwo)
<< endl;
break;
case 4:

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

You might also like