In: Computer Science
c++
LINEAR SEARCH ARRAYS OF OBJECTS
Use the Item class defined in question #12.
1. (3 pts) Declare an array of 1024 Item objects. Assuming the array is now sorted by Value (price per item * quantity).
2. Write a function (with both declaration/prototype (3 pts) and definition (6 pts) ) that takes an array of Item objects, an integer as array size and two references to integers that represents the start_index and end_index of Item object elements whose Values are 50.0.
The function's implementation should be:
An example of such array of Items will be the below:
index 0 1 2 3 4 5 6 7 8 9 ........
Value 21.4 23.3 50.0 50.0 50.0 67.5 88.0 88.3 95.2 141.5 ....... (Note that the array is sorted)
In this example your function must assign 2 to start_index and 4 to end_index.
#12
This question has two parts:
Part 1: Define an Item class with the following specifications:
NOTE: you must declare and define the class separately. Include the definitions of constructors/destructor and member functions in class declaration will result in 50% point deduction.
NOTE: The class definition must follow Google naming convention for class name, member data names and member function names (do not use camelCase convention)
Part 2: (5 pts)
Instantiate two Item objects: one using the default constructor and the other using the non-default constructor (description: "Toys", quantity: 100, price per item: 29.95).
Invoke the company name (static data).
Set the price per item of the default object to the non-default object's price per item.
Output the Value of the non-default object.
Increment the default-object's quantity to 9999.
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
=================================
#include <iostream>
using namespace std;
// Creating an Item class
class Item
{
private:
// Declaring variables
string description;
int quantity;
double value;
static const string companyname;
public:
// Zero argumented constructor
Item()
{
this->description="Unknown";
this->quantity = 0;
this->value=0.0;
}
Item(string des,int qty,double val)
{
this->description=des;
this->quantity = qty;
this->value=val;
}
~Item()
{
cout<<"Description
:"<<description<<endl;
cout<<"Quantity
:"<<quantity<<endl;
cout<<"Value :"<<value<<endl;
}
string getDescription()
{
return description;
}
void setQuantity(int qty)
{
this->quantity=qty;
}
int getQuantity()
{
return quantity;
}
// mutator function to set the description
void setDescription(string des)
{
this->description = des;
}
void setValue(double val)
{
this->value=val;
}
// This function will increment quantity by 1
double increment(int qty)
{
if(qty>0)
this->quantity +=qty;
else
return quantity*value;
}
double getValue()
{
return value;
}
static string getCompanyName()
{
return companyname;
}
};
const string Item::companyname="Foothill Merchandise";
int main()
{
//Creating Two instances of class
Item item1;
Item item2("Toys",100,29.95);
cout<<"Company name
:"<<Item::getCompanyName()<<endl;
item1.setValue(45.00);
cout<<"Item#1 Price per Item
:$"<<item1.getValue()<<endl;
item1.increment(9999);
return 0;
}
===================================
Output:

=====================Could you plz rate me well.Thank You