SlideShare a Scribd company logo
So I already have most of the code and now I have to:
1. create an index file to keep track of all the inventory IDs and their locations
2. modify my class to be able to display any record with a given ID without searching through
the entire file
// This program displays the contents of the inventory file.
#include
#include
#include
using namespace std;
class DB{
// Declaration of InventoryItem structure
class InventoryItem
{
public:
char Id[5];
char desc[31];
int qty;
float price;
};
string DBname;
fstream inventory;// (DBname, ios::in | ios::binary);
public: DB(string N){ DBname = N; }// constructor
private:void Input(InventoryItem &Inv)
{
cout << "Please type Id" << endl;
cin >> Inv.Id;
cout << "Please type Desc" << endl;
cin >> Inv.desc;
cout << "Please type qty" << endl;
cin >> Inv.qty;
cout << "Please type price"<> Inv.price;
}
public: void Create(int Nrec)
{
inventory.open(DBname, ios::out | ios::binary);
// fstream inventory("Inventory.dat", ios::out | ios::binary);
InventoryItem record = { "", " ", 0, 0.0 };
// Write the blank records
for (int count = 0; count < Nrec; count++)
{
Input(record);
cout << "Now writing record " << count << endl;
inventory.write(reinterpret_cast(&record), sizeof(record));
}
// Close the file.
inventory.close();
return ;
}
public: void Display()
{
inventory.open(DBname, ios::in | ios::binary);
InventoryItem record = { "","", 0, 0.0 };
// Now read and display the records
inventory.read(reinterpret_cast(&record),
sizeof(record));
while (!inventory.eof())
{
cout << "Inventory Id: ";
cout << record.Id << endl;
cout << "Description: ";
cout << record.desc << endl;
cout << "Quantity: ";
cout << record.qty << endl;
cout << "Price: ";
cout << record.price << endl << endl;
inventory.read(reinterpret_cast(&record), sizeof(record));
}
// Close the file.
inventory.close();
return;
}
};
int main()
{
DB Mydb("Inventory.dat"); // declare a database
Mydb.Create(3); // load data
cout << "***** display ***" << endl;
Mydb.Display(); // print entire database
// implement the following function
// Mydb.Show("AB001"); // display record with given ID
char C; cin >> C; return 0;
}
Solution
Programming Code in C++
#include
#include
#include
#include
#include
#include
using namespace std;
//Structure.
struct InvStruct
{
string iName;
int iQuantity;
double iPrice;
};
const int MAXSIZE = 9;
void addToInventory(InvStruct aList[], int& aSize);
void displayInventory(const InvStruct aList[], int aSize);
void saveToFile(const InvStruct aList[], int aSize);
void openAFile(InvStruct aList[], int& aSize);
char menuResponse();
int main(int argc, char *argv[])
{
InvStruct iRecords[MAXSIZE];
int noOfRec = 0;
bool reRun = true;
do
{
cout << "Inventory has " << noOfRec << " items" << endl;
switch (menuResponse())
{
case 'A':
addToInventory(iRecords, noOfRec);
break;
case 'D':
displayInventory(iRecords, noOfRec);
break;
case 'O':
openAFile(iRecords, noOfRec);
break;
case 'S':
saveToFile(iRecords, noOfRec);
break;
case 'Q':
reRun = false;
break;
default:
cout << "Invalid Selection" << endl;
}
} while (reRun);
cout << endl << "Code Ends" << endl;
return EXIT_SUCCESS;
}
//Method definition addToInventory().
void addToInventory(InvStruct aList[], int& aSize)
{
InvStruct temp;
char reRun;
char iStr[256];
if (aSize < MAXSIZE)
{
system("cls");
cout << "Enter data to inventory! " << endl;
cout << "Enter data: " << endl << endl;
cout << "Name: ";
cin.getline(iStr, 256, ' ');
temp.iName = iStr;
cout << "Quantity: ";
cin >> temp.iQuantity;
cout << "Value: ";
cin >> temp.iPrice;
cout << endl;
cout << "Add more data to the inventory? (y/n) ";
cin >> reRun;
if (toupper(reRun) == 'Y')
aList[aSize++] = temp;
}
else
{
cout << "Can't add data! Inventory is full!!" << endl;
system("pause");
}
system("cls");
}
//Method definition displayInventory().
void displayInventory(const InvStruct aList[], int aSize)
{
system("cls");
double iCost = 0;
if (aSize < 1)
{
cout << "No data to display" << endl;
}
else
{
cout << "All data in the inventory" << endl << endl;
cout << fixed << setprecision(2);
cout << "Name Quantity Price" << endl;
cout << "--------------------------------------" << endl;
cout << left;
for (int inc = 0; inc < aSize; inc++)
{
cout << setw(21) << aList[inc].iName << right
<< setw(4) << aList[inc].iQuantity
<< setw(10) << aList[inc].iPrice << left << endl;
iCost = iCost + aList[inc].iPrice * aList[inc].iQuantity;
}
cout << "--------------------------------------" << endl;
cout << right << setw(3) << aSize;
cout << " data listed";
cout << right << setw(18) << iCost << endl << endl;
}
system("PAUSE");
system("cls");
}
//Method definition saveToFile()
void saveToFile(const InvStruct aList[], int aSize)
{
ofstream outf("Inventory.dat");
if (!outf.fail())
{
system("cls");
cout << "Save the inventory";
for (int inc = 0; inc < aSize; inc++)
{
outf << aList[inc].iName << ';'
<< aList[inc].iQuantity << ';'
<< aList[inc].iPrice;
if (inc < aSize - 1)
outf << endl;
}
cout << endl << aSize << " data written." << endl;
outf.close();
system("PAUSE");
system("cls");
}
else
{
cout << "Problem with the input file" << endl;
system("PAUSE");
system("cls");
}
}
void openAFile(InvStruct aList[], int& aSize)
{
ifstream inf("Inventory.txt");
string iStr;
stringstream iStrStrm;
// make sure the file stream is open before doing IO
if (!inf.fail())
{
system("cls");
cout << "Read inventory";
aSize = 0;
while (!inf.eof() && aSize < MAXSIZE)
{
getline(inf, iStr, ';');
aList[aSize].iName = iStr;
getline(inf, iStr, ';');
iStrStrm.str("");
iStrStrm.clear();
iStrStrm << iStr;
iStrStrm >> aList[aSize].iQuantity;
getline(inf, iStr);
iStrStrm.str(""); iStrStrm.clear();
iStrStrm << iStr;
iStrStrm >> aList[aSize++].iPrice;
}
cout << endl << aSize << " data read from the inventory." << endl;
system("PAUSE");
system("cls");
}
else
{
cout << "Problem with the input file" << endl;
system("PAUSE");
system("cls");
}
}
char menuResponse()
{
char reRun;
cout << endl << "Your selection" << endl
<< "A - Add data, D - Display data, O - Open File, S - Save File, Q - Quit" << endl
<< "> ";
cin >> reRun;
cin.ignore(256, ' ');
return toupper(reRun);
}
Sample Output:
Inventory has 1 item
Your selection
A- Add data, D- Display data, O - Open File, S - Save File, Q - Quit
>
D
Name Quantity Price
--------------------------------------------------------------------------------------------------
12 12.50
--------------------------------------------------------------------------------------------------
1 data listed 150.00

