Need help adding a pointer. Help me run this!! Do not close... Any help with thi
ID: 657588 • Letter: N
Question
Need help adding a pointer. Help me run this!!
Do not close... Any help with this subject will get points. Im not asking explicitly for code. im looking for explanations or code. Explanation for why a pointer would even be necesarry for example.
Please only in c++
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:
// Vectors-Class.cpp : Defines the entry point for the console application.
//Header files
#include
#include
using namespace std;
//define the structure
struct item //mix types of structure
{
int upcCode;
char pname[20];
int qty;
float price;
int status;
};
//define the class a
class a
{//specify the access specifier
public:
//construntor
a(){ }
//reading n no.of array of products
void inputItems(struct item Array[], int size) //reading n no.of array of products
{
for (int i = 0; i< size; 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
}
}
//definition of rentsellItem defines the Renting of an item
void rentsellItem(struct item Array[], int upcCode, int size)
{
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";
}
//definition of returnItem that returns the status of item
void returnItem(struct item Array[], int upcCode, int size)
{
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";
}
//definition of searchItem that searches for the upcCode and displays the values
void searchItem(struct item Array[], int upcCode, int size) //Searcing function
{
int i;
cout << "Product details: " << endl;
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";
}
};
//main function
int main()
{
//declare the class variable
a o;
//declare the variables
int ch = 0;
int itemcode;
struct item items[5];
//Prompt the user regarding the id information
cout << " Enter the item codes in between 101 to 105." << endl;
//call teh inputItems method by passing the array of structures and size
o.inputItems(items, 5);
while (ch != 5) //repeat menu 05 options
{
//display the menu
cout << " 1.Rent/Sell item";
cout << " 2.Return an item";
cout << " 3.Search for specific item";
cout << " 4.Display inventory items";
cout << " 5.Exit";
//prompt the user to enter the choice
cout << " Enter your choice: ";
cin >> ch;
switch (ch) //switch for each menu option
{
case 1:
cout << " Enter the code of the item rent/sell: ";
cin >> itemcode;
o.rentsellItem(items, itemcode, 5);
break;
case 2:
cout << " Enter the code of the item rent/sell: ";
cin >> itemcode;
o.returnItem(items, itemcode, 5);
break;
case 3:
cout << " Enter the code of the item rent/sell: ";
cin >> itemcode;
o.searchItem(items, itemcode, 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;
}
/*Note :
1. In the code, when the structure is defined, the name of the structure should be as same as the parameter that is used in the method declaration.
That is, struct item items[].Here, the structure is item.
If you want to define it as vector then change the name item to vector.
2. The for loop is not properly defined in the code, just replaced the code of for loop.*/
Explanation / Answer
#include iostream;
#include std;
using namespace std;
struct item
{
int upcCode;
char pname[20];
int qty;
float price;
int status;
};
class a
{
public:
a(){
qty q= new qty();
this.qty(a);
}
void inputItems(struct item Array[], int size)
{
for (int i = 0; i< size; 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;
}
}
void rentsellItem(struct item Array[], int upcCode, int size)
{
int i;
for (i = 0; i<size;i++)
{
if (Array[i].upcCode == upcCode)
{
Array[i].status = 1;
cout << " Rental/Selling is done for product code : " << upcCode;
break;
}
}
if (Array[i].upcCode != upcCode)
cout << " Sorry no such product";
}
void returnItem(struct item Array[], int upcCode, int size)
{
int i;
for (i = 0; i<size;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)
cout << " Sorry no such product";
}
void searchItem(struct item Array[], int upcCode, int size)
{
int i;
cout << "Product details: " << endl;
for (i = 0; i<size;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 = 0;
int itemcode;
struct item items[5];
cout << " Enter the item codes in between 101 to 105." << endl;
o.inputItems(items, 5);
while (ch != 5)
{
cout << " 1.Rent/Sell item";
cout << " 2.Return an item";
cout << " 3.Search for specific item";
cout << " 4.Display inventory items";
cout << " 5.Exit";
cout << " Enter your choice: ";
cin >> ch;
switch (ch)
{
case 1:
cout << " Enter the code of the item rent/sell: ";
cin >> itemcode;
o.rentsellItem(items, itemcode, 5);
break;
case 2:
cout << " Enter the code of the item rent/sell: ";
cin >> itemcode;
o.returnItem(items, itemcode, 5);
break;
case 3:
cout << " Enter the code of the item rent/sell: ";
cin >> itemcode;
o.searchItem(items, itemcode, 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.