Abdul Rafay Lab 10

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

[Year]

ITPLAB 10

ABDUL RAFAY
bcs241085

[Company name] | [Company address]


Practice Task 1:
Write a function that would calculate an item’s sale price based on the item’s purchase price
plus the tax. The function prototype is double Sale_Price (double, double). The first parameter
is the purchase price and the second parameter is the tax. The function will return the sale price
of the product. its formula is: Tax Amount= purchase price *(Tax Rate/100) The formula of
calculating the final price of an item is: Sale Price = Purchase price + Tax Amount.

#include <iostream>
using namespace std;
double Sale_Price(double purchasePrice, double taxRate) {
// Calculate tax amount
double taxAmount = purchasePrice * (taxRate / 100);

// Calculate sale price


double salePrice = purchasePrice + taxAmount;

return salePrice;
}

int main() {
double purchasePrice, taxRate, salePrice;

std::cout << "Enter the purchase price: ";


std::cin >> purchasePrice;

std::cout << "Enter the tax rate (in %): ";


std::cin >> taxRate;

salePrice = Sale_Price(purchasePrice, taxRate);

std::cout << "The sale price is: " << salePrice << std::endl;

return 0;
}
Practice Task 2:
Write a function to print the diamond of size n. n will be taken input from user and pass as an argument
in function by reference.
#include <iostream>
using namespace std;
void printDiamond(int& n) {
// Print top half of diamond
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
std::cout << " ";
}
for (int k = 1; k <= 2 * i - 1; k++) {
std::cout << "*";
}
std::cout << std::endl;
}

// Print bottom half of diamond


for (int i = n - 1; i >= 1; i--) {
for (int j = 1; j <= n - i; j++) {
std::cout << " ";
}
for (int k = 1; k <= 2 * i - 1; k++) {
std::cout << "*";
}
std::cout << std::endl;
}
}

int main() {
int n;
std::cout << "Enter the size of the diamond: ";
std::cin >> n;
printDiamond(n);
return 0;
}
Practice Task 3:
Write a program that implements isVowel that returns the value true if a given character is a vowel and
otherwise returns false. Mention proper function declaration/prototype, and function call from 160 the
main body. Out comes The outcomes of this lab were: a) You have learnt functions: pass-by-value b) You
have learnt functions: pass-by-value c) You have learned the scenarios where to use pass-by-value and
where to use pass-by-reference.
#include <iostream>
using namespace std;
// Function declaration/prototype
bool isVowel(char c);

int main() {
char c;
std::cout << "Enter a character: ";
std::cin >> c;
bool is_vowel = isVowel(c);
if (is_vowel) {
std::cout << c << " is a vowel." << std::endl;
}
else {
std::cout << c << " is not a vowel." << std::endl;
}
return 0;
}

// Function definition
bool isVowel(char c) {
c = tolower(c); // Convert to lowercase for easier comparison
const std::string vowels = "aeiou";
return vowels.find(c) != std::string::npos;
}

You might also like