Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume that you have the following definition of a struct: struct partsType { St

ID: 3672413 • Letter: A

Question

Assume that you have the following definition of a struct:

struct partsType
{
String partName;
Int partNum;
double price;
int quantitiesInStock;
};

Declare an array, inventory, of 100 components of type partsType.

Now take above struct definition above and:

Write a C++ code to initialize each component of inventory as follows: part name to null string, partNum to -1, price to 0.0 and quantities in quantitiesInStock to 0.

Write a C++ code that uses a loop to output the data stored in inventory. Assume that the variable length indicates the number of elements in inventory.

Note suggest testing your solution and submit outcome.

Assignment Requirements:

Start by analyzing the problem; use an IPO chart and pseudocode (or flowchart) to brainstorm the logic prior to start coding. Using Visual Studio code and test your program according to your pseudocode solution. Once you are satisfied with your program outcome, open a Word document and insert a cover page, include your design IPO chart, pseudocode or flowchart, C++ source code, and print screen shots of the DOS command dialog window showing your test results. Be sure to test the program at least two times to insure the program executes properly.

Insure that your C++ source code is fully documented by including source code comments. Include a “flower box”, i.e.

/* Programmers full name:
Today’s Date:
Lesson number:
Program purpose: */

Assignment must be submitted as a Word document.  

Explanation / Answer

#include <iostream>
#include <string>
struct partsType
{
std::string partName;
int partNum = -1;
double price;
int quantitiesInStock;
};
int main()
{
const size_t N = 100;
partsType inventory[N] = {};
for ( partsType part : inventory )
{
std::cout << "Name: " << part.partName << ", number: " << part.partNum
<< ", price: " << part.price << ", quantity: " << part.quantitiesInStock
<< std::endl;
}
return 0;
}