Question

In: Computer Science

A customer can order one or more items in one transaction (طلبية) . Every item has...

A customer can order one or more items in one transaction (طلبية) . Every item has a unique ID, Name, Price, and Description. Given the following item class, assume it is already programmed and ready for use.

Class Item {

public:

Item();

void SetID(int);                       int GetID();

void SetPrice(double);              double GetPrice();       

void SetName(string);              string GeName();       

void SetDesc(string);               string GetDesc();

private:

int id;

String name, description;

double price;

};

Define a new class called Transaction that represents a customer order, where it contains 1 or more items. The Transaction class should have:                                                                                             (4 Points)

  • Items: a dynamic array to track current items in transaction
  • Qtys: a dynamic array of type integer to track the quantities of each item in the transaction
  • numItems: Integer counter of current items
  • Size: Integer variable to track the size of items array, and quantities array.
  • ID: and integer which should be fixed and set based on the number of transactions, starting from 1.
  • Count: an integer which is used to track the number of transactions starting from 1 and increased with each transaction object created.

Define the following member functions:

1) Default constructor that initializes the dynamic arrays to null and the numItems and size to zero, also it sets the id and increase count.                              (4 Points)

2) Constructor that receives array of items, array of quantities of items, and the number of items. Then initializes the Items, Qtys, and numItems accordingly(وفقا لذلك). It should set the transaction to contain these items and quantities. And it sets the id and increase count.                                           (8 Points)

      NOTE: you should reserve (يحجز) an array size that equals the number of items + 5.

3) int Exists(int ItemID), checks if the item exists then returns its index, otherwise returns -1. (5 points)

4) void resize(), which increases the size of items and QTY arrays with 5 more slots.                (5 points)

5) void AddItem(Item i, int Qty), which should add item i to the current items. If the item is already exists only the quantity of this item is increased by Qty. Also, if the current array is full, a new bigger array (with 5 more locations) should be created where all old items are put in the new array. (8 Points)

6) void RemoveItem( int itemID), which should remove item with id itemID, and then shifts all items after it. For example Items: 1,3,5,6,7, remove 3 should result of 1,5,6,7.                                (6 Points)

7) double TotalValue() which returns the total value a customer should pay for the current transaction                                                                                                            (5 Points)

8) Destructor, should decrease count, and free allocated memory.                       (2 Points)

9) int getID(), which returns the transaction’s ID.                                              (2 Points)

10) bool hasMoreItems(Transaction &t2) which returns true if original transaction has more item than Transaction t2. Otherwise, return false.                                    (8 Points)

11) int similarItems(Transaction &t2), which compares original transaction, with transaction t2, and return number of similar items.                                          (8 Points)

12) Write a program that uses classes Transaction and Item, , which does the following:

  1. Define an array of five transactions, called myTransactions.                           (5 Points)
  2. For each transaction in myTransactions array, ask the user how many items it contains, then build an array of items and quantities based on user input, fill it inside the transaction.                                                                                               (12 Points)
  3. Print out the total value of each transaction in myTransactions array.              (8 Points)
  4. Print out the information of the transaction with the highest value in myTransactionsarray.                                                                                                              (10 Points)

Solutions

Expert Solution

Item.hpp

#include <string>
 
 
 
class Item {
 
    public:
 
    Item();
 
    void SetID(int);
    int GetID();
 
    void SetPrice(double);
    double GetPrice();
 
    void SetName( std::string);
     std::string GeName();
 
    void SetDesc( std::string);
     std::string GetDesc();
 
    private:
 
    int id;
 
    std::string name, description;
 
    double price;
 
};

Transaction.hpp

#include <string>
#include <vector>
#include <item.hpp>
 
class Transaction{
public:
    Transaction();
   ~ Transaction();
 
    Transaction(std::vector<Item> items, std::vector<int> qtys,int numItems);
 
    std::vector<Item> items;
    std::vector<int> qtys;
    int numItems;
    int size;
    static int count;
 
    int Exists(int itemID);
    void resize();
    void AddItem(Item i, int Qty);
    void RemoveItem( int itemID);
    double TotalValue();
    int getID();
    bool hasMoreItems(Transaction &t2);
    int similarItems(Transaction &t2);
    int id;
};

Transaction.cpp

#include "Transaction.hpp"
 
Transaction::Transaction()
{
    numItems = 0;
    size = 0;
    count = count+1;
    id = count;
}
 
Transaction::~Transaction()
{
count = count-1;
}
 
Transaction::Transaction( std::vector<Item> items, std::vector<int> qtys,int numItems){
    items = this->items;
    qtys = this->qtys;
    numItems = this->numItems;
    count = count+1;
    id = count;
}
int Transaction::Exists(int itemId){
    for(int i=0;i<items.size();i++){
        if(items.at(i).GetID() ==itemId)
            return i;
    }
    return -1;
}
void Transaction::resize(){
    items.resize(items.size()+5);
    qtys.resize(qtys.size()+5);
}
 
void Transaction::AddItem(Item item,int qty){
    items.push_back(item);
    qtys.push_back(qty);
}
 
void Transaction::RemoveItem(int itemId){
    for(int i=0;i<items.size();i++){
        if(items.at(i).GetID() ==itemId){
            //remove
        }
    }
}
 
double Transaction::TotalValue(){
    double totalitem = 0;
    for(int i=0;i<items.size();i++){
        totalitem = totalitem+ qtys.at(i)*items.at(i).GetPrice();
    }
    return  totalitem;
}
 
int Transaction::getID(){
    return  id;
}
 
bool Transaction::hasMoreItems(Transaction &t2){
    if(items.size()<t2.items.size()){
        return  true;
    }
    return  false;
 
}
 
