Need help adding a vector, pointer and a copy constructor. This is my assignment
ID: 657236 • Letter: N
Question
Need help adding a vector, pointer and a copy constructor.
This is my assignment:
The CSC 161 client would like to have a program for a generic rental/retail store, and a sample application which utilizes that library and demonstrates the functionality for a store renting a selected mix of two types of items (books and videos, cars and trucks, skis and snowboards, etc.) The application should have a menu of options to:
rent/sell an item
return an item
search for a specific item (using the UPC code)
display the inventory sorted by item type, detailing its attributes
This is my code
// program for Inventory of mix types
#include
using namespace std;
struct item //mix types of structure
{
int upcCode;
char pname[20];
int qty;
float price;
int status;
};
void inputItems(struct item Array[], int size) //reading n no.of array of products
{
for (int i = 0; i
{
cout << "Enter unique product code :";
cin >> Array[i].upcCode;
cout << "Enter product name :";
cin >> Array[i].pname;
cout << "Enter product quantity :";
cin >> Array[i].qty;
cout << "Enter product price :";
cin >> Array[i].price;
Array[i].status = 0; //Rental or status of items is 0 initially
}
}
void rentsellItem(struct item Array[], int upcCode, int size) //Renting of an item
{
int i;
for (i = 0; i
{
if (Array[i].upcCode == upcCode) //if item found
{
Array[i].status = 1;
cout << " Rental/Selling is done for product code : " << upcCode;
break;
}
}
if (Array[i].upcCode != upcCode) //if item not found
cout << " Sorry no such product";
}
void returnItem(struct item Array[], int upcCode, int size) //returning status of item
{
int i;
for (i = 0; i
{
if (Array[i].upcCode == upcCode)
{
Array[i].status = 0;
cout << " Return of item is done for product code : " << upcCode;
break;
}
}
if (Array[i].upcCode != upcCode) //if not found
cout << " Sorry no such product";
}
void searchItem(struct item Array[], int upcCode, int size) //Searcing function
{
int i;
for (i = 0; i
{
if (Array[i].upcCode == upcCode)
{
cout << " Product code :" << Array[i].upcCode;
cout << " product name : " << Array[i].pname;
cout << " product quantity :" << Array[i].qty;
cout << " product price : " << Array[i].price;
cout << " product status : " << Array[i].status;
break;
}
}
if (Array[i].upcCode != upcCode)
cout << " Sorry no such product";
}
int main()
{
int ch = 1;
struct item items[5];
inputItems(items, 5);
while (ch != 5) //repeat menu 05 options
{
cout << " 1.Rent/Sell item";
cout << " 2.Return an item";
cout << " 3.Search for specific item";
cout << " 4.Display inventory items";
cout << " 5.Exit";
cin >> ch;
switch (ch) //switch for each menu option
{
case 1:
rentsellItem(items, 103, 5);
break;
case 2:
returnItem(items, 103, 5);
break;
case 3:
searchItem(items, 103, 5);
break;
case 4:
for (int i = 101; i <= 105; i++)
searchItem(items, i, 5);
break;
case 5:
cout << " Exit";
break;
default:
cout << " Invalid choice";
}
}
return 0;
}
//OUTPUT
Explanation / Answer
#include<vector>
using namespace std;
class a
{
a()
{
}
vector item //mix types of structure
{
int upcCode;
char pname[20];
int qty;
float price;
int status;
};
void inputItems(struct item Array[], int size) //reading n no.of array of products
{
for (int i = 0; i
{
cout << "Enter unique product code :";
cin >> Array[i].upcCode;
cout << "Enter product name :";
cin >> Array[i].pname;
cout << "Enter product quantity :";
cin >> Array[i].qty;
cout << "Enter product price :";
cin >> Array[i].price;
Array[i].status = 0; //Rental or status of items is 0 initially
}
}
void rentsellItem(struct item Array[], int upcCode, int size) //Renting of an item
{
int i;
for (i = 0; i
{
if (Array[i].upcCode == upcCode) //if item found
{
Array[i].status = 1;
cout << " Rental/Selling is done for product code : " << upcCode;
break;
}
}
if (Array[i].upcCode != upcCode) //if item not found
cout << " Sorry no such product";
}
void returnItem(struct item Array[], int upcCode, int size) //returning status of item
{
int i;
for (i = 0; i
{
if (Array[i].upcCode == upcCode)
{
Array[i].status = 0;
cout << " Return of item is done for product code : " << upcCode;
break;
}
}
if (Array[i].upcCode != upcCode) //if not found
cout << " Sorry no such product";
}
void searchItem(struct item Array[], int upcCode, int size) //Searcing function
{
int i;
for (i = 0; i
{
if (Array[i].upcCode == upcCode)
{
cout << " Product code :" << Array[i].upcCode;
cout << " product name : " << Array[i].pname;
cout << " product quantity :" << Array[i].qty;
cout << " product price : " << Array[i].price;
cout << " product status : " << Array[i].status;
break;
}
}
if (Array[i].upcCode != upcCode)
cout << " Sorry no such product";
}
};
int main()
{
a o;
int ch = 1;
struct item items[5];
o.inputItems(items, 5);
while (ch != 5) //repeat menu 05 options
{
cout << " 1.Rent/Sell item";
cout << " 2.Return an item";
cout << " 3.Search for specific item";
cout << " 4.Display inventory items";
cout << " 5.Exit";
cin >> ch;
switch (ch) //switch for each menu option
{
case 1:
o.rentsellItem(items, 103, 5);
break;
case 2:
o.returnItem(items, 103, 5);
break;
case 3:
o.searchItem(items, 103, 5);
break;
case 4:
for (int i = 101; i <= 105; i++)
o.searchItem(items, i, 5);
break;
case 5:
cout << " Exit";
break;
default:
cout << " Invalid choice";
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.