Question

Create an Enum and call it “Item”. Declare 20 values in the Enum and name them...

  1. Create an Enum and call it “Item”. Declare 20 values in the Enum and name them based on your preference. Create a structure called “Order”. Declare an Item and a double for the item price. Create a structure called “Package” where it has an Order pointer, integer for the size, string for the address, package id and bill details. In the main, declare a Package and assign to it more than 3 items. Create a string returning function called “generateBillDetails” that takes a Package as constant reference and return the bill details as string. Don’t create a string variable/object in the main or outside the main to store the returned value. Store the returned string in the Package. Show the bill string on the console..C++

Sample Example:

Package ID    : #4546-786-543-06-5g

Address       : United States, The Crazy State, Porgareta, Senti-Marraia, St. 12, Villa #2

Ordered Items : Car            $2,500.00

                Chair             $60.00

                Door             $100.00

                Computer         $999.50

                Aircraft     $150,000.01

               --------------------------

                Total:       $153,659.51

A picture so it will be more clarified

Package ID    : #4546-786-543-06-5g

Address       : United States, The Crazy State, Porgareta, Senti-Marraia, St. 12, Villa #2

Ordered Items : Car            $2,500.00

                Chair             $60.00

                Door             $100.00

                Computer         $999.50

                Aircraft     $150,000.01

               --------------------------

                Total:       $153,659.51

Language is c++

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

Code:

#include <iostream>
#include <string>

using namespace std;

enum Item
{
   Car,
   Chair,
   Computer,
   Aircraft,
   Door,
   Bag,
   Books,
   Laptop,
   Table,
   Sofa,
   TV,
   Shoes,
   Dress,
   Jeep,
   HeadPhone,
   Mobile,
   Purse,
   Cupboard,
   Cap,
   Hammer
};

string itemarr[] =
{
   "Car",
   "Chair",
   "Computer",
   "Aircraft",
   "Door",
   "Bag",
   "Books",
   "Laptop",
   "Table",
   "Sofa",
   "TV",
   "Shoes",
   "Dress",
   "Jeep",
   "HeadPhone",
   "Mobile",
   "Purse",
   "Cupboard",
   "Cap",
   "Hammer"
};

struct Order
{
   Item item;
   double price;
   Order(int num, double p)
   {
       item = (Item)num;
       price = p;
   }
};

struct Package
{
   Order* orderptr;
   int size;
   string address;
   string packId;
   string billDetails;
};

string generateBillDetails(const Package& pack)
{
   string billDetails;
   billDetails += "Package ID :" + pack.packId + "\n";
   billDetails += "Address : " + pack.address + "\n";
   billDetails += "Ordered Items : ";
   double total = 0.00;
   for (int i = 0; i < pack.size; i++)
   {
       billDetails += itemarr[(int)pack.orderptr[i].item] + " " + to_string(pack.orderptr[i].price) + "\n";
       total += pack.orderptr[i].price;
   }
   billDetails += "---------------------------\n";
   billDetails += "Total : "+to_string(total) + "\n";
   return billDetails;
}
int main()
{
  
   Package pack;
   pack.packId = "#4546-786-543-06-5g";
   pack.address = "United States, The Crazy State, Porgareta, Senti-Marraia, St. 12, Villa #2";
   pack.orderptr = new Order[5]{ {(Item)0,2500.00},{(Item)1,60.00},{(Item)2,100.00},{(Item)3,999.50},{(Item)4,150000.00} };
   pack.size = 5;
   pack.billDetails = generateBillDetails(pack);
   cout << "Bill Details : \n"<<pack.billDetails;
   return 0;
}

OUTPUT:

Microsoft Visual Studio Debug Console Bill Details Package ID #4546-786-543-06-5g Address United States, The Crazy State, Por

Add a comment
Know the answer?
Add Answer to:
Create an Enum and call it “Item”. Declare 20 values in the Enum and name them...
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
  • Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In...

    Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In this project, we combine the concepts of Recursion and Merge Sorting. Please note that the focus of this project is on Merging and don't forget the following constraint: Programming Steps: 1) Create a class called Art that implements Comparable interface. 2) Read part of the file and use Merge Sort to sort the array of Art and then write them to a file. 3)...

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
ADVERTISEMENT