More Related Content

Similar to So I already have most of the code and now I have to1. create an .pdf

Managing console
Managing consoleManaging console
Managing console
Shiva Saxena
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
ssuser454af01
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
Ashwin Francis
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
Mitul Patel
 
getting errors in the Product-cpp file error- (Expected function bo.pdf
getting errors in the Product-cpp file error-    (Expected function bo.pdfgetting errors in the Product-cpp file error-    (Expected function bo.pdf
getting errors in the Product-cpp file error- (Expected function bo.pdf
NicholasflqStewartl
 
Array of objects.pptx
Array of objects.pptxArray of objects.pptx
Array of objects.pptx
RAGAVIC2
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
adityastores21
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
HIMANSUKUMAR12
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
aassecuritysystem
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
aathiauto
 
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project ADN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
Dataconomy Media
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
pratikbakane
 
Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptx
arjurakibulhasanrrr7
 
I keep on get a redefinition error and an undefined error.Customer.pdf
I keep on get a redefinition error and an undefined error.Customer.pdfI keep on get a redefinition error and an undefined error.Customer.pdf
I keep on get a redefinition error and an undefined error.Customer.pdf
herminaherman
 
The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196
Mahmoud Samir Fayed
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 

Similar to So I already have most of the code and now I have to1. create an .pdf (20)

Managing console
Managing consoleManaging console
Managing console
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
 
getting errors in the Product-cpp file error- (Expected function bo.pdf
getting errors in the Product-cpp file error-    (Expected function bo.pdfgetting errors in the Product-cpp file error-    (Expected function bo.pdf
getting errors in the Product-cpp file error- (Expected function bo.pdf
 
Array of objects.pptx
Array of objects.pptxArray of objects.pptx
Array of objects.pptx
 
Day 1
Day 1Day 1
Day 1
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project ADN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptx
 
I keep on get a redefinition error and an undefined error.Customer.pdf
I keep on get a redefinition error and an undefined error.Customer.pdfI keep on get a redefinition error and an undefined error.Customer.pdf
I keep on get a redefinition error and an undefined error.Customer.pdf
 
The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 

More from arjuncollection

In the negative feedback control system of the papillary light refle.pdf
In the negative feedback control system of the papillary light refle.pdfIn the negative feedback control system of the papillary light refle.pdf
In the negative feedback control system of the papillary light refle.pdf
arjuncollection
 
images of a Hindu deity such as Shiva, Vishnu, Kali, Ganesh, or any .pdf
images of a Hindu deity such as Shiva, Vishnu, Kali, Ganesh, or any .pdfimages of a Hindu deity such as Shiva, Vishnu, Kali, Ganesh, or any .pdf
images of a Hindu deity such as Shiva, Vishnu, Kali, Ganesh, or any .pdf
arjuncollection
 
Identify each of the enzymes involved in DNA replication and whether.pdf
Identify each of the enzymes involved in DNA replication and whether.pdfIdentify each of the enzymes involved in DNA replication and whether.pdf
Identify each of the enzymes involved in DNA replication and whether.pdf
arjuncollection
 
How and what do sea stars eatSolutionSea Star eat clams, oyste.pdf
How and what do sea stars eatSolutionSea Star eat clams, oyste.pdfHow and what do sea stars eatSolutionSea Star eat clams, oyste.pdf
How and what do sea stars eatSolutionSea Star eat clams, oyste.pdf
arjuncollection
 
Estimate the time needed for the Point in Polyhedron test for a poly.pdf
Estimate the time needed for the Point in Polyhedron test for a poly.pdfEstimate the time needed for the Point in Polyhedron test for a poly.pdf
Estimate the time needed for the Point in Polyhedron test for a poly.pdf
arjuncollection
 
Discuss the binary representation of Char strings. What makes th.pdf
Discuss the binary representation of Char strings. What makes th.pdfDiscuss the binary representation of Char strings. What makes th.pdf
Discuss the binary representation of Char strings. What makes th.pdf
arjuncollection
 
Describe a possible difference in the DNA content of chromosome 1.pdf
Describe a possible difference in the DNA content of chromosome 1.pdfDescribe a possible difference in the DNA content of chromosome 1.pdf
Describe a possible difference in the DNA content of chromosome 1.pdf
arjuncollection
 
Consider the following function. Find the inverse function State the.pdf
Consider the following function.  Find the inverse function State the.pdfConsider the following function.  Find the inverse function State the.pdf
Consider the following function. Find the inverse function State the.pdf
arjuncollection
 
Compare and contrast the ideas that led to the Bohr model of the ato.pdf
Compare and contrast the ideas that led to the Bohr model of the ato.pdfCompare and contrast the ideas that led to the Bohr model of the ato.pdf
Compare and contrast the ideas that led to the Bohr model of the ato.pdf
arjuncollection
 
Blackboard Learn Realtor Rite Aid Citizens Bank peoples CPOBIE UI.pdf
Blackboard Learn Realtor Rite Aid Citizens Bank peoples CPOBIE UI.pdfBlackboard Learn Realtor Rite Aid Citizens Bank peoples CPOBIE UI.pdf
Blackboard Learn Realtor Rite Aid Citizens Bank peoples CPOBIE UI.pdf
arjuncollection
 
According to the Shannon-Hartley theorem, the capacity of a communic.pdf
According to the Shannon-Hartley theorem, the capacity of a communic.pdfAccording to the Shannon-Hartley theorem, the capacity of a communic.pdf
According to the Shannon-Hartley theorem, the capacity of a communic.pdf
arjuncollection
 
A fellow student, one that is not as careful as you, finds the follow.pdf
A fellow student, one that is not as careful as you, finds the follow.pdfA fellow student, one that is not as careful as you, finds the follow.pdf
A fellow student, one that is not as careful as you, finds the follow.pdf
arjuncollection
 
2. There are special proteins (called transporters) that are able to.pdf
2. There are special proteins (called transporters) that are able to.pdf2. There are special proteins (called transporters) that are able to.pdf
2. There are special proteins (called transporters) that are able to.pdf
arjuncollection
 
A bacterium that has flagella arranged as a tuft at one end of the b.pdf
A bacterium that has flagella arranged as a tuft at one end of the b.pdfA bacterium that has flagella arranged as a tuft at one end of the b.pdf
A bacterium that has flagella arranged as a tuft at one end of the b.pdf
arjuncollection
 
11. Recessive epistasis is described by all of the following EXCEPT.pdf
11. Recessive epistasis is described by all of the following EXCEPT.pdf11. Recessive epistasis is described by all of the following EXCEPT.pdf
11. Recessive epistasis is described by all of the following EXCEPT.pdf
arjuncollection
 
Write complete VHDL codes for the following schematic. Solution.pdf
Write complete VHDL codes for the following schematic.  Solution.pdfWrite complete VHDL codes for the following schematic.  Solution.pdf
Write complete VHDL codes for the following schematic. Solution.pdf
arjuncollection
 
Why do carrier-mediated processes become saturated (choose the best .pdf
Why do carrier-mediated processes become saturated (choose the best .pdfWhy do carrier-mediated processes become saturated (choose the best .pdf
Why do carrier-mediated processes become saturated (choose the best .pdf
arjuncollection
 
Why is it that linked lists are better when it comes to needing freq.pdf
Why is it that linked lists are better when it comes to needing freq.pdfWhy is it that linked lists are better when it comes to needing freq.pdf
Why is it that linked lists are better when it comes to needing freq.pdf
arjuncollection
 
Which of the following isare characteristic of the parasympathetic .pdf
Which of the following isare characteristic of the parasympathetic .pdfWhich of the following isare characteristic of the parasympathetic .pdf
Which of the following isare characteristic of the parasympathetic .pdf
arjuncollection
 
What statistic is often interpreted as providing an estimate of the .pdf
What statistic is often interpreted as providing an estimate of the .pdfWhat statistic is often interpreted as providing an estimate of the .pdf
What statistic is often interpreted as providing an estimate of the .pdf
arjuncollection
 

More from arjuncollection (20)

In the negative feedback control system of the papillary light refle.pdf
In the negative feedback control system of the papillary light refle.pdfIn the negative feedback control system of the papillary light refle.pdf
In the negative feedback control system of the papillary light refle.pdf
 
images of a Hindu deity such as Shiva, Vishnu, Kali, Ganesh, or any .pdf
images of a Hindu deity such as Shiva, Vishnu, Kali, Ganesh, or any .pdfimages of a Hindu deity such as Shiva, Vishnu, Kali, Ganesh, or any .pdf
images of a Hindu deity such as Shiva, Vishnu, Kali, Ganesh, or any .pdf
 
Identify each of the enzymes involved in DNA replication and whether.pdf
Identify each of the enzymes involved in DNA replication and whether.pdfIdentify each of the enzymes involved in DNA replication and whether.pdf
Identify each of the enzymes involved in DNA replication and whether.pdf
 
How and what do sea stars eatSolutionSea Star eat clams, oyste.pdf
How and what do sea stars eatSolutionSea Star eat clams, oyste.pdfHow and what do sea stars eatSolutionSea Star eat clams, oyste.pdf
How and what do sea stars eatSolutionSea Star eat clams, oyste.pdf
 
Estimate the time needed for the Point in Polyhedron test for a poly.pdf
Estimate the time needed for the Point in Polyhedron test for a poly.pdfEstimate the time needed for the Point in Polyhedron test for a poly.pdf
Estimate the time needed for the Point in Polyhedron test for a poly.pdf
 
Discuss the binary representation of Char strings. What makes th.pdf
Discuss the binary representation of Char strings. What makes th.pdfDiscuss the binary representation of Char strings. What makes th.pdf
Discuss the binary representation of Char strings. What makes th.pdf
 
Describe a possible difference in the DNA content of chromosome 1.pdf
Describe a possible difference in the DNA content of chromosome 1.pdfDescribe a possible difference in the DNA content of chromosome 1.pdf
Describe a possible difference in the DNA content of chromosome 1.pdf
 
Consider the following function. Find the inverse function State the.pdf
Consider the following function.  Find the inverse function State the.pdfConsider the following function.  Find the inverse function State the.pdf
Consider the following function. Find the inverse function State the.pdf
 
Compare and contrast the ideas that led to the Bohr model of the ato.pdf
Compare and contrast the ideas that led to the Bohr model of the ato.pdfCompare and contrast the ideas that led to the Bohr model of the ato.pdf
Compare and contrast the ideas that led to the Bohr model of the ato.pdf
 
Blackboard Learn Realtor Rite Aid Citizens Bank peoples CPOBIE UI.pdf
Blackboard Learn Realtor Rite Aid Citizens Bank peoples CPOBIE UI.pdfBlackboard Learn Realtor Rite Aid Citizens Bank peoples CPOBIE UI.pdf
Blackboard Learn Realtor Rite Aid Citizens Bank peoples CPOBIE UI.pdf
 
According to the Shannon-Hartley theorem, the capacity of a communic.pdf
According to the Shannon-Hartley theorem, the capacity of a communic.pdfAccording to the Shannon-Hartley theorem, the capacity of a communic.pdf
According to the Shannon-Hartley theorem, the capacity of a communic.pdf
 
A fellow student, one that is not as careful as you, finds the follow.pdf
A fellow student, one that is not as careful as you, finds the follow.pdfA fellow student, one that is not as careful as you, finds the follow.pdf
A fellow student, one that is not as careful as you, finds the follow.pdf
 
2. There are special proteins (called transporters) that are able to.pdf
2. There are special proteins (called transporters) that are able to.pdf2. There are special proteins (called transporters) that are able to.pdf
2. There are special proteins (called transporters) that are able to.pdf
 
A bacterium that has flagella arranged as a tuft at one end of the b.pdf
A bacterium that has flagella arranged as a tuft at one end of the b.pdfA bacterium that has flagella arranged as a tuft at one end of the b.pdf
A bacterium that has flagella arranged as a tuft at one end of the b.pdf
 
11. Recessive epistasis is described by all of the following EXCEPT.pdf
11. Recessive epistasis is described by all of the following EXCEPT.pdf11. Recessive epistasis is described by all of the following EXCEPT.pdf
11. Recessive epistasis is described by all of the following EXCEPT.pdf
 
Write complete VHDL codes for the following schematic. Solution.pdf
Write complete VHDL codes for the following schematic.  Solution.pdfWrite complete VHDL codes for the following schematic.  Solution.pdf
Write complete VHDL codes for the following schematic. Solution.pdf
 
Why do carrier-mediated processes become saturated (choose the best .pdf
Why do carrier-mediated processes become saturated (choose the best .pdfWhy do carrier-mediated processes become saturated (choose the best .pdf
Why do carrier-mediated processes become saturated (choose the best .pdf
 
Why is it that linked lists are better when it comes to needing freq.pdf
Why is it that linked lists are better when it comes to needing freq.pdfWhy is it that linked lists are better when it comes to needing freq.pdf
Why is it that linked lists are better when it comes to needing freq.pdf
 
Which of the following isare characteristic of the parasympathetic .pdf
Which of the following isare characteristic of the parasympathetic .pdfWhich of the following isare characteristic of the parasympathetic .pdf
Which of the following isare characteristic of the parasympathetic .pdf
 
What statistic is often interpreted as providing an estimate of the .pdf
What statistic is often interpreted as providing an estimate of the .pdfWhat statistic is often interpreted as providing an estimate of the .pdf
What statistic is often interpreted as providing an estimate of the .pdf
 

Recently uploaded

Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 

Recently uploaded (20)

Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 

So I already have most of the code and now I have to1. create an .pdf

  • 1. So I already have most of the code and now I have to: 1. create an index file to keep track of all the inventory IDs and their locations 2. modify my class to be able to display any record with a given ID without searching through the entire file // This program displays the contents of the inventory file. #include #include #include using namespace std; class DB{ // Declaration of InventoryItem structure class InventoryItem { public: char Id[5]; char desc[31]; int qty; float price; }; string DBname; fstream inventory;// (DBname, ios::in | ios::binary); public: DB(string N){ DBname = N; }// constructor private:void Input(InventoryItem &Inv) { cout << "Please type Id" << endl; cin >> Inv.Id; cout << "Please type Desc" << endl; cin >> Inv.desc; cout << "Please type qty" << endl; cin >> Inv.qty; cout << "Please type price"<> Inv.price; } public: void Create(int Nrec) { inventory.open(DBname, ios::out | ios::binary);
  • 2. // fstream inventory("Inventory.dat", ios::out | ios::binary); InventoryItem record = { "", " ", 0, 0.0 }; // Write the blank records for (int count = 0; count < Nrec; count++) { Input(record); cout << "Now writing record " << count << endl; inventory.write(reinterpret_cast(&record), sizeof(record)); } // Close the file. inventory.close(); return ; } public: void Display() { inventory.open(DBname, ios::in | ios::binary); InventoryItem record = { "","", 0, 0.0 }; // Now read and display the records inventory.read(reinterpret_cast(&record), sizeof(record)); while (!inventory.eof()) { cout << "Inventory Id: "; cout << record.Id << endl; cout << "Description: "; cout << record.desc << endl; cout << "Quantity: "; cout << record.qty << endl; cout << "Price: "; cout << record.price << endl << endl; inventory.read(reinterpret_cast(&record), sizeof(record));
  • 3. } // Close the file. inventory.close(); return; } }; int main() { DB Mydb("Inventory.dat"); // declare a database Mydb.Create(3); // load data cout << "***** display ***" << endl; Mydb.Display(); // print entire database // implement the following function // Mydb.Show("AB001"); // display record with given ID char C; cin >> C; return 0; } Solution Programming Code in C++ #include #include #include #include #include #include using namespace std; //Structure. struct InvStruct { string iName; int iQuantity; double iPrice; };
  • 4. const int MAXSIZE = 9; void addToInventory(InvStruct aList[], int& aSize); void displayInventory(const InvStruct aList[], int aSize); void saveToFile(const InvStruct aList[], int aSize); void openAFile(InvStruct aList[], int& aSize); char menuResponse(); int main(int argc, char *argv[]) { InvStruct iRecords[MAXSIZE]; int noOfRec = 0; bool reRun = true; do { cout << "Inventory has " << noOfRec << " items" << endl; switch (menuResponse()) { case 'A': addToInventory(iRecords, noOfRec); break; case 'D': displayInventory(iRecords, noOfRec); break; case 'O': openAFile(iRecords, noOfRec); break; case 'S': saveToFile(iRecords, noOfRec); break; case 'Q': reRun = false; break; default: cout << "Invalid Selection" << endl;
  • 5. } } while (reRun); cout << endl << "Code Ends" << endl; return EXIT_SUCCESS; } //Method definition addToInventory(). void addToInventory(InvStruct aList[], int& aSize) { InvStruct temp; char reRun; char iStr[256]; if (aSize < MAXSIZE) { system("cls"); cout << "Enter data to inventory! " << endl; cout << "Enter data: " << endl << endl; cout << "Name: "; cin.getline(iStr, 256, ' '); temp.iName = iStr; cout << "Quantity: "; cin >> temp.iQuantity; cout << "Value: "; cin >> temp.iPrice; cout << endl; cout << "Add more data to the inventory? (y/n) "; cin >> reRun; if (toupper(reRun) == 'Y') aList[aSize++] = temp; } else { cout << "Can't add data! Inventory is full!!" << endl; system("pause"); } system("cls"); }
  • 6. //Method definition displayInventory(). void displayInventory(const InvStruct aList[], int aSize) { system("cls"); double iCost = 0; if (aSize < 1) { cout << "No data to display" << endl; } else { cout << "All data in the inventory" << endl << endl; cout << fixed << setprecision(2); cout << "Name Quantity Price" << endl; cout << "--------------------------------------" << endl; cout << left; for (int inc = 0; inc < aSize; inc++) { cout << setw(21) << aList[inc].iName << right << setw(4) << aList[inc].iQuantity << setw(10) << aList[inc].iPrice << left << endl; iCost = iCost + aList[inc].iPrice * aList[inc].iQuantity; } cout << "--------------------------------------" << endl; cout << right << setw(3) << aSize; cout << " data listed"; cout << right << setw(18) << iCost << endl << endl; } system("PAUSE"); system("cls"); } //Method definition saveToFile() void saveToFile(const InvStruct aList[], int aSize) { ofstream outf("Inventory.dat"); if (!outf.fail())
  • 7. { system("cls"); cout << "Save the inventory"; for (int inc = 0; inc < aSize; inc++) { outf << aList[inc].iName << ';' << aList[inc].iQuantity << ';' << aList[inc].iPrice; if (inc < aSize - 1) outf << endl; } cout << endl << aSize << " data written." << endl; outf.close(); system("PAUSE"); system("cls"); } else { cout << "Problem with the input file" << endl; system("PAUSE"); system("cls"); } } void openAFile(InvStruct aList[], int& aSize) { ifstream inf("Inventory.txt"); string iStr; stringstream iStrStrm; // make sure the file stream is open before doing IO if (!inf.fail()) { system("cls"); cout << "Read inventory"; aSize = 0; while (!inf.eof() && aSize < MAXSIZE)
  • 8. { getline(inf, iStr, ';'); aList[aSize].iName = iStr; getline(inf, iStr, ';'); iStrStrm.str(""); iStrStrm.clear(); iStrStrm << iStr; iStrStrm >> aList[aSize].iQuantity; getline(inf, iStr); iStrStrm.str(""); iStrStrm.clear(); iStrStrm << iStr; iStrStrm >> aList[aSize++].iPrice; } cout << endl << aSize << " data read from the inventory." << endl; system("PAUSE"); system("cls"); } else { cout << "Problem with the input file" << endl; system("PAUSE"); system("cls"); } } char menuResponse() { char reRun; cout << endl << "Your selection" << endl << "A - Add data, D - Display data, O - Open File, S - Save File, Q - Quit" << endl << "> "; cin >> reRun; cin.ignore(256, ' '); return toupper(reRun); } Sample Output:
  • 9. Inventory has 1 item Your selection A- Add data, D- Display data, O - Open File, S - Save File, Q - Quit > D Name Quantity Price -------------------------------------------------------------------------------------------------- 12 12.50 -------------------------------------------------------------------------------------------------- 1 data listed 150.00