Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// class InventoryItem #include #include #include #include using namespace std; //#include InventoryItem.h class InventoryItem { private: string description; // The item description int quantityOnHand; //

// class InventoryItem
#include
#include
#include
#include
using namespace std;
//#include "InventoryItem.h"
class InventoryItem
{
private:
string description; // The item description
int quantityOnHand; // Number of units on hand
public:
/*** Class constructors need to be added */
// Accessor functions
string getDescription(){
/*** Add in-line implementation */
}
int getQuantityOnHand(){
/*** Add in-line implementation */
}
// Mutator functions
void setDescription(string ); // sets description member to argument
void setQuantityOnHand(int ); // sets QuantityOnHand to argument
};
//**********************************************************
// From here to the line of asterisks is the implementation of class
// InventoryItem
void InventoryItem::setDescription(string d)
// Post: description data member is set to string d;
{
/*** add code here */
}
void InventoryItem::setQuantityOnHand(int q)
// Post: set quantityOnHand to to q if q >= 0; unchanged otherwise;
{
/*** add code here */
}
//*******************************************************
// This program is used to test class InventoryItem
int main()
{
/*** Declare an InventoryItem object */
/*** write code to test the mutator and accessor members */
system(pause);
return 0;
}
TASK1: ACCESSORS AND MUTATORS (GETTERS AND SETTERS)
Exerise 1. Create a new projects and enter the code above in a cpp file.
Exerise 2. Complete the code for the getQuantityOnhand() and setQuantityOnHand functions).
Exerise 3. Test the two functions:
Declare an InventoryItem objet in function main().
Call the setQuantityOnHand() function to set its qantityOnHand data member. Then call getQuantityOnhand() to display it. Whats your test data set?
Try to access (e.g. display) qantityOnHand using the member access operator (i.e. dot operator). What happens?
Exerise 4. Repeat steps 2 and 3 for the description data member.
TASK2: SEPARATE CLASS SPECIFICATION AND CLASS IMPLEMENTATION
Split the original file into three files: InventoryItem.h (class specification), InventoryItem.cpp (class implementation), and myClient.cpp (client program with the main function). Make sure to include the header file in both cpp files. Run the project and verify that it works correctly.
TASK 3: CLASS CONSTRUCTORS
Exercise 1. As you may have noted, class InventroyItem is missing class constructors. Add two class constructors to the class: a default constructor and a constructor that initializes each of the class data members to a specified value. Remember that quantityOnHand should never be negative.
Exercise 2. Modify the client program to test your constructors (e.g. initialize item1 with default constructor and item2 with the second constructor).
TASK 4: INPUT/OUTPUT MEMBER FUNCTIONS
1. Add a member function to class InventoryItem to display the data members on the standard output device. The description and quantity on hand should be displayed on two separate lines. Name your function displayInventoryItem().
Describe how you plan to test this member function.
Show expected results here
2. Add a member function (readInventoryItem) to class InventoryItem to read data from an input stream (i.e. file) and set the data members. Data in the input stream has the following format:
A line string representing an item description
An integer representing the quantity on hand
Describe how you plan to test this member function.
Show expected results here
s set to string d;
{
/*** add code here */
}
void InventoryItem::setQuantityOnHand(int q)
// Post: set quantityOnHand to to q if q >= 0; unchanged otherwise;
{
/*** add code here */
}
//*******************************************************
// This program is used to test class InventoryItem
int main()
{
/*** Declare an InventoryItem object */
/*** write code to test the mutator and accessor members */
system(pause);
return 0;
}
TASK1: ACCESSORS AND MUTATORS (GETTERS AND SETTERS)
Exerise 1. Create a new projects and enter the code above in a cpp file.
Exerise 2. Complete the code for the getQuantityOnhand() and setQuantityOnHand functions).
Exerise 3. Test the two functions:
Declare an InventoryItem objet in function main().
Call the setQuantityOnHand() function to set its qantityOnHand data member. Then call getQuantityOnhand() to display it. Whats your test data set?
Try to access (e.g. display) qantityOnHand using the member access operator (i.e. dot operator). What happens?
Exerise 4. Repeat steps 2 and 3 for the description data member.
TASK2: SEPARATE CLASS SPECIFICATION AND CLASS IMPLEMENTATION
Split the original file into three files: InventoryItem.h (class specification), InventoryItem.cpp (class implementation), and myClient.cpp (client program with the main function). Make sure to include the header file in both cpp files. Run the project and verify that it works correctly.
TASK 3: CLASS CONSTRUCTORS
Exercise 1. As you may have noted, class InventroyItem is missing class constructors. Add two class constructors to the class: a default constructor and a constructor that initializes each of the class data members to a specified value. Remember that quantityOnHand should never be negative.
Exercise 2. Modify the client program to test your constructors (e.g. initialize item1 with default constructor and item2 with the second constructor).
TASK 4: INPUT/OUTPUT MEMBER FUNCTIONS
1. Add a member function to class InventoryItem to display the data members on the standard output device. The description and quantity on hand should be displayed on two separate lines. Name your function displayInventoryItem().
Describe how you plan to test this member function.
Show expected results here
2. Add a member function (readInventoryItem) to class InventoryItem to read data from an input stream (i.e. file) and set the data members. Data in the input stream has the following format:
A line string representing an item description
An integer representing the quantity on hand
Describe how you plan to test this member function.
Show expected results here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

A Complete Guide To Data Science Essentials

Authors: Miguel

1st Edition

9358684992, 978-9358684995

More Books

Students also viewed these Databases questions

Question

Write as the sum 64 log4 I N

Answered: 1 week ago

Question

1. Identify and control your anxieties

Answered: 1 week ago