int Transaction::similarItems(Transaction &t2){
    int similaritems = 0;
    for(int i=0;i<items.size();i++){
        for(int j=0;j<t2.items.size();j++){
        if(items.at(i).GetID() ==t2.items.at(j).GetID()){
            similaritems = similaritems+1;
        }
        }
    }
    return  similaritems;
}

main.cpp

#include <Transaction.hpp>
#include <Item.hpp>
#include<stdio.h>
#include<vector>

int main (){

 std::vector<Transaction>myTransctions;
 
    for(int i=0;i<5;i++){
        int j;
       cout << "Enter the items in transaction - "<< i;
       cin >> j;
       for(int k=0;k<j;k++){
           std::string name;
           int id;
           int qty;
           double price;
           cout << "Enter item name for - "<< k;
           cin << name;
           cout << "Enter item id for - "<< k;
           cin << id;
           cout << "Enter quantity for item - "<< k;
           cin << qty;
           cout << "Enter price for item - "<< k;
           cin << price;
           Item item;
           item.SetID(id);
           item.SetName(name);
           item.SetPrice(price);
           Transaction  transaction;
           transaction.items.push_back(item);
           transaction.qtys.push_back(qty);
           myTransctions.push_back(transaction);
       }
 
    }
    double totlavalue;
    for(int i=0;i<5;i++){
        totlavalue= totlavalue + myTransctions.at(i).TotalValue();
    }
    cout<<"Total value --" << totlavalue;
 
    Transaction highestvalue = myTransctions.at(0);
    for(int i=0;i<5;i++){
        if(myTransctions.at(i).TotalValue()>highestvalue.TotalValue()){
            highestvalue = myTransctions.at(i);
        }
    }
 
 
     cout<< "Details about highest transaction";
     cout << "Number of items = "<< highestvalue.items.size();
      cout << "Transaction Id = "<< highestvalue.id;

}



                    

Related Solutions

Wholesalers often provide reduced prices on goods if the customer purchases more than one item. Your...
Wholesalers often provide reduced prices on goods if the customer purchases more than one item. Your company wants to create a program that customers can use to determine the cost of their purchase. Quantity 0 ≤ q < 10 10 ≤ q < 100 100 ≤ q < 1000 1000 ≤ q Price $15.00 per unit $10.00 per unit + $50.00 $7.50 per unit + $300.00 $2.00 per unit + $5,080.00 Your program should prompt the user for the number...
Choose one of the items listed below (you may not choose an item someone else has...
Choose one of the items listed below (you may not choose an item someone else has responded to unless all of them have been addressed.) Include the number of the item in the subject line of your posting. Indicate whether there are any Internal Control violations in the item. If there are, make a suggestion of how to improve the process. Select Company is a retail company that sells plumbing supplies. It has both cash sales and sales on account....
a) Which of the items listed below represent financial assets? (It can be more than one...
a) Which of the items listed below represent financial assets? (It can be more than one or none.) ⦁   Mickey Mouse brand name ⦁   Disney common stock ⦁   Disney bonds ⦁   Florida state bonds ⦁   Apartment building ⦁   Shares in a Real Estate Investment Trust (REIT) that owns apartment buildings ⦁   REIT exchange-traded fund shares ⦁   PhD degree in economics b) Empty Seats (EMS), a global airline headquartered in Chicago, issued a bond a year ago. ⦁   What will happen...
A customer has purchased 15 items in a department store.
A customer has purchased 15 items in a department store. Write a code segment to read the unit price and the quantity of each these 15 items and to compute and print its price (which is the unit price times the quantity). Also compute and print average price of the 15 items.
Question 57 A Customer must exist before an Order Header for that Customer can be added....
Question 57 A Customer must exist before an Order Header for that Customer can be added. True False Question 58 Each Supplier must supply at least one Part. True False Question 59 Every Order Header must have at least one Order Line. True False Question 60 Every Order Line must contain one and only one Product. True False
Provide an alternative product or service to the items your classmate purchased. For one item, it...
Provide an alternative product or service to the items your classmate purchased. For one item, it needs to be a complement and the other a substitute. State what that item is, and whether it is a complement or a substitute good. (e.g. Honda – I bought a Toyota, it is a substitute. Prescription drugs - complement). Also, give an estimate of the cross-price elasticity coefficient for your items (e.g. > 0, 0, or <0)
Write a pseudocode for the following code: /*every item has a name and a cost */...
Write a pseudocode for the following code: /*every item has a name and a cost */ public class Item {    private String name;    private double cost;    public Item(String name, double cost) {        this.name = name;        this.cost = cost;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public double getCost() {        return cost;...
Determining Amounts for Items Omitted from Income Statement One item is omitted in each of the...
Determining Amounts for Items Omitted from Income Statement One item is omitted in each of the following four lists of income statement data. Determine the amounts of the missing items. Chase Company Jessup Inc. Osterman Company      Snyder Co. Sales $463,200 $ $1,077,000 $ Cost of goods sold $ $408,400 $ $411,800 Gross profit $87,800 $290,600 $295,400 $266,400
Briefly describe the following items: 1.Transaction exposure, economic exposure and translation exposure. Which exposure is more...
Briefly describe the following items: 1.Transaction exposure, economic exposure and translation exposure. Which exposure is more relevant to multinational corporation? Please explain 2.Purchasing power parity and Interest rate parity, and their linkage.
The Fashion Store sells fashion items. The store has to order these items many months in...
The Fashion Store sells fashion items. The store has to order these items many months in advance of the fashion season in order to get a good price on the items. Each unit costs Fashion $100. These units are sold to customers at a price of $250 per unit. Items not sold during the season can be sold to the outlet store at $80 per unit. If the store runs out of an item during the season it has to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT