Question

Create a program using C++ for a store. It will be a ledger for daily transactions....

Create a program using C++ for a store. It will be a ledger for daily transactions. It should be able to record the transactions on a date.

The transactions will happen at a given time (hour, minute, second). Also, every transaction must have a unique ID that is a number that is randomly generated by the system. *Note that the transaction has an ID, NOT the items. There will be no more than 10 transactions on a date. Within every transaction an item will be sold. Each item should have a name, a cost price, selling price, and all item’s cost price should be more than the selling price to generate a profit. You must also implement the ability to void (delete) a transaction. If 10 transactions have not occurred, then more transactions should be possible. After each day, a list of transactions will be made. The list should include:

The time (hour, minute, and second) in which the item was sold.

The cost.

The name of the item.

The unique ID for the transaction.

Selling price.

Finally, the profit.

A menu should also be implemented within your program, and should allow you to do the following:

Create a new transaction by giving the hour, minute, and second the transaction was made followed by the details of the specific item.

Void (delete) a transaction by entering the ID of the transaction. *Note: The ID can be obtained by viewing the summary of transactions.

Print the summary of all transactions on that date. It should have the time, ID, name, cost, selling price, profit, the average profit for each individual item, and the total profit for that date. When the ‘Print Summary’ option is chosen, another menu should be shown to decide how the summary should be printed. The user should have the option to sort the summary by name, ID, or by increasing order of profit. For sorting, use either binary or selection sort algorithms.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
#define MAX 10
using namespace std;

// Defines class Item
class Item
{
// Data member to store item information
string name;
double costPrice;
double sellingPrice;
public:
// Default constructor to initialize data member
Item()
{
name = "";
costPrice = 0.0;
sellingPrice = 0.0;
}// End of default constructor

// Parameterized constructor to assign parameter data to data members
Item(string na, double cp, double sp)
{
name = na;
costPrice = cp;
sellingPrice = sp;
}// End of parameterized constructor

// Function to set name
void setName(string na)
{
name = na;
}// End of function

// Function to set cost price
void setCostPrice(double cp)
{
costPrice = cp;
}// End of function

// Function to set selling price
void setSellingPrice(double sp)
{
sellingPrice = sp;
}// End of function

// Function to return name
string getName()
{
return name;
}// End of function

// Function to return cost price
double getCostPrice()
{
return costPrice;
}// End of function

// Function to return selling price
double getSellingPrice()
{
return sellingPrice;
}// End of function

// Function to display item information
void printItem()
{
cout<<"\n Item Name: "<<name<<"\n Cost Price: "
<<costPrice<<"\n Selling Price: "<<sellingPrice<<endl;
}// End of function
};// End of class Item

