Project · C++ Programming (modern C++ and DSA)
Project: a kirana shop's GST bill
The brief
Write the billing program for a kirana shop in Pune. It reads the items from a file, works out each line, the GST per line and per slab, splits it into CGST and SGST, rounds to the nearest rupee and skips bad lines with a clear reason.
Why it matters
Every shop in India that is registered for GST prints bills like this, and billing software (Tally, Vyapar, Marg and many in-house POS systems) does exactly these steps. Getting the paise right, splitting CGST and SGST and rejecting bad entries is daily work for developers of retail and accounting software.
Skills you practise
- reading structured input with >> and getline
- loops and running totals
- functions
- switch on a rate
- double and fixed output
- rounding with static_cast
- input validation
You need
- g++ 11 or newer (MinGW-w64 via MSYS2 on Windows, build-essential on Ubuntu, Xcode command line tools on macOS, where g++ runs Apple clang)
- A terminal (Git Bash, MSYS2 or PowerShell on Windows)
- items.txt and bad-items.txt saved next to bill.cpp
What you will have at the end
bill.cpp: a kirana GST billing program that reads items from a file, prints line amounts, GST per line and per slab, CGST/SGST, a rounded amount to pay, and skips bad lines with reasons.
How it is marked (rubric, 100 points)
| Correct billEvery check passes: Rs 1275 for items.txt and Rs 417 with three clear skip messages for bad-items.txt. | 40 |
|---|---|
| Functions and structurelineAmount, gstAmount and validLine each do one job; main reads, calls and prints. | 25 |
| Money handled carefullyNo integer-division bugs, GST split rather than doubled, rounding to the nearest rupee. | 20 |
| Clean build and explanationNo warnings with -Wall -Wextra; you can explain CGST/SGST and the round off. | 15 |
0/6 steps done
Step 1 of 6
Read the item list
The program reads items.txt and prints each item's name, quantity and price, then "Items: 6, units: 13".
items.txt starts with the number of items, then one line per item: quantity, price, GST rate (in %) and the name, which may contain spaces. Read the three numbers with >>, then the rest of the line with std::getline after std::ws. Use a for loop for the n items and keep two counters: items and units (the sum of the quantities). Feed the file to the program with < items.txt, so you do not have to type it. The GST rates are example rates for this shop.
int n = 0;
std::cin >> n;
for (int i = 1; i <= n; ++i) {
int qty = 0, rate = 0;
double price = 0;
std::string name;
std::cin >> qty >> price >> rate >> std::ws;
std::getline(std::cin, name);
// ...
}$ g++ -std=c++17 -Wall -Wextra -o bill bill.cpp; ./bill < items.txtYour notes: bill.cpp
Write down each command you ran. It goes into your project summary.