Assume the Product structure is declared as follows: struct Product { string description; // Product description int partNum; // Part number double cost; // Product cost }; 1. Add two constructors to the Product structure declaration. The first should be a default constructor that sets the description member to the null string and the partNum and cost members to zero. The second con- structor should have three parameters: a string, an int, and a double. It should copy the values of the arguments into the description, partNum, and cost members. 2. Define a print function as member of the struct that prints an object of this struct in the following format. Description: Claw Hammer Part Number: 547 Part Cost: $8.29 3. Declare an array of size 5 with pointers and named it ”items”. Initilize it with user input values. 4. Write a print function (not as a member of the struct) and pass a pointer to the pointer that points to the array(double pointer) and print all the items of the array.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter9: Records (struct)
Section: Chapter Questions
Problem 1TF: Mark the following statements as true or false. All members of a struct must be of different types....
icon
Related questions
Question

need code in C++

answer all parts

Assume the Product structure is declared as follows:

struct Product
{
string description; // Product description
int partNum; // Part number
double cost; // Product cost
};
1. Add two constructors to the Product structure declaration. The first
should be a default constructor that sets the description member to the

null string and the partNum and cost members to zero. The second con-
structor should have three parameters: a string, an int, and a double. It

should copy the values of the arguments into the description, partNum,
and cost members.
2. Define a print function as member of the struct that prints an object of
this struct in the following format.
Description: Claw Hammer Part
Number: 547
Part Cost: $8.29
3. Declare an array of size 5 with pointers and named it ”items”. Initilize it
with user input values.
4. Write a print function (not as a member of the struct) and pass a pointer
to the pointer that points to the array(double pointer) and print all the
items of the array.
5. Define a max function (not as a member of the struct) that gets an array
of items as an input and returns a pointer to the max element of the array.
6. Declare a 3 by 3 two dimensional array with pointers and overload a output
function to get a stream object and a pointer to a 2D array as arguments
and outputs column descriptions and data members of objects in format of
3*3 table into the given stream. Test your function both with and output
file stream and cout stream.
7. Write a testbench to test your program properly.

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Structure chart
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr