An engineer keeps an inventory of car parts, but on paper. The usual operations on his ‘inventory database’ include adding new parts, updating levels of current stock and producing different reports based on the current stock levels. As the inventory is getting larger, this manual system is becoming difficult to manage. The engineer decided to develop a computerized system to help him manage the inventory. As he is not expert in database management systems, he decided to develop his own application, based on the C++ knowledge he had during his early university education. The inventory data are printed as in the following table:
make model partNo price quantity partName
Pajero NA1H25 1 3.65 11 BLADE W/S WIPER
*there is almost a thousand of these but I put it just to know the data-type:
Data must be read from the inventory file and stored in one-dimensional arrays of correct data type. Further data processing is performed on these arrays.
Requirements
You are required to help this engineer by developing the Inventory Control System. Your system should perform the following operations:
Add a new item. Write a function called addItem() that asks the user to input data of a new part and then add the data to the parts file.
Update stock level. Write a function called updateItem() that takes as parameter the partNo and the quantity to be added/removed. Check that enough items are there if the operation is a remove operation.
Remove an item. You cannot remove an array element. However, let us use a negative partNo to indicate a removed item. When saving the arrays to the file, only save items with positive partNo.
List the current inventory in a tabular format (begin with the partNo followed by the PartName). In the last column of this list show the total price of each item (i.e. price*quantity).
Produce lists of the following:
o All items whose quantity field < 5.
o All items whose price is greater than a value provided by the user.
o All items whose price is greater than the average item price.
o Stock statistics such as: the current value of the stock (sum of price*quantity), the average price, the most expensive item, the least expensive item, the least stocked item … etc.
= = = = = = = = =
//
#include<iostream>
#include<iomanip>
#include<string>
#include <fstream>
using namespace std;
const int arraySize = 1000;
double price[arraySize];
int partNo[arraySize], quantity[arraySize];
string make[arraySize], partName[arraySize];
void menu();
void option(int);
void choice1();
int main()
{
int choice=0;
while (choice != 8)// condtion choice not equal 8
{
menu();//calling menu function
cin >> choice;// enter the choice
option (choice);// calling the switch funtion and send the choice
}
return 0;
}
void menu()// menu function the have the menu output only
{
cout <<"Inventory Control System \n \n"
<< "\t [1] Add part\n"
<< "\t [2] Update part \n"
<< "\t [3] Remove part\n"
<< "\t [4] List inventory \n"
<< "\t [5] Parts whose quantity < 5 \n"
<< "\t [6] Parts above a given price \n"
<< "\t [7] Parts above the average price \n"
<< "\t [8] Stock statistics \n \n"
<< "\t [9] Exit \n \n"
<< "Enter your choice: ";
}
void option(int x)
{
switch(x)
{
case 1 :
choice1();
break;
case 2 :
choice2();
break;
case 3 :
choice3();
break;
case 4 :
choice4();
break;
case 5 :
choice5();
break;
case 6 :
choice6();
break;
case 7 :
choice7();
break;
case 8 :
choice8();
break;
case 9 :
choice9();
break;
default :
cout<<"Wrong choice \n";// if the choice were wrong
}
}
//
[[
This is a tough question I started but got confused
when I started doing the void functions:
also I faced a problem while trying to read the data.
#include <iostream>
#include <string>
usingnamespace std;
class StockItem {
private: // Reduntant as this is the default for class structure
string Make;
string Model;
int PartNo;
int Qty;
double Price;
public:
StockItem (); // default contructor
bool Add ();
bool Delete ();
bool Edit ();
void List ( int Qty );
void List ( double Value, bool Equal = true );
};
// Default constructor. Set items to known values incase class declared on stack.
StockItem::StockItem () {
Make = Model = "";
PartNo = Qty = 0;
Price = 0.0;
};
StockItem Stk [256]; // Should be sufficient for this example
int main () {
return 0;
}
We did not study classes and structures yet. but the main idea was clear for me, thank you for your answer I really appreciate it if u can use simple functions and arrays, it's easier to understand
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
// Main body of application
int main () {
// You put stuff here to make next conditional work
if ( FileNme != "" ) {
// Open a stream called Data
if ( Data.good () ) {
Data.close ();
return 0; // At this point everything went according to plan.
}
else
cout << "Failed to open " << FileNme << endl;
}
else
cout << "You must specify a name" << endl;
return -1; // If we made it to here, something went wrong
}
I choose this method of top down structure because it makes improperly nested conditionals a lot less likely as the app develops