#include #include using namespace std; const int NUM_PRODUCTS = 3; // Number of products float calculateTotalPrice(float price, int quantity); int main() { float price[NUM_PRODUCTS]; int quantity[NUM_PRODUCTS]; // Input prices and quantities for each product for (int i = 0; i < NUM_PRODUCTS; ++i) { cout << "Enter price for product " << i + 1 << ": "; cin >> price[i]; cout << "Enter quantity for product " << i + 1 << ": "; cin >> quantity[i]; } // Calculate total price for each product float totalPrices[NUM_PRODUCTS]; for (int i = 0; i < NUM_PRODUCTS; ++i) { totalPrices[i] = calculateTotalPrice(price[i], quantity[i]); } // Calculate overall total price float overallTotalPrice = 0; for (int i = 0; i < NUM_PRODUCTS; ++i) { overallTotalPrice += totalPrices[i]; } // Display results cout << fixed << setprecision(2); for (int i = 0; i < NUM_PRODUCTS; ++i) { cout << "Total price for product " << i + 1 << ": " << totalPrices[i] << endl; } cout << "Overall total price including GST: " << overallTotalPrice << endl; return 0; } // Function to calculate total price including GST for a product float calculateTotalPrice(float price, int quantity) { const float GST_RATE = 0.18; float totalPrice = price * quantity * (1 + GST_RATE); return totalPrice; } 2) #include #include using namespace std; const float PI = 3.14159; float calculateArea(char shape) { float area = 0.0; switch (shape) { case 'C': // Circle { float radius; cout << "Enter the radius of the circle: "; cin >> radius; area = PI * pow(radius, 2); } break; case 'T': // Triangle { float base, height; cout << "Enter the base of the triangle: "; cin >> base; cout << "Enter the height of the triangle: "; cin >> height; area = 0.5 * base * height; } break; case 'U': // Cuboid { float length, width, height; cout << "Enter the length of the cuboid: "; cin >> length; cout << "Enter the width of the cuboid: "; cin >> width; cout << "Enter the height of the cuboid: "; cin >> height; area = 2 * (length * width + length * height + width * height); } break; default: cout << "Invalid shape code!" << endl; } return area; } int main() { char shape; // Calculate area of a circle cout << "Enter 'C' for circle: "; cin >> shape; cout << "Area of the circle: " << calculateArea(shape) << endl; // Calculate area of a triangle cout << "Enter 'T' for triangle: "; cin >> shape; cout << "Area of the triangle: " << calculateArea(shape) << endl; // Calculate area of a cuboid cout << "Enter 'U' for cuboid: "; cin >> shape; cout << "Area of the cuboid: " << calculateArea(shape) << endl; return 0; } 3)a #include using namespace std; int main() { int n; cout << "Enter an integer: "; cin >> n; // Using a loop instead of recursion unsigned long factorial = 1; for (int i = 1; i <= n; ++i) { factorial *= i; } cout << "Factorial of " << n << " is " << factorial << endl; return 0; } 3)b #include using namespace std; int main() { int n; cout << "Enter a positive integer: "; cin >> n; // Without using recursion, using a while loop int factorial = 1; int i = 1; while (i <= n) { factorial *= i; i++; } cout << "Factorial of " << n << " is " << factorial << endl; return 0; } 4) #include #include using namespace std; // Inline function to calculate total price including GST for a product inline float calculateTotalPrice(float price, int quantity) { const float GST_RATE = 0.18; return price * quantity * (1 + GST_RATE); } int main() { // Product 1 float price1; int quantity1; cout << "Enter price for product 1: "; cin >> price1; cout << "Enter quantity for product 1: "; cin >> quantity1; // Product 2 float price2; int quantity2; cout << "Enter price for product 2: "; cin >> price2; cout << "Enter quantity for product 2: "; cin >> quantity2; // Product 3 float price3; int quantity3; cout << "Enter price for product 3: "; cin >> price3; cout << "Enter quantity for product 3: "; cin >> quantity3; // Calculate total price for each product using inline function float totalPrice1 = calculateTotalPrice(price1, quantity1); float totalPrice2 = calculateTotalPrice(price2, quantity2); float totalPrice3 = calculateTotalPrice(price3, quantity3); // Calculate overall total price float overallTotalPrice = totalPrice1 + totalPrice2 + totalPrice3; // Display results cout << fixed << setprecision(2); cout << "Total price for product 1........: " << totalPrice1 << endl; cout << "Total price for product 2........: " << totalPrice2 << endl; cout << "Total price for product 3........: " << totalPrice3 << endl; cout << "Overall total price including GST: " << overallTotalPrice << endl; return 0; }