// Defines class Transaction
class Transaction
{
// Data member to store transaction information
int hour, minute, second;
int transactionID[MAX];
Item *item[MAX];
int index;
public:
// Default constructor to initialize data member
Transaction()
{
hour = minute = second = 0;
transactionID[0] = 100;
index = 0;
}// End of default constructor

// Parameterized constructor to assign parameter data to data members
Transaction(string na, double cp, double sp, int h, int m, int s)
{
hour = h;
minute = m;
second = s;
// Creates a new item using parameterize constructor and assigns it at index position
item[index] = new Item(na, cp, sp);
// Sets the transaction id
transactionID[index] = index + 100;
// Increase the index by one
index++;
}// End of parameterized constructor

// Function to add an item
void addItem()
{
string name = "";
double costPrice = 0.0;
double sellingPrice = 0.0;

// Checks if it is less than 10 transactions
if(index < 10)
{
// Accepts the transaction time
cout<<"\n Enter hour: ";
cin>>hour;
cout<<"\n Enter minute: ";
cin>>minute;
cout<<"\n Enter second: ";
cin>>second;

// Accepts item information
cout<<"\n Enter Item Name: ";
cin>>name;
cout<<"\n Enter Cost Price: ";
cin>>costPrice;
cout<<"\n Enter Selling Price: ";
cin>>sellingPrice;

// Creates a new item using parameterize constructor and assigns it at index position
item[index] = new Item(name, costPrice, sellingPrice);
// Sets the transaction id
transactionID[index] = index + 100;

// Increase the index by one
index++;
cout<<"\n Transaction added successfully.";
}// End of id condition

// Otherwise reached limit transaction
else
cout<<"\n Cannot make more than 10 transaction per day.";
}// End of function

// Function to delete a transaction based on transaction id
void deleteItem()
{
int id;
// Calls the function to display all transactions
PrintTransaction();

// Accepts the transaction id to delete
cout<<"\n Enter the transaction ID to Delete: ";
cin>>id;

// Calculates id index
id = (id - 100);

// Checks if id is grater than or equals to 0 and less then current number of transactions
if(id >= 0 && id < index)
{
// Loops from id to delete to last transaction
for(int c = id; c < index; c++)
{
// Shifts each item to left
item[c] = item[c + 1];
// Shifts each transaction to left
transactionID[c] = transactionID[c + 1];
}// End of for loop
// Decrease the index by one
index--;
cout<<"\n Transaction item deleted successfully.";
}// End of if condition

// Otherwise invalid transaction id
else
cout<<"\n Invalid Transaction ID.";
}// End of function

// Function to displays each transaction information
void PrintTransaction()
{
cout<<"\n ************** Transaction Information **************";
double profit = 0;
// Loops till number of transactions
for(int c = 0; c < index; c++)
{
// Displays transaction id
cout<<"\n\n Transaction ID: "<<transactionID[c]<<endl;
// Displays time
cout<<" "<<hour<<":"<<minute<<":"<<second<<endl;
// Calls the function to display item information
item[c]->printItem();
// Calculates profit or loss
profit = item[c]->getSellingPrice() - item[c]->getCostPrice();

// Checks if profit is 0 then no profit or no loss
if(profit ==0)
cout<<"No Profit No Loss: "<<profit;

// Otherwise if profit is greater than zero display the profit
else if(profit > 0)
cout<<"Profit: "<<profit;
// Otherwise display the loss
else
cout<<"Loss: "<<abs(profit);
}// End of for loop
}// End of function

// Function to display average profit
void printSummary()
{
double profit = 0;
cout<<"\n ************** Transaction Summary **************";
// Calls the function display each transaction
PrintTransaction();

// Loops till number of transactions
for(int c = 0; c < index; c++)
// Calculates total profit
profit += item[c]->getSellingPrice() - item[c]->getCostPrice();
// Calculates and displays average profit
cout<<"\n Average Profit: "<<profit / index;
}// End of function
};// End of class

// Function to display menu, accepts user choice and returns it
int menu()
{
int ch;
// Displays menu
cout<<"\n ************** Transaction MENU **************";
cout<<"\n 1 - Add Transaction.";
cout<<"\n 2 - Delete Transaction.";
cout<<"\n 3 - Print Transaction.";
cout<<"\n 4 - Print Summary.";
cout<<"\n 5 - EXIT.";

// Accepts user choice
cout<<"\n Enter your choice: ";
cin>>ch;

// Returns choice
return ch;
}// End of function

// main function definition
int main()
{
// Creates an object of the class Transaction
Transaction t;

// Loop till user choice is not 5
do
{
// Calls the function to accept user choice
// Calls the appropriate function based on user choice returned
switch(menu())
{
case 1:
t.addItem();
break;
case 2:
t.deleteItem();
break;
case 3:
t.PrintTransaction();
break;
case 4:
t.printSummary();
break;
case 5:
exit(0);
default:
cout<<"\n Invalid Choice!";
}// End of switch - case
}while(1);// End of do - while loop
}// End of main function

Sample Output:

************** Transaction MENU **************
1 - Add Transaction.
2 - Delete Transaction.
3 - Print Transaction.
4 - Print Summary.
5 - EXIT.
Enter your choice: 1

Enter hour: 10

Enter minute: 11

Enter second: 22

