Can I get some assistance in coding this in C++ For insurance purposes, you have
ID: 3688154 • Letter: C
Question
Can I get some assistance in coding this in C++
For insurance purposes, you have decided to write a menu driven program to track the items in your house. You have chosen to store the information in an array of structures and display the information in various formats through a menu. The inventory structure should contain the fields and data types listed below. The program should allow for 20 household items. The menu selections should be similar to the ones listed below. Each menu selection should be a separate function. 1. Enter information into the array structure. Keep track of the number of items read and allow for additional items to be entered during the execution of the program. The program should check that entered prices do not exceed $10,000 and that Y or N has been entered as the insured value. 2. Display all of the items entered. The output should be in a report format with headings. Values should be aligned and numeric values should be displayed to 2 decimal places. 3. Display the total quantity of items in your possession. 4. Display the total value of all your assets. The total value of your assets is computed by multiplying each item by the quantity and summing the results. This value should be properly labeled and computed to 2 decimal places. 5. Display only the Insured items. 6. Quit.Explanation / Answer
Here is the code for you:
#include <iostream>
using namespace std;
struct Inventory
{
string description;
int quantity;
float price;
char insured;
};
void addInventory(struct Inventory inv[], int &count)
{
if(count == 20)
cout<<"The array size is full. Cannot add inventory."<<endl;
else
{
cout<<"Enter the item description:";
cin>>inv[count].description;
cout<<"Enter the quantity: ";
cin>>inv[count].quantity;
cout<<"Enter the price of item: ";
cin>>inv[count].price;
while(inv[count].price > 10000)
{
cout<<"Price cannot exceed $10,000."<<endl;
cout<<"Enter the price of item: ";
cin>>inv[count].price;
}
cout<<"Is the item insured? Y/N: ";
cin>>inv[count].insured;
if(inv[count].insured == 'Y' || inv[count].insured == 'y')
inv[count].insured = 'Y';
else
inv[count].insured = 'N';
count++;
}
}
void displayInventories(struct Inventory inv[], int count)
{
for(int i = 0; i < count; i++)
cout<<inv[i].description<<" "<<inv[i].quantity<<" "<<inv[i].price<<" "<<inv[i].insured<<endl;
}
void displayQuantities(struct Inventory inv[], int count)
{
int q = 0;
for(int i = 0; i < count; i++)
q += inv[i].quantity;
cout<<"The total quantity in the inventory is: "<<q<<endl;
}
void displayValues(struct Inventory inv[], int count)
{
double value = 0;
for(int i = 0; i < count; i++)
value += inv[i].quantity * inv[i].price;
cout<<"The total value of the inventory is: "<<value<<endl;
}
void displayInsured(struct Inventory inv[], int count)
{
for(int i = 0; i < count; i++)
if(inv[i].insured == 'Y')
cout<<inv[i].description<<" "<<inv[i].quantity<<" "<<inv[i].price<<" "<<inv[i].insured<<endl;
}
int main()
{
struct Inventory inventory[20]; //The program should allow for 20 household items.
int choice, count = 0;
while(true)
{
cout<<"Inventory Management:"<<endl;
cout<<"1. Add inventory."<<endl;
cout<<"2. Display inventory."<<endl;
cout<<"3. Display quantities."<<endl;
cout<<"4. Display values."<<endl;
cout<<"5. Display insured items."<<endl;
cout<<"6. Quit."<<endl;
cout<<"Enter your choice... ";
cin>>choice;
switch(choice)
{
case 1: addInventory(inventory, count); break;
case 2: displayInventories(inventory, count); break;
case 3: displayQuantities(inventory, count); break;
case 4: displayValues(inventory, count); break;
case 5: displayInsured(inventory, count); break;
case 6: return 0;
default: cout<<"Invalid menu option. Try again."<<endl;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.