Write a program that reads product Information into an Item structure and calcul
ID: 3820461 • Letter: W
Question
Write a program that reads product Information into an Item structure and calculates inventory Information (See Sample Output below). Each Item should have a name, cost, and a quantity Store the items into an array of Item structure that can hold 3 elements The program should output the total number of inventory items, the total cost of all the items, and the cheapest item. Item data should be stored in a struct variable of the type Item, which has three components: name (string) cost (double) quantity (integer) There are 3 items. Use an array with 3 elements of the data type Item. 1. Read the item information into the structure array from the console. 2. Calculate the total quantity of all 3 items. 3. Calculate the total cost of all 3 items. 4. Find the index of the cheapest item. Sample Output: Product #1 Enter name: Backpack Enter coat: 4 9.99 Enter quantity: 5 Product #2 Enter name: Sneakers Enter cost: 82.99 Enter quantity: 10 Product #3 Enter name: Gatorade Enter cost: 2.50 Enter quantity: 100 Total number of items: 115 Total value of inventory: $1329.85 Cheapest item: Gatorade WRITE your name In a block or inline comment at the top of your program. PRINT and attach a copy of your source code and output to this worksheet. UPLOAD your source code as Iab12.cpp to my website.Explanation / Answer
#include <iostream>
using namespace std;
struct item
{
char name[50];
int quantity;
float price;
} s[10];
int main()
{
int totq,totcost;
cout << "Enter information : " << endl;
// storing information
for(int i = 0; i < 3; ++i)
{
cout << "quantity"<<endl ;
cin>> s[i].quantity ;
cout << "Enter name: "<<endl;
cin >> s[i].name;
cout << "Enter price: "<<endl;
cin >> s[i].price;
cout << endl;
}
cout << "Displaying Information: " << endl;
// Displaying information
for(int i = 0; i < 3; ++i)
{
cout<<"PRODUCT #"<<i+1;
cout << " l quantity: " <<s[i].quantity << endl;
cout << "Name: " << s[i].name << endl;
cout << "price " << s[i].price << endl;
}
totcost = s[0].price+s[1].price+s[2].price;
totq = s[0].quantity+s[1].quantity+s[2].quantity;
cout<<"total cost " <<totcost<<endl;
cout<<"total quantity " <<totq<<endl;
if((s[0].price<s[1].price) && (s[0].price<s[2].price))
{
cout<< "cheapest is " << s[0].name;
}
else
{
if(s[1].price<s[2].price)
cout<<"cheapeast is " << s[1].name;
else
cout<<"cheapest is " << s[2].name;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.