Programming Fundamental
(Assignment-2)
Question 1
#include <iostream>
using namespace std;
char customerName[50];
char customerID[20];
int customerType;
int meterType;
void registerCustomer();
int displayMenu();
float calculateBill(int units);
float calculateGST(float amount);
float calculateIncomeTax(float amount);
float calculateDuty(float amount);
float calculateFixedCharges(int units);
float calculateNewConnectionCharges();
void displayBill();
void displayCustomerDetails();
int main()
{
registerCustomer();
int choice;
do
{
choice = displayMenu();
if(choice == 1)
{
displayBill();
}
else if(choice == 2)
{
cout << "\nNew Connection Charges = Rs. ";
cout << calculateNewConnectionCharges() << endl;
}
else if(choice == 3)
{
displayCustomerDetails();
}
else if(choice == 4)
{
cout << "\nProgram Ended.\n";
}
else
{
cout << "\nInvalid Choice.\n";
}
} while(choice != 4);
return 0;
}
void registerCustomer()
{
cout << "Enter Customer Name: ";
cin >> customerName;
cout << "Enter Customer ID: ";
cin >> customerID;
cout << "\nCustomer Type\n";
cout << "1. Household\n";
cout << "2. Commercial\n";
cin >> customerType;
cout << "\nMeter Type\n";
cout << "1. First Meter\n";
cout << "2. Second Meter\n";
cin >> meterType;
}
int displayMenu()
{
int choice;
cout << "\n ! MENU ! \n";
cout << "1. Calculate Electricity Bill\n";
cout << "2. Apply For New Connection\n";
cout << "3. View Customer Details\n";
cout << "4. Exit\n";
cout << "Enter Choice: ";
cin >> choice;
return choice;
}
float calculateBill(int units)
{
float rates[8] =
{
12.21,
14.53,
31.51,
38.41,
41.62,
43.04,
44.18,
49.10
};
float rate;
if(units <= 100)
rate = rates[0];
else if(units <= 200)
rate = rates[1];
else if(units <= 300)
rate = rates[2];
else if(units <= 400)
rate = rates[3];
else if(units <= 500)
rate = rates[4];
else if(units <= 600)
rate = rates[5];
else if(units <= 700)
rate = rates[6];
else
rate = rates[7];
return units * rate;
}
float calculateGST(float amount)
{
return amount * 0.18;
}
float calculateIncomeTax(float amount)
{
if(customerType == 1)
return amount * 0.10;
else
return amount * 0.15;
}
float calculateDuty(float amount)
{
return amount * 0.015;
}
float calculateFixedCharges(int units)
{
if(units <= 300)
return 0;
else if(units <= 400)
return 200;
else if(units <= 500)
return 400;
else if(units <= 600)
return 600;
else if(units <= 700)
return 800;
else
return 1000;
}
float calculateNewConnectionCharges()
{
float meterCost = 15000;
float cableCost = 5000;
float securityCost = 10000;
float additionalCharges;
if(customerType == 1)
{
if(meterType == 1)
additionalCharges = 2500;
else
additionalCharges = 5000;
}
else
{
if(meterType == 1)
additionalCharges = 35000;
else
additionalCharges = 70000;
}
return meterCost + cableCost + securityCost + additionalCharges + 250000;
}
void displayBill()
{
int units;
cout << "\nEnter Units Consumed: ";
cin >> units;
float consumptionCharges = calculateBill(units);
float duty = calculateDuty(consumptionCharges);
float fixedCharges = calculateFixedCharges(units);
float meterRent = 250;
float tvFee = 35;
float subtotal = consumptionCharges + duty + fixedCharges + meterRent + tvFee;
float gst = calculateGST(subtotal);
float incomeTax = calculateIncomeTax(subtotal);
float totalBill = subtotal + gst + incomeTax;
cout << "\n ! LESCO ELECTRICITY BILL ! \n";
cout << "Customer Name: " << customerName << endl;
cout << "Customer ID: " << customerID << endl;
if(customerType == 1)
cout << "Customer Type: Household\n";
else
cout << "Customer Type: Commercial\n";
cout << "Units Consumed: " << units << endl;
cout << "\nConsumption Charges: Rs. " << consumptionCharges << endl;
cout << "Electricity Duty: Rs. " << duty << endl;
cout << "Fixed Charges: Rs. " << fixedCharges << endl;
cout << "Meter Rent: Rs. " << meterRent << endl;
cout << "TV Fee: Rs. " << tvFee << endl;
cout << "GST: Rs. " << gst << endl;
cout << "Income Tax: Rs. " << incomeTax << endl;
cout << "\nTotal Payable Bill: Rs. " << totalBill << endl;
}
void displayCustomerDetails()
{
cout << "\n! CUSTOMER DETAILS ! \n";
cout << "Customer Name: " << customerName << endl;
cout << "Customer ID: " << customerID << endl;
if(customerType == 1)
cout << "Customer Type: Household\n";
else
cout << "Customer Type: Commercial\n";
if(meterType == 1)
cout << "Meter: First Meter\n";
else
cout << "Meter: Second Meter\n";
}
Question 2
#include <iostream>
using namespace std;
char customerName[50];
char contactNumber[20];
int orderType;
int persons;
char foodItems[8][30] =
{
"Chicken Burger",
"Zinger Burger",
"Pizza Small",
"Pizza Large",
"Chicken Biryani",
"BBQ Platter",
"Fries",
"Cold Drink"
};
float prices[8] =
{
450,
550,
900,
1800,
350,
1200,
250,
120
};
float foodBill = 0;
void registerCustomer();
void displayFoodMenu();
void placeOrder();
float calculateFoodBill();
float calculateServiceCharges(float bill);
float calculateGST(float bill);
float calculateDiscount(float bill);
void displayFinalBill();
void displayCustomerDetails();
int main()
{
registerCustomer();
int choice;
do
{
cout << "\n===== MAINMENU =====\n";
cout << "1. View Food Menu\n";
cout << "2. Place Order\n";
cout << "3. Calculate Bill\n";
cout << "4. View Customer Details\n";
cout << "5. Exit\n";
cout << "Enter Choice: ";
cin >> choice;
if(choice == 1)
{
displayFoodMenu();
}
else if(choice == 2)
{
placeOrder();
}
else if(choice == 3)
{
displayFinalBill();
}
else if(choice == 4)
{
displayCustomerDetails();
}
else if(choice == 5)
{
cout << "\nProgram Ended.\n";
}
else
{
cout << "\nInvalid Choice.\n";
}
} while(choice != 5);
return 0;
}
void registerCustomer()
{
cout << "Enter Customer Name: ";
cin >> customerName;
cout << "Enter Contact Number: ";
cin >> contactNumber;
cout << "\nOrder Type\n";
cout << "1. Dine In\n";
cout << "2. Takeaway\n";
cin >> orderType;
cout << "Enter Number Of Persons: ";
cin >> persons;
}
void displayFoodMenu()
{
cout << "\n===== FOOD MENU =====\n";
for(int i = 0; i < 8; i++)
{
cout << i + 1 << ". "
<< foodItems[i]
<< " - Rs. "
<< prices[i]
<< endl;
}
}
void placeOrder()
{
int itemNo;
int quantity;
char more;
do
{
displayFoodMenu();
cout << "\nEnter Item Number: ";
cin >> itemNo;
cout << "Enter Quantity: ";
cin >> quantity;
if(itemNo >= 1 && itemNo <= 8)
{
foodBill = foodBill + (prices[itemNo - 1] * quantity);
}
else
{
cout << "Invalid Item Number\n";
}
cout << "Add More Items? (y/n): ";
cin >> more;
} while(more == 'y' || more == 'Y');
}
float calculateFoodBill()
{
return foodBill;
}
float calculateServiceCharges(float bill)
{
if(orderType == 1)
return bill * 0.10;
else
return bill * 0.05;
}
float calculateGST(float bill)
{
return bill * 0.16;
}
float calculateDiscount(float bill)
{
if(bill >= 3000 && bill <= 5000)
return bill * 0.05;
else if(bill >= 5001 && bill <= 10000)
return bill * 0.10;
else if(bill > 10000)
return bill * 0.15;
else
return 0;
}
void displayFinalBill()
{
float bill = calculateFoodBill();
float serviceCharges =
calculateServiceCharges(bill);
float gst =
calculateGST(bill);
float discount =
calculateDiscount(bill);
float total =
bill +
serviceCharges +
gst -
discount;
cout << "\n========== RESTAURANT BILL ==========\n";
cout << "Customer Name: "
<< customerName << endl;
if(orderType == 1)
cout << "Order Type: Dine In\n";
else
cout << "Order Type: Takeaway\n";
cout << "Number Of Persons: "
<< persons << endl;
cout << "\nFood Bill: Rs. "
<< bill << endl;
cout << "Service Charges: Rs. "
<< serviceCharges << endl;
cout << "GST: Rs. "
<< gst << endl;
cout << "Discount: Rs. "
<< discount << endl;
if(total > 5000)
{
cout << "Free Delivery Added\n";
}
cout << "-----------------------------\n";
cout << "Total Payable Amount: Rs. "
<< total << endl;
cout << "Enjoy Your Meal :)\n";
cout << "====================================\n";
}
void displayCustomerDetails()
{
cout << "\n===== CUSTOMER DETAILS =====\n";
cout << "Customer Name: "
<< customerName << endl;
cout << "Contact Number: "
<< contactNumber << endl;
cout << "Number Of Persons: "
<< persons << endl;
if(orderType == 1)
cout << "Order Type: Dine In\n";
else
cout << "Order Type: Takeaway\n";
}
Question 3
#include <iostream>
using namespace std;
char customerName[50];
char customerID[20];
int customerType;
int paymentMethod;
char items[8][30] =
{
"Rice 1 KG",
"Sugar 1 KG",
"Cooking Oil 1 Litre",
"Milk Pack",
"Tea Pack",
"Flour 5 KG",
"Eggs Dozen",
"Detergent"
};
float prices[8] =
{
350,
180,
580,
220,
450,
950,
320,
600
};
float grossBill = 0;
float salesTax = 0;
void registerCustomer();
void displayGroceryList();
void addItemsToCart();
float calculateGrossBill();
float calculateSalesTax();
float calculateMembershipDiscount(float bill);
float calculateBillDiscount(float bill);
float calculateCardCharges(float bill);
int calculateLoyaltyPoints(float bill);
void redeemLoyaltyPoints(float &totalBill);
void displayFinalBill();
void displayCustomerDetails();
int main()
{
registerCustomer();
int choice;
do
{
cout << "\n===== MAIN MENU =====\n";
cout << "1. View Grocery Items\n";
cout << "2. Add Items To Cart\n";
cout << "3. Calculate Bill\n";
cout << "4. View Customer Details\n";
cout << "5. Exit\n";
cout << "Enter Choice: ";
cin >> choice;
if(choice == 1)
{
displayGroceryList();
}
else if(choice == 2)
{
addItemsToCart();
}
else if(choice == 3)
{
displayFinalBill();
}
else if(choice == 4)
{
displayCustomerDetails();
}
else if(choice == 5)
{
cout << "\nProgram Ended.\n";
}
else
{
cout << "\nInvalid Choice.\n";
}
} while(choice != 5);
return 0;
}
void registerCustomer()
{
cout << "Enter Customer Name: ";
cin >> customerName;
cout << "Enter Customer ID: ";
cin >> customerID;
cout << "\nCustomer Type\n";
cout << "1. Regular Customer\n";
cout << "2. Member Customer\n";
cin >> customerType;
cout << "\nPayment Method\n";
cout << "1. Cash\n";
cout << "2. Card\n";
cin >> paymentMethod;
}
void displayGroceryList()
{
cout << "\n===== GROCERY ITEMS =====\n";
for(int i = 0; i < 8; i++)
{
cout << i + 1 << ". "
<< items[i]
<< " - Rs. "
<< prices[i]
<< endl;
}
}
void addItemsToCart()
{
int itemNo;
int quantity;
char more;
do
{
displayGroceryList();
cout << "\nEnter Item Number: ";
cin >> itemNo;
cout << "Enter Quantity: ";
cin >> quantity;
if(itemNo >= 1 && itemNo <= 8)
{
grossBill = grossBill + (prices[itemNo - 1] * quantity);
if(itemNo >= 1 && itemNo <= 7)
{
salesTax = salesTax +
((prices[itemNo - 1] * quantity) * 0.05);
}
else
{
salesTax = salesTax +
((prices[itemNo - 1] * quantity) * 0.10);
}
}
else
{
cout << "Invalid Item Number\n";
}
cout << "Add More Items? (y/n): ";
cin >> more;
} while(more == 'y' || more == 'Y');
}
float calculateGrossBill()
{
return grossBill;
}
float calculateSalesTax()
{
return salesTax;
}
float calculateMembershipDiscount(float bill)
{
if(customerType == 2)
return bill * 0.07;
else
return 0;
}
float calculateBillDiscount(float bill)
{
if(bill >= 5000 && bill <= 10000)
return bill * 0.05;
else if(bill > 10000)
return bill * 0.10;
else
return 0;
}
float calculateCardCharges(float bill)
{
if(paymentMethod == 2)
return bill * 0.02;
else
return 0;
}
int calculateLoyaltyPoints(float bill)
{
return bill / 100;
}
void redeemLoyaltyPoints(float &totalBill)
{
int existingPoints;
int currentPoints;
int totalPoints;
int choice;
currentPoints = calculateLoyaltyPoints(totalBill);
cout << "Generated Loyalty Points: "
<< currentPoints << endl;
cout << "Enter Existing Loyalty Points: ";
cin >> existingPoints;
totalPoints = currentPoints + existingPoints;
cout << "Loyalty Points After Purchase: "
<< totalPoints << endl;
cout << "Press 1 To Redeem Loyalty Points\n";
cout << "Press 2 To Continue\n";
cin >> choice;
if(choice == 1)
{
totalBill = totalBill - totalPoints;
cout << "Loyalty Points Redeemed Successfully.\n";
}
}
void displayFinalBill()
{
float bill = calculateGrossBill();
float tax = calculateSalesTax();
float memberDiscount =
calculateMembershipDiscount(bill);
float billDiscount =
calculateBillDiscount(bill);
float cardCharges =
calculateCardCharges(bill);
float total =
bill +
tax +
cardCharges -
memberDiscount -
billDiscount;
cout << "\n========== GROCERY MART BILL ==========\n";
cout << "Customer Name: "
<< customerName << endl;
if(customerType == 1)
cout << "Customer Type: Regular Customer\n";
else
cout << "Customer Type: Member Customer\n";
if(paymentMethod == 1)
cout << "Payment Method: Cash\n";
else
cout << "Payment Method: Card\n";
cout << "\nGross Bill: Rs. "
<< bill << endl;
cout << "Sales Tax: Rs. "
<< tax << endl;
cout << "Membership Discount: Rs. "
<< memberDiscount << endl;
cout << "Bill Discount: Rs. "
<< billDiscount << endl;
cout << "Card Charges: Rs. "
<< cardCharges << endl;
redeemLoyaltyPoints(total);
cout << "---------------------------------\n";
cout << "Total Payable Amount: Rs. "
<< total << endl;
cout << "Thank You For Shopping :)\n";
cout << "=================================\n";
}
void displayCustomerDetails()
{
cout << "\n===== CUSTOMER DETAILS =====\n";
cout << "Customer Name: "
<< customerName << endl;
cout << "Customer ID: "
<< customerID << endl;
if(customerType == 1)
cout << "Customer Type: Regular Customer\n";
else
cout << "Customer Type: Member Customer\n";
if(paymentMethod == 1)
cout << "Payment Method: Cash\n";
else
cout << "Payment Method: Card\n";
}
Question 5
#include <iostream>
using namespace std;
char clientName[50];
char businessName[50];
int businessType;
int campaignDuration;
char platforms[3][20] =
{
"Instagram",
"Facebook",
"LinkedIn"
};
float platformCharges[3] =
{
15000,
12000,
20000
};
int selectedPlatform = 0;
int staticPosts;
int reelPosts;
int carouselPosts;
float adBudget = 0;
void registerClient();
void displayPlatforms();
void selectPlatform();
float calculatePostDesignCost();
float calculateAdHandlingFee();
float calculateExtraDurationCharges();
float calculateGST(float total);
float calculateDiscount(float total);
void displayFinalCampaignBill();
void displayClientDetails();
int main()
{
registerClient();
int choice;
do
{
cout << "\n===== MAIN MENU =====\n";
cout << "1. View Platforms\n";
cout << "2. Select Campaign Platform\n";
cout << "3. Calculate Campaign Cost\n";
cout << "4. View Client Details\n";
cout << "5. Exit\n";
cout << "Enter Choice: ";
cin >> choice;
// Handle user choices
if(choice == 1)
{
displayPlatforms();
}
else if(choice == 2)
{
selectPlatform();
}
else if(choice == 3)
{
displayFinalCampaignBill();
}
else if(choice == 4)
{
displayClientDetails();
}
else if(choice == 5)
{
cout << "\nProgram Ended.\n";
}
else
{
cout << "\nInvalid Choice.\n";
}
} while(choice != 5);
return 0;
}
void registerClient()
{
cout << "Enter Client Name: ";
cin >> clientName;
cout << "Enter Business Name: ";
cin >> businessName;
cout << "\nBusiness Type\n";
cout << "1. Small Business\n";
cout << "2. Medium Business\n";
cout << "3. Corporate Business\n";
cin >> businessType;
cout << "Enter Campaign Duration (Days): ";
cin >> campaignDuration;
}
void displayPlatforms()
{
cout << "\n===== SOCIAL MEDIA PLATFORMS =====\n";
for(int i = 0; i < 3; i++)
{
cout << i + 1 << ". "
<< platforms[i]
<< " - Rs. "
<< platformCharges[i]
<< endl;
}
}
void selectPlatform()
{
displayPlatforms();
cout << "\nSelect Platform Number: ";
cin >> selectedPlatform;
if(selectedPlatform < 1 || selectedPlatform > 3)
{
cout << "Invalid Platform Selection\n";
selectedPlatform = 0;
return;
}
cout << "Enter Number Of Static Posts: ";
cin >> staticPosts;
cout << "Enter Number Of Reel/Video Posts: ";
cin >> reelPosts;
cout << "Enter Number Of Carousel Posts: ";
cin >> carouselPosts;
cout << "Enter Advertisement Budget: ";
cin >> adBudget;
}
float calculatePostDesignCost()
{
return (staticPosts * 1000) +
(reelPosts * 2500) +
(carouselPosts * 1800);
}
float calculateAdHandlingFee()
{
if(adBudget < 50000)
return adBudget * 0.05;
else if(adBudget <= 100000)
return adBudget * 0.08;
else
return adBudget * 0.10;
}
float calculateExtraDurationCharges()
{
if(campaignDuration > 30)
return (campaignDuration - 30) * 500;
else
return 0;
}
float calculateGST(float total)
{
return total * 0.16;
}
float calculateDiscount(float total)
{
if(businessType == 1)
return total * 0.05;
else if(businessType == 2)
return total * 0.08;
else
return total * 0.10;
}
void displayFinalCampaignBill()
{
if(selectedPlatform == 0)
{
cout << "\nPlease Select A Platform First.\n";
return;
}
float managementCharges =
platformCharges[selectedPlatform - 1];
float postDesignCost =
calculatePostDesignCost();
float handlingFee =
calculateAdHandlingFee();
float extraCharges =
calculateExtraDurationCharges();
float subtotal =
managementCharges +
postDesignCost +
adBudget +
handlingFee +
extraCharges;
float gst =
calculateGST(subtotal);
float discount =
calculateDiscount(subtotal);
// Calculate final cost
float finalCost =
subtotal +
gst -
discount;
// Display the bill details
cout << "\n========== SOCIAL MEDIA CAMPAIGN BILL ==========\n";
cout << "Client Name: "
<< clientName << endl;
cout << "Business Name: "
<< businessName << endl;
// Display business type textually
if(businessType == 1)
cout << "Business Type: Small Business\n";
else if(businessType == 2)
cout << "Business Type: Medium Business\n";
else
cout << "Business Type: Corporate Business\n";
cout << "Selected Platform: "
<< platforms[selectedPlatform - 1]
<< endl;
cout << "Campaign Duration: "
<< campaignDuration
<< " Days\n";
cout << "\nPlatform Management Charges: Rs. "
<< managementCharges << endl;
cout << "Post Design Cost: Rs. "
<< postDesignCost << endl;
cout << "Ad Budget: Rs. "
<< adBudget << endl;
cout << "Ad Handling Fee: Rs. "
<< handlingFee << endl;
cout << "Extra Duration Charges: Rs. "
<< extraCharges << endl;
cout << "GST: Rs. "
<< gst << endl;
cout << "Discount: Rs. "
<< discount << endl;
cout << "------------------------------------------------\n";
cout << "Final Campaign Cost: Rs. "
<< finalCost << endl;
cout << "================================================\n";
}
void displayClientDetails()
{
cout << "\n===== CLIENT DETAILS =====\n";
cout << "Client Name: "
<< clientName << endl;
cout << "Business Name: "
<< businessName << endl;
cout << "Campaign Duration: "
<< campaignDuration
<< " Days\n";
if(businessType == 1)
cout << "Business Type: Small Business\n";
else if(businessType == 2)
cout << "Business Type: Medium Business\n";
else
cout << "Business Type: Corporate Business\n";
if(selectedPlatform >= 1 && selectedPlatform <= 3)
{
cout << "Selected Platform: "
<< platforms[selectedPlatform - 1]
<< endl;
}
else
{
cout << "Selected Platform: Not Selected Yet\n";
}
}