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

assume you have this codeL class inventory_item { private: string description: f

ID: 3534455 • Letter: A

Question

assume you have this codeL

class inventory_item

{

private: string description:

float price:

public:

inventory_item()

{

description = "";

price = 0;

}

void setDescription (string s)

{

description = s;

}

void setprice (float p)

{

price = p:

}

void show() const

{cout<<description<<""<<price:

}

};

inventory_item*item_ptr;


Write statements that

a. Dynamically allocate an invetory_item object and use item_ptr to point ot it.

b. assign "poppyseed bagels 6-pak" to the objects decription and 2.99 to the objects price.

c. explain what the purpose of the keyword const is after the show() funct.

Explanation / Answer

invetory_item A=new inventory_item();

invetory_item * item_ptr=A;


A.setDescription ("poppyseed bagels 6-pak");

A.void setprice (2.99);


const to a variable/function is useful for storage that can be changed in value but not moved in memory.