Question

C++ Write a program that keeps track of inventory The data is located in the file Inventory.txt. ...

C++ Write a program that keeps track of inventory The data is located in the file Inventory.txt. While the program is running, the information should be stored in a linked list.

  1. The information for each item needs be stored in a struct

    1. The definition will be in a separate file called items.h

  2. The total inventory will be stored in a linked list

    1. The definition of the list class will be in a file called linkList.h

  3. The program should be able to perform the following functions

    1. Display the inventory in alphabetical order by name

    2. Display the inventory in reverse alphabetical order

    3. Add an item

    4. Delete an item from inventory

    5. Change any info for an item

      1. Which means you have to be able to search for a particular item

  4. The program will run until the user chooses an option to exit

  5. The list is not in alphabetical order, so you will need to put it in order.

  6. Whenever you change a name or if you add an item, the list must stay in order.

  7. When you are done, the list will be output to a file called list.txt

    Inventory.txt *************************************************************************************************************************************************************************************************** Telephoto-Pocket-Camera 54.95 15 20
    Mini-Pocket-Camera 24.95 15 12
    Polaroid-1Step-Camera 49.95 10 20
    Sonar-1Step-Camera 189.95 12 13
    Pronto-Camera 74.95 5 15
    8MM-Zoom-Movie-Camera 279.99 10 9
    8MM-Sound/ZoomMovieCamera 310.55 10 15
    35MM-Minolta-SLR-XG-7-Camera 389.00 12 10
    35MM-Pentax-SLR-AE-1-Camera 349.95 12 11
    35MM-Canon-SLR-ME-Camera 319.90 12 20
    35MM-Hi-Matic-Camera 119.95 12 13
    35MM-Compact-Camera 89.99 12 20
    Zoom-Movie-Projector 129.95 5 7
    Zoom-Sound-Projector 239.99 5 9
    Auto-Carousel-Projector 219.99 5 10
    Carousel-Slide-Projector 114.95 5 4
    Pocket-Strobe 14.95 5 4
    StrobeSX-10 48.55 10 12
    Electonic-Flash-SX-10 28.99 15 10
    Tele-Converter 32.99 15 13
    28MM-Wide-Angle-Lens 97.99 15 14
    135MM-Telephoto-Lens 87.95 15 13
    35-105MM-Zoom-Lens 267.95 5 8
    80-200MM-Zoom-Lens 257.95 5 7
    Heavy-Duty-Tripod 67.50 5 4
    Lightweight-Tripod 19.95 5 10
    35MM-Enlarger-Kit 159.99 5 10
    40x40-Deluxe-Screen 35.98 5 4
    50x50-Deluxe-Screen 44.98 5 10
    120-Slide-Tray 4.29 25 17
    100-Slide-Tray 2.95 25 33
    Slide-Viewer 6.25 15 12
    Movie-Editor 55.95 10 12
    Condenser-Microphone 59.95 5 10
    AA-Alkaline-Battery 0.89 100 80
    Gadget-Bag 19.79 20 19
    135-24-Color-Film 1.49 50 45
    110-12-Color-Film 0.99 50 60
    110-24-Color-Film 1.45 50 42
    110-12-B/W-Film 0.59 25 37
    110-24-B/W-Film 0.95 25 43
    126-12-Color-Film 0.89 50 44
    126-12-B/W-Film 0.59 25 27
    8MM-Film-Cassette 6.89 50 39
    16MM-Film-Cassette 11.89 20 25
    Combination-Camera-Kit 959.99 12 10 *****************************************************************************************************************************************************************************************************
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

const int SIZE=50;

struct CamLibrary
{
string cameraName;
int price1;
int price2;
int price3;
CamLibrary *next;
CamLibrary(string, int, int, int,CamLibrary*);
};

CamLibrary::CamLibrary(string tempcameraName,int tempprice1,int tempprice2,int tempprice3,CamLibrary* tempNext):cameraName(tempcameraName), price1(tempprice1), price2(tempprice2), price3(tempprice3), next(tempNext){}

typedef CamLibrary* CamLibraryPtr;

void getline(istream &stream, string &str, char delimiter)
{   char temp[500];

   stream.get(temp, 500, delimiter);
   stream.ignore(500, delimiter);
   str = temp;
}
void getline(istream &stream, int &num, char delimiter)
{   int temp;

   stream >> temp;
   stream.ignore(500, delimiter);
   num= temp;
}

CamLibraryPtr locatecamera(CamLibraryPtr temp, string camName);
void readFile(CamLibraryPtr &root);
void insert(CamLibraryPtr &root);
void delCamera(CamLibraryPtr &root);
void searchCamera(CamLibraryPtr temp);
void saveFile(CamLibraryPtr temp);
int countNodes(CamLibraryPtr temp);
void insertionSort(struct CamLibrary **head_ref);
void printList(CamLibraryPtr temp);


