0% found this document useful (0 votes)
101 views5 pages

Cs201 Assignment 1 Solution 2025

The document outlines an assignment for a C++ programming course, requiring students to create a program that calculates a bill based on menu item prices and a user's VU ID. Students must extract specific digits from the VU ID to determine quantities of items ordered and apply a discount if the total exceeds Rs. 5000. The assignment includes detailed instructions on output formatting and calculations, along with a sample output for reference.

Uploaded by

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

Cs201 Assignment 1 Solution 2025

The document outlines an assignment for a C++ programming course, requiring students to create a program that calculates a bill based on menu item prices and a user's VU ID. Students must extract specific digits from the VU ID to determine quantities of items ordered and apply a discount if the total exceeds Rs. 5000. The assignment includes detailed instructions on output formatting and calculations, along with a sample output for reference.

Uploaded by

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

Assignment No.

1 Total Marks: 20

nd
Semester: Spring 2025 Due Date: 2 May, 2025

CS201 – Introduction to Programming Syllabus: Lectures 1 to 8

For Paid Assignment 03234131842

Problem Statement:

Write a C++ program that uses items price from a menu and your VU ID to calculate the total and net bills according to the requirements given below.

Requirement Instructions:

 You are required to Hard-Code your own name and VU ID (e.g., BS123456789) & display it afterwards.

 Now, you have to ask a user to enter the numeric part of VU ID.

 Extract and display 5 digits from the middle of the numeric part asked in the above step:

o Remove 2 digits from the left and 2 from the right of the 9-digit number.

o For example, from 123456789, you will extract 34567.

o 12 from the left and 89 from the right will be removed.

 Each digit of 5 digits extracted in the above step (e.g., 34567) will be used as the quantity for a specific menu item:

o The leftmost is the 1st digit and the rightmost is the 5th digit.

o Digit 1 should be used for the quantity of Burger.

o Digit 2 should be used for the quantity of Pizza.

o Digit 3 should be used for the quantity of Fries.

o Digit 4 should be used for the quantity of Sandwich.

o Digit 5 should be used for the quantity of Cold Drink.

 The price of each menu item should be the same as shown in the sample output screenshot below.

 Multiply each menu item price by its designated quantity to calculate the total bill.

 Display the full billing details for each item including:

o Item name

o Quantity (from digit)

o Unit price

o Subtotal (quantity × price)

o Sample is shown in screenshot

 After processing all 5 items, calculate the total bill.

All Subject Paid Assignment Available 03234131842 Page 1


 If the total bill is greater than or equal to Rs. 5000, apply a 10% discount.

 Display the following at the end:

o Total before discount

o Discount amount

o Final payable amount

o Sample is shown in screenshot

Note: Remember that if you have not used your name and student id in the program your marks will be deducted.

Solution

#include <iostream>

#include <string>

#include <conio.h>

using namespace std;

int main() {

string name = "Ali";

string vu_id = "BC200417617";

cout << "Name: " << name;

cout << "\nVU-ID: " << vu_id;

string numeric_part;

cout << "\n\nEnter numeric part of VU-ID: ";

cin >> numeric_part;

if (numeric_part.length() < 7) {

cout << "\nError: Please enter a valid numeric part with at least 7 digits." << endl;

return 1;

All Subject Paid Assignment Available 03234131842 Page 2


string middle_digits = numeric_part.substr(2, 5);

cout << "\nExtracted Middle Five Digits: " << middle_digits;

const int price_burger = 250;

const int price_pizza = 500;

const int price_fries = 150;

const int price_sandwich = 200;

const int price_cold_drink = 100;

cout << "\n\n=== Welcome to C++ Cafe ===";

cout << "\n------ MENU ------";

cout << "\n1. Burger - Rs. 250";

cout << "\n2. Pizza - Rs. 500";

cout << "\n3. Fries - Rs. 150";

cout << "\n4. Sandwich - Rs. 200";

cout << "\n5. Cold Drink - Rs. 100";

int quantity_burger = middle_digits[0] - '0';

int quantity_pizza = middle_digits[1] - '0';

int quantity_fries = middle_digits[2] - '0';

int quantity_sandwich = middle_digits[3] - '0';

int quantity_cold_drink = middle_digits[4] - '0';

int subtotal_burger = quantity_burger * price_burger;

int subtotal_pizza = quantity_pizza * price_pizza;

int subtotal_fries = quantity_fries * price_fries;

int subtotal_sandwich = quantity_sandwich * price_sandwich;

All Subject Paid Assignment Available 03234131842 Page 3


int subtotal_cold_drink = quantity_cold_drink * price_cold_drink;

cout << "\n\nBurger (" << quantity_burger << " x Rs. " << price_burger << ") = Rs. " << subtotal_burger;

cout << "\nPizza (" << quantity_pizza << " x Rs. " << price_pizza << ") = Rs. " << subtotal_pizza;

cout << "\nFries (" << quantity_fries << " x Rs. " << price_fries << ") = Rs. " << subtotal_fries;

cout << "\nSandwich (" << quantity_sandwich << " x Rs. " << price_sandwich << ") = Rs. " << subtotal_sandwich;

cout << "\nCold Drink (" << quantity_cold_drink << " x Rs. " << price_cold_drink << ") = Rs. " << subtotal_cold_drink;

int total_before_discount = subtotal_burger + subtotal_pizza + subtotal_fries + subtotal_sandwich + subtotal_cold_drink;

float discount = 0.0f;

if (total_before_discount >= 5000) {

discount = total_before_discount * 0.10f;

cout << "\n\nSurprise! You've unlocked a 10% discount!";

float final_amount = total_before_discount - discount;

cout << "\n\n=== Final Bill ====";

cout << "\nTotal before discount: Rs. " << total_before_discount;

cout << "\nDiscount: Rs. " << discount;

cout << "\nNet Payable Amount: Rs. " << final_amount;

cout << "\n\nThank you for visiting C++ Cafe!" << endl;

getch(); // pause the screen (Windows-specific)

return 0;

Sample Output:

All Subject Paid Assignment Available 03234131842 Page 4


For Paid Assignment 03234131842

All Subject Paid Assignment Available 03234131842 Page 5

You might also like