Must use NetBeans Program for C++ Progrmming iclude Header Files EECS 1510 Objec
ID: 3689364 • Letter: M
Question
Must use NetBeans Program for C++ Progrmming
iclude Header Files
Explanation / Answer
#include <iostream>
#include <fstream>
#include <cctype>
using namespace std;
int rec_num=0;
int num_entries;
class Entry {
public:
string name, number, notes;
}InventoryList[200];
string strToUpper (string S) {
for (size_t i=0; i < S.length(); i++)
S[i] = toupper(S[i]);
return S;
}
void readInventory () {
string line;
rec_num=0;
ifstream infile("PhoneData.txt");
while (getline(infile, line))
{
int a, b , c;
if (!(infile >> a >> b >> c)) { break; } // error
else {
InventoryList[rec_num].name = a;
InventoryList[rec_num].number = b;
InventoryList[rec_num].notes = c;
rec_num++;
}
}
}
void storeInventory () {
fstream F("PhoneData.txt");
int rec_num = 0;
while (rec_num < num_entries){
F << InventoryList[rec_num].name << " "
<< InventoryList[rec_num].number << " "
<< InventoryList[rec_num].notes << " " << endl; rec_num++;
}
cout << "Inventory stored." << endl;
return;
}
void enter()
{
char ch,a;
cin>>InventoryList[rec_num].name;
cout<<endl<<"Enter quantity: ";
cin>>InventoryList[rec_num].number;
cout<<endl<<"Enter notes: ";
cin>>InventoryList[rec_num].notes;
rec_num++;
num_entries =rec_num;
}
void findd(string product)
{ int flag=0;
for(int i=0;i<num_entries;i++)
{
if(strToUpper(InventoryList[i].name) == strToUpper(product))
{
cout<<endl<<"--"<<InventoryList[i].name;
cout<<endl<<"--"<<InventoryList[i].number;
cout<<endl<<"--"<<InventoryList[i].notes;
flag=1;
break;
}
}
if(flag == 0)
cout<<endl<<"** No entry with this code "<<product;
return ;
}
void listt()
{
for(int i=0;i<num_entries;i++)
{
cout<<InventoryList[i].name<<endl;
cout<<InventoryList[i].number<<endl;
cout<<InventoryList[i].notes<<endl;
cout<<endl;
}
}
int main()
{
char c;
string f;
cout<<"Press e to enter,f to find,l to list & q to quit";
cout<<" Command:";
cin>>c;
while(c!='q')
{
if(c=='e') enter();
else if(c=='f') {cin>>f; findd(f); }
else if(c=='l') listt();
cout<<" Command:";
cin>>c;
}
storeInventory();
readInventory();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.