Enter Item Name: Lux

Enter Cost Price: 20.32

Enter Selling Price: 22.50

Transaction added successfully.
************** Transaction MENU **************
1 - Add Transaction.
2 - Delete Transaction.
3 - Print Transaction.
4 - Print Summary.
5 - EXIT.
Enter your choice: 1

Enter hour: 12

Enter minute: 22

Enter second: 32

Enter Item Name: Dove

Enter Cost Price: 50.22

Enter Selling Price: 65.22

Transaction added successfully.
************** Transaction MENU **************
1 - Add Transaction.
2 - Delete Transaction.
3 - Print Transaction.
4 - Print Summary.
5 - EXIT.
Enter your choice: 3

************** Transaction Information **************

Transaction ID: 100
12:22:32

Item Name: Lux
Cost Price: 20.32
Selling Price: 22.5
Profit: 2.18

Transaction ID: 101
12:22:32

Item Name: Dove
Cost Price: 50.22
Selling Price: 65.22
Profit: 15
************** Transaction MENU **************
1 - Add Transaction.
2 - Delete Transaction.
3 - Print Transaction.
4 - Print Summary.
5 - EXIT.
Enter your choice: 2

************** Transaction Information **************

Transaction ID: 100
12:22:32

Item Name: Lux
Cost Price: 20.32
Selling Price: 22.5
Profit: 2.18

Transaction ID: 101
12:22:32

Item Name: Dove
Cost Price: 50.22
Selling Price: 65.22
Profit: 15
Enter the transaction ID to Delete: 102

Invalid Transaction ID.
************** Transaction MENU **************
1 - Add Transaction.
2 - Delete Transaction.
3 - Print Transaction.
4 - Print Summary.
5 - EXIT.
Enter your choice: 2

************** Transaction Information **************

Transaction ID: 100
12:22:32

Item Name: Lux
Cost Price: 20.32
Selling Price: 22.5
Profit: 2.18

Transaction ID: 101
12:22:32

Item Name: Dove
Cost Price: 50.22
Selling Price: 65.22
Profit: 15
Enter the transaction ID to Delete: 101

Transaction item deleted successfully.
************** Transaction MENU **************
1 - Add Transaction.
2 - Delete Transaction.
3 - Print Transaction.
4 - Print Summary.
5 - EXIT.
Enter your choice: 3

************** Transaction Information **************

Transaction ID: 100
12:22:32

Item Name: Lux
Cost Price: 20.32
Selling Price: 22.5
Profit: 2.18
************** Transaction MENU **************
1 - Add Transaction.
2 - Delete Transaction.
3 - Print Transaction.
4 - Print Summary.
5 - EXIT.
Enter your choice: 1

Enter hour: 5

Enter minute: 10

Enter second: 20

Enter Item Name: Cinthol

Enter Cost Price: 23.60

Enter Selling Price: 24.23

Transaction added successfully.
************** Transaction MENU **************
1 - Add Transaction.
2 - Delete Transaction.
3 - Print Transaction.
4 - Print Summary.
5 - EXIT.
Enter your choice: 3

************** Transaction Information **************

Transaction ID: 100
5:10:20

Item Name: Lux
Cost Price: 20.32
Selling Price: 22.5
Profit: 2.18

Transaction ID: 101
5:10:20

Item Name: Cinthol
Cost Price: 23.6
Selling Price: 24.23
Profit: 0.63
************** Transaction MENU **************
1 - Add Transaction.
2 - Delete Transaction.
3 - Print Transaction.
4 - Print Summary.
5 - EXIT.
Enter your choice: 4

************** Transaction Summary **************
************** Transaction Information **************

Transaction ID: 100
5:10:20

Item Name: Lux
Cost Price: 20.32
Selling Price: 22.5
Profit: 2.18

Transaction ID: 101
5:10:20

Item Name: Cinthol
Cost Price: 23.6
Selling Price: 24.23
Profit: 0.63
Average Profit: 1.405