int main()
{
   int choice;
   CamLibraryPtr root = NULL;
   readFile(root);
   printList(root);

   do
   {
       cout << "Menu: Select your option\n\n";
       cout << "(1) Add a camera to the list\n";
       cout << "(2) Delete a camera based on camera name\n";
       cout << "(3) Search for a camera by camera name.\n";
       cout << "(4) List all cameras in alphabetical order.\n";
       cout << "(5) Quit.\n\n";
       cout << "Enter your choice ---> ";

       cin >> choice;

       if (1 <= choice && choice <= 5)
       {  
           switch (choice)
           {
           case 1:
               insert(root);
               printList(root);
               break;
           case 2:
               delCamera(root);
               printList(root);
               break;
           case 3:
               searchCamera(root);
               printList(root);
               break;
           case 4:
           insertionSort(&root);
               printList(root);
               break;
           default:
               cout << "Invalid choice. Enter again.\n\n";
               break;
           }
       }  
   }
   while (choice != 5);
   saveFile(root);
   return 0;
}

void readFile(CamLibraryPtr &root)
{
   int numCameras;
   string camName;
   int price1,price2,price3;
   ifstream infile("Inventory.txt", ios::in);
   infile >> numCameras;
   infile.ignore(500,'\n');
   for (int count = 0; count < numCameras; count++)
   {
       getline(infile, camName, '\n');
       getline(infile, price1, '\n');
       getline(infile,price2, '\n');
       getline(infile,price3, '\n');
       root = new CamLibrary(camName,price1,price2,price3,root);
   }
}

void insert(CamLibraryPtr &root)
{
   string camName;
   int price1,price2,price3;

   cout << "Camera Name:\t\t\t";
   cin.ignore(500,'\n');
   getline(cin, camName, '\n');
   cout << "Price 1:\t\t\t";
   getline(cin, price1, '\n');
   cout << "Price 2:\t\t";
   getline(cin,price2, '\n');
   cout << "Price 3:\t\t\t";
   getline(cin,price3, '\n');

   root = new CamLibrary (camName,price1,price2,price3, root);
}

void delCamera(CamLibraryPtr &root)
{
   string camName;
  
   cout << "Camera Name:\t\t\t";
   cin.ignore(500,'\n');
   getline(cin, camName, '\n');

   CamLibraryPtr p = locatecamera(root, camName);

   if (p == NULL)
       cout << "\nDeletion cannot be done.\n\n";
   else if (root == p)
       root = p->next;
   else
   {
       CamLibraryPtr q = root;
       while (q->next != p)
           q = q->next;
       q->next = p->next;
   }
   delete p;
}

CamLibraryPtr locatecamera(CamLibraryPtr temp, string camName)
{
   while (temp != NULL)
   {
       if (temp->cameraName == camName)
       {
           return temp;
       }
       temp = temp->next;
   }
   return NULL;
}

void searchCamera(CamLibraryPtr temp)
{
   string camName;

   cout << "Camera Name:\t\t\t";
   cin.ignore(500,'\n');
   getline(cin, camName, '\n');
  
   while (temp != NULL)
   {
       if (camName == temp->cameraName)
       {
           cout << temp->cameraName << "\n";
           cout << temp->price1 << "\n";
           cout << temp->price2 << "\n";
           cout << temp->price3 << "\n\n";
       }
       temp = temp->next;
   }
   cout << "\n";
}
void sortedInsert(struct CamLibrary** head_ref, struct CamLibrary* new_node)
{
struct CamLibrary* current;
/* Special case for the head end */
if (*head_ref == NULL || (*head_ref)->cameraName >= new_node->cameraName)
{
new_node->next = *head_ref;
*head_ref = new_node;
}
else
{
/* Locate the node before the point of insertion */
current = *head_ref;
while (current->next!=NULL &&
current->next->cameraName < new_node->cameraName)
{
current = current->next;
}
new_node->next = current->next;
current->next = new_node;
}
}

void saveFile(CamLibraryPtr temp)
{
   int count = countNodes(temp);
   ofstream outFile("list.txt",ios::out);
  
   outFile << count << "\n";
   while (temp != NULL)
   {
       outFile << temp->cameraName << "\n";
       outFile << temp->price1 << "\n";
       outFile << temp->price2 << "\n";
       outFile << temp->price3 << "\n";
       temp = temp->next;
   }
   cout << "\n";
}

int countNodes(CamLibraryPtr temp)
{
   int countB = 0;
   while (temp != NULL)
   {
       countB++;
       temp = temp->next;
   }
   return countB;
}
void insertionSort(struct CamLibrary **head_ref)
{
// Initialize sorted linked list
struct CamLibrary *sorted = NULL;
  
// Traverse the given linked list and insert every
// node to sorted
struct CamLibrary *current = *head_ref;
while (current != NULL)
{
// Store next for next iteration
struct CamLibrary *next = current->next;
  
// insert current in sorted linked list
sortedInsert(&sorted, current);
  
// Update current
current = next;
}
  
// Update head_ref to point to sorted linked list
*head_ref = sorted;
}

