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 constructor 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 . stream object is here. Claw hammer 547 8.29 Socket set 892 18.45 Screwdriver 345 1.50 use C++ only. Please do 5-7 as parts 1-4 have been answered previously # include # include #include using namespace std; struct Product {    string description; // Product description    int partNum; // Part number    double cost; // Product cost    //1. Add two constructors    Product(){        description ="";        partNum = 0;        cost = 0.0;    }    Product(string desc, int num, double c){        description = desc;        partNum = num;        cost = c;    }    //2. Define a print function as member of the struct that prints an object    void print() const{        cout<<"Description: "<> items[i].partNum;        cout<<"Enter product cost: $"; cin >> items[i].cost;        cin.ignore();    }       Product* pItems = items;    print(pItems); }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 constructor 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 . stream object is here. Claw hammer 547 8.29 Socket set 892 18.45 Screwdriver 345 1.50 use C++ only.

Please do 5-7 as parts 1-4 have been answered previously

# include <iostream>
# include <iomanip>
#include<string>
using namespace std;


struct Product {
   string description; // Product description
   int partNum; // Part number
   double cost; // Product cost
   //1. Add two constructors
   Product(){
       description ="";
       partNum = 0;
       cost = 0.0;
   }
   Product(string desc, int num, double c){
       description = desc;
       partNum = num;
       cost = c;
   }
   //2. Define a print function as member of the struct that prints an object
   void print() const{
       cout<<"Description: "<<description<<endl;
       cout<<"Part Number: "<<partNum<<endl;
       cout<<"Part Cost: $"<<setprecision(2)<<fixed<<showpoint<<cost<<endl;
   }

};

//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.
void print(Product * pItems){
  

cout<<endl<<endl;

 


   for(int i=0; i<5; i++){


       pItems[i].print();
   }
  
}

int main( ) {
  
  
   //3. Declare an array of size 5 with pointers and named it ”items”. Initilize it with user input values.
   Product items[5];

 


  
   for(int i=0; i<5; i++){


       cout<<"Product #"<<i+1<<endl;
       cout<<"Enter product description: "   ; getline(cin, items[i].description,'\n');
       cout<<"Enter part number: "; cin >> items[i].partNum;
       cout<<"Enter product cost: $"; cin >> items[i].cost;
       cin.ignore();
   }
  
   Product* pItems = items;
   print(pItems);

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education