Add a comment
Know the answer?
Add Answer to:
Create a program using C++ for a store. It will be a ledger for daily transactions....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE DO NOT COPY AND PASTE FROM A PREVIOUS QUESTION , THIS IS DIFFERENT. PLEASE READ...

    PLEASE DO NOT COPY AND PASTE FROM A PREVIOUS QUESTION , THIS IS DIFFERENT. PLEASE READ STEP 5 CAREFULLY. MUST BE WRITTEN IN C++ You are to implement a program for creating a daily transaction ledger for a shop. For this project, you will need to utilize the concepts ofarrays and object creation that have been discussed in class The list of requirements and constraints for the system are as follows 1. The system must be able to maintain records...

  • THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #inclu...

    THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #include "pch.h" #include #include using namespace std; // Function prototype void displayMessage(void); void totalFees(void); double calculateFees(int); double calculateFees(int bags) {    return bags * 30.0; } void displayMessage(void) {    cout << "This program calculates the total amount of checked bag fees." << endl; } void totalFees() {    double bags = 0;    cout << "Enter the amount of checked bags you have." << endl;    cout <<...

  • C++ program Write a C++ program to manage a hospital system, the system mainly uses file...

    C++ program Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....

  • In C++ write a simple menu program that displays a menu for the user in an...

    In C++ write a simple menu program that displays a menu for the user in an object-oriented technique. The menu should keep showing up until the user chooses to quit. Also, there is a sub-menu inside a menu. The user should get at least a line displayed after he or she chooses that particular option meaning if the user presses 1 for the read actors from the file. The output can look like "reading actors from a file" and then...

  • Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class...

    Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class Delete extends Info { String name; int Id; int del; public Delete() { } public void display() { Scanner key = new Scanner(System.in); System.out.println("Input Customer Name: "); name = key.nextLine(); System.out.println("Enter ID Number: "); Id = key.nextInt(); System.out.println("Would you like to Delete? Enter 1 for yes or 2 for no. "); del = key.nextInt(); if (del == 1) { int flag = 0; //learned...

  • Java 1. Develop a program to emulate a purchase transaction at a retail store. This program...

    Java 1. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual line item of merchandise that a customer is purchasing. The Transaction class will combine several LineItem objects and calculate an overall total price for the line item within the transaction. There will also be two test classes, one for the LineItem class and one for the...

  • You have to write a java solution for a store. Part 1 The solution needs to...

    You have to write a java solution for a store. Part 1 The solution needs to have at least following features: ◦ Item: Name, ID (incremental ID by 1 for each product), Price. ◦ Store Basket: ID (incremental ID by 1 for each basket), Net Amount, Total Amount, VAT, List of items, Date and Time of purchase, Address of the store, name of cashier. ◦ Cashier: Name, Surname, Username and Password (insert from code five fixed cashiers). ◦ Manager: Name,...

  • please write in C++ Write a program that uses a structure to store the following inventory...

    please write in C++ Write a program that uses a structure to store the following inventory data in a file: The data can be either read from a text file or the keyboard Item name (string) Quantity on hand(int) Wholesale cost(double) Retail Cost(double) The program should have a menu that allows the user to perform the following tasks: Add new records to the file Display any record in the file User will provide the name of the item or the...

  • c++ programming : everything is done, except when you enter ("a" ) in "F" option ,...

    c++ programming : everything is done, except when you enter ("a" ) in "F" option , it does not work. here is the program. #include <iostream> #include <string> #include <bits/stdc++.h> #include <iomanip> #include <fstream> using namespace std; #define MAX 1000 class Inventory { private: long itemId; string itemName; int numberOfItems; double buyingPrice; double sellingPrice; double storageFees; public: void setItemId(long id) { itemId = id; } long getItemId() { return itemId; } void setItemName(string name) { itemName = name; } string...

  • 4.18 Ch 7 Program: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping...

    4.18 Ch 7 Program: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (solution from previous lab assignment is provided in Canvas). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by the quantity, price, and subtotal PrintItemDescription() -...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT