Professional Documents
Culture Documents
Abdul Rafay Lab 10
Abdul Rafay Lab 10
Abdul Rafay Lab 10
ITPLAB 10
ABDUL RAFAY
bcs241085
#include <iostream>
using namespace std;
double Sale_Price(double purchasePrice, double taxRate) {
// Calculate tax amount
double taxAmount = purchasePrice * (taxRate / 100);
return salePrice;
}
int main() {
double purchasePrice, taxRate, salePrice;
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;
}
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;
}