void printList(CamLibraryPtr temp)
{
   while (temp != NULL)
   {
       cout << temp->cameraName << "\n";
       cout << temp->price1 << "\n";
       cout << temp->price2 << "\n";
       cout << temp->price3 << "\n";
       temp = temp->next;
   }
   cout << "\n";
}



2 MiniPocketCamera 3 24 씹 15 5 12 6 Polaroid1StepCamera 7 49 8 10 9 20 10 Sonar1StepCamera 11 189 12 2 13 13 14 ProntoCamera Im in readfile ProntoCamera 74 15 Sonarlstepcamera 189 13 Polaroid1stepCamera 49 18 28 MiniPocketCamera 24 15 12 Menu: Selec

Menu: Select your option (1) Add a camera to the list (2) Delete a camera based on camera name (3) Search for a camera by cam

Menu: Select your option (1) Add a camera to the ї1st (2) Delete a camera based on camera name (3) Search for a camera by cam

Enter your choice Camera Name: arpitha 14 15 19 ---> 3 arpithaenu: Select your option (1) Add a camera to the list (2) Delete a camera based on camera name (3) Search for a camera by came

Add a comment
Know the answer?
Add Answer to:
C++ Write a program that keeps track of inventory The data is located in the file Inventory.txt. ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ General Description: For this project, you will write a program that keeps track of...

    In C++ General Description: For this project, you will write a program that keeps track of inventory for a camera store. The data is located in the file Inventory.txt on the S:\ drive. While the program is running, the information should be stored in a linked list. 1. The information for each item will be stored in a struct a. The definition will be in a separate file called item.h 2. The total inventory will be stored in a linked...

  • Use C++ For this week’s lab you will write a program to read a data file...

    Use C++ For this week’s lab you will write a program to read a data file containing numerical values, one per line. The program should compute average of the numbers and also find the smallest and the largest value in the file. You may assume that the data file will have EXACTLY 100 integer values in it. Process all the values out of the data file. Show the average, smallest, largest, and the name of the data file in the...

  • Accounting Question (Fringe Benefits) You are the Tax Director of a large public company. The CFO...

    Accounting Question (Fringe Benefits) You are the Tax Director of a large public company. The CFO is very frugal and is looking for fringe benefits that will be viewed favorably and provide incentives to employees and executives, but perhaps not cost the company very much. A consultant has provided the CFO a list of the following possible employee fringe benefits, and has claimed that all the benefits are tax free to the employee and deductible to the company. (He does...

  • Write a C program for: One technique for dealing with deadlock is called “detect and recover.” In...

    Write a C program for: One technique for dealing with deadlock is called “detect and recover.” In this scheme, some procedure is used to identify when a deadlock occurs, and then another procedure is used to deal with the blocked processes. One technique to identify a deadlock is to maintain a resource graph that identifies all processes, all resources, and the relationships between them (that is, which processes exclusively own which resources, and which processes are blocked waiting for which...

  • Write a c++ program: Many mathematical problems require the addition, subtraction, and multiplication of two matrices. Write an ADT Matrix. You may use the following class definition: const int MAX_RO...

    Write a c++ program: Many mathematical problems require the addition, subtraction, and multiplication of two matrices. Write an ADT Matrix. You may use the following class definition: const int MAX_ROWS = 10; const int MAX_COLS = 10; class MatrixType { public: MatrixType(); void MakeEmpty(); void SetSize(int rowsSize, int colSize); void StoreItem(int item, int row, int col); void Add(MatrixType otherOperand, MatrixType& result); void Sub(MatrixType otherOperand, MatrixType& result); void Mult(MatrixType otherOperand, MatrixType& result); void Print(ofstream& outfile); bool AddSubCompatible(MatrixType otherOperand); bool MultCompatible(MatrixType otherOperand);...

  • Digital world is a retail store that sells cameras and photography supplies the firms credit purchases...

    Digital world is a retail store that sells cameras and photography supplies the firms credit purchases and purchases returns and allowance transactions for June 2019 appear below along with the general ledger account used to record these transactions the balance shown in accounts payable is for the beginning of June. what amount is owed to nano glass on June 30? Digital World is a retail store that sells cameras and photography supplies. The firm's credit purchases and purchases returns and...

  • Digital world is a retail store that sells cameras in photography supplies the firms credit purchases...

    Digital world is a retail store that sells cameras in photography supplies the firms credit purchases and purchases returns and allowances transactions for June 2019 appear below along with the general ledger account used to record these transactions the balance shown in the accounts payable is for the beginning of June Digital World is a retail store that sells cameras and photography supplies. The firm's credit purchases and purchases returns and allowances transactions for June 2019 appear below, along with...

  • Please use own words. Thank you. CASE QUESTIONS AND DISCUSSION > Analyze and discuss the questions...

    Please use own words. Thank you. CASE QUESTIONS AND DISCUSSION > Analyze and discuss the questions listed below in specific detail. A minimum of 4 pages is required; ensure that you answer all questions completely Case Questions Who are the main players (name and position)? What business (es) and industry or industries is the company in? What are the issues and problems facing the company? (Sort them by importance and urgency.) What are the characteristics of the environment in which...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT