0% found this document useful (0 votes)
1 views4 pages

Programming Assignment Menu

This document contains a C++ program that prompts the user for their roll number and extracts a numeric portion to determine quantities of food items. It calculates subtotals for each item based on predefined prices and applies a discount if the total exceeds a certain amount. Finally, it displays the total, discount, and payable amount to the user.

Uploaded by

samerhussain093
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views4 pages

Programming Assignment Menu

This document contains a C++ program that prompts the user for their roll number and extracts a numeric portion to determine quantities of food items. It calculates subtotals for each item based on predefined prices and applies a discount if the total exceeds a certain amount. Finally, it displays the total, discount, and payable amount to the user.

Uploaded by

samerhussain093
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Subject : Programming Fundamentals

Assigned by : Ma’am Haiqa Nayab


Submitted by : Syed Samar Hussain
Department : BSCS-1
Date : 15-05-2025
Code:
#include <iostream>
#include <string>

#include <iomanip>

using namespace std;

int main() {
string name = "Syed Samar Hussain";

string rollNo = "H-BSCS2259045";

cout << "Name: " << name << endl;

cout << "Roll No: " << rollNo << endl << endl;

string numericRoll;

cout << "Enter the numeric part of your Roll Number (e.g., 2259024): ";
cin >> numericRoll;

if (numericRoll.length() != 7) {

cout << "Invalid input! Please enter exactly 7 digits." << endl;
return 1;

string extracted = numericRoll.substr(1, 5);

cout << "Extracting 5 digits: " << extracted << endl << endl;

int quantities[5];
for (int i = 0; i < 5; i++) {
quantities[i] = extracted[i] - '0';

if (i != 4 && quantities[i] > 3) {


quantities[i] = 3;

}
}

string items[5] = {"Biriyani", "Juice", "Roll", "Mutton Karhai", "Kandhari Naan"};

int prices[5] = {350, 150, 120, 1700, 50};

int subtotals[5];

int total = 0;

cout << left << setw(15) << "Item"

<< right << setw(10) << "Quantity"

<< setw(15) << "Unit Price"

<< setw(15) << "Subtotal" << endl;

cout << string(55, '-') << endl;

for (int i = 0; i < 5; i++) {

subtotals[i] = quantities[i] * prices[i];

total += subtotals[i];
cout << left << setw(15) << items[i]

<< right << setw(10) << quantities[i]


<< setw(15) << prices[i]

<< setw(15) << subtotals[i] << endl;


}
float discount = 0;
if (total >= 5000) {

discount = total * 0.10;


}

float finalAmount = total - discount;

cout << "\n" << string(55, '-') << endl;

cout << left << setw(35) << "Total before discount: Rs." << total << endl;

cout << left << setw(35) << "Discount: Rs." << discount << endl;

cout << left << setw(35) << "Payable amount: Rs." << finalAmount << endl;

return 0;

Output:

You might also like