Here's a simple C++ program for a basic tally system:
#include <iostream>
#include <string>
using namespace std;
class Tally {
private:
string itemName;
int quantity;
double price;
public:
Tally(string itemName, int quantity, double price) {
this->itemName = itemName;
this->quantity = quantity;
this->price = price;
}
void display() {
cout << "Item Name: " << itemName << endl;
cout << "Quantity: " << quantity << endl;
cout << "Price: " << price << endl;
cout << "Total: " << quantity * price << endl;
}
};
int main() {
int choice;
string itemName;
int quantity;
double price;
do {
cout << "Tally System" << endl;
cout << "1. Add Item" << endl;
cout << "2. Display Item" << endl;
cout << "3. Exit" << endl;
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
cout << "Enter item name: ";
cin.ignore();
getline(cin, itemName);
cout << "Enter quantity: ";
cin >> quantity;
cout << "Enter price: ";
cin >> price;
Tally item(itemName, quantity, price);
item.display();
break;
case 2:
// Add code to display all items
break;
case 3:
cout << "Exiting program..." << endl;
break;
default:
cout << "Invalid choice. Please try again." << endl;
}
} while (choice != 3);
return 0;
}
This program creates a simple tally system with the following features:
- Adds items with name, quantity, and price
- Displays the item details along with the total price
- Allows users to exit the program
Note that this is a basic implementation and can be extended to include more features
like storing items in a database, calculating totals, and generating reports.
No comments:
Post a Comment