Question

This is C++ Note, for part 2 of this assignment, you DO NOT NEED to use...

This is C++

Note, for part 2 of this assignment, you DO NOT NEED to use arrays or vectors. All changes, calculations, etc should be performed in place ( in the file). You may need one or two structures that temporary hold data needed to be displayed, changed, etc.

Part 2: Binary Files

Write a program that uses a structure to store the following inventory data in a file: The data can be either read from a text file or the keyboard

  • Item name (string)
  • Quantity on hand(int)
  • Wholesale cost(double)
  • Retail Cost(double)

The program should have a menu that allows the user to perform the following tasks:

  1. Add new records to the file
  2. Display any record in the file
    1. User will provide the name of the item or the first n letters of the name of the item
  3. Change any record in the file (Note: if this option chosen, then the whole record must be reentered even if the user wants to change only one or more fields)
  4. Display all records
  5. Prepare a report containing:
    1. The total wholesale value of the inventory
    2. The total retail value of the inventory
    3. The total quantity of all values in the inventory.

Input validation: The program should not accept quantities or wholesale or retail costs less than 0.

Homework Answers

Answer #1

#include<iostream>
#include<fstream>
#include<string>

using namespace std;

class NODE{
   private:
       string name;// to store name
       int qty;// number of quantity
       double wholecost;// wholesale value
       double retailcost;// retail value
   public:
      
       // constructor
       NODE(){
           name="";
           qty=0;
           wholecost=0;
           retailcost=0;
       }  
      
       // constructor with arguments
       NODE(string a,int b,double c,double d){
           name=a;
           qty=b;
           wholecost=c;
           retailcost=d;
       }
      
       // setter
       void setName(string nm){name=nm;}
       void setQty(int q){qty=q;}
       void setWholeCost(double c){wholecost=c;}
       void setRetailCost(double c){retailcost=c;}
      
       // getter
       string getName(){return(name);}
       int getQty(){return(qty);}
       double getWholeCost(){return(wholecost);}
       double getRetailCost(){return(retailcost);}
      
      
};


// linked list node
class LinkedNode{
   private:
   NODE *data;// data
   LinkedNode *next;// next link
   public:
       // constructor
       LinkedNode(){
           data=NULL;
           next=NULL;
       }
      
       LinkedNode(string a,int b,double c,double d){
           data=new NODE(a,b,c,d);
           next=NULL;
       }
      
       // setter
       void setData(NODE *n){data=n;}
       void setNext(LinkedNode *l){next=l;}
      
       // getter
       NODE* getData(){return(data);}
       LinkedNode* getNext(){return(next);}
};

// linked list
class LinkedList{
   private:
       // root node
       LinkedNode *root;
   public:
       // constructor
       LinkedList(){
           root=NULL;
       }
      
       // add data in linked list
       void add(string a,int b,double c,double d){
           LinkedNode *node=new LinkedNode(a,b,c,d);
           node->setNext(root);
           root=node;
       }
      
       // find by name or first n characters
       LinkedNode* findByName(string nm){
           LinkedNode *cur=root;
           while(cur!=NULL){
               size_t found=cur->getData()->getName().rfind(nm);
               if(found!= string::npos){
                   return cur;
               }
               cur=cur->getNext();
           }
           return NULL;
       }
      
       // display list
       void display(){
           LinkedNode *cur=root;
           int i=0;
           while(cur!=NULL){
               cout<<"Record "<<(i+1);
               cout<<"\nItem name : "<<cur->getData()->getName();
               cout<<"\nTotal wholesale value is "<<(cur->getData()->getWholeCost()*cur->getData()->getQty());
               cout<<"\nTotal retail value is "<<(cur->getData()->getRetailCost()*cur->getData()->getQty());
               cout<<"\nTotal quantity is "<<cur->getData()->getQty()<<endl;
               cur=cur->getNext();
           }
       }
};

int main(){
   LinkedList ll;
  
   while(1){
      
       // menu
       cout<<"1) Add record";
       cout<<"\n2) Display record by name";
       cout<<"\n3) Display records";
       cout<<"\n4) Exit";
       cout<<"\nUser choice : ";
      
       int choice;
       cin>>choice;
      
       // choise between 1 to 4
       if(choice>=1 && choice<=4){
           if(choice==1){
               cout<<"Enter name : ";
               string a;
               cin>>a;
               cout<<"Enter number of quantity : ";
               int b;
               cin>>b;
               cout<<"Enter Wholesale Cost : ";
               double c;
               cin>>c;
               cout<<"Enter Retail Cost : ";
               double d;
               cin>>d;
              
               ll.add(a,b,c,d);
               cout<<"\nData Added\n";
           }
           if(choice==2){
               cout<<"Enter name : ";
               string a;
               cin>>a;
               LinkedNode* ln=ll.findByName(a);
               if(ln!=NULL){
                   cout<<endl<<ln->getData()->getName();
                   cout<<"\nWholesale value is "<<(ln->getData()->getWholeCost());
                   cout<<"\nRetail value is "<<(ln->getData()->getRetailCost());
                   cout<<"\nQuantity is "<<ln->getData()->getQty()<<endl;      
               }
               else{
                   cout<<"\nNo record found.\n";
               }
           }
           if(choice==3){
               ll.display();
           }
           if(choice==4){
               break;
           }
       }else{
           cout<<"Please choose correct option.\n";
       }
   }
  
   cout<<"\nProgram End.\n";
  
   return 0;
}

Know the answer?
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
Similar Questions
Each part of this lab will use the same input file, named “lab3-in.dat.” This file will...
Each part of this lab will use the same input file, named “lab3-in.dat.” This file will be located in the same directory as the executables (do not specify a path for the file in the Select statements). This file is a roster of animals in a travelling carnival. The record format for the file is as follows: Field Description Length Data Type Name 12 String Gender 1 String Species 15 String The end result of each part of this assignment...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
I cannot upload the needed text files to this question for your benefit of double checking...
I cannot upload the needed text files to this question for your benefit of double checking your solution, but I need help on this multi part question. Thanks! Write a Python program that will open the ‘steam.csv’ file. Your program should load the data as col- umns corresponding to the variable names located in the first row (You can hard code this – i.e open the file and use the names in the first row as variable names). You should...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
C Programming. Do not use a function in the solution. Assignment 6 This assignment focuses on...
C Programming. Do not use a function in the solution. Assignment 6 This assignment focuses on using arrays. Instructions Create a program called arrays.c that does the following: 1. Prompt the user for a string (<= 100 characters). (using the attached file: AS06Data.txt) AS06Data.txt file contains the text " Instructions: When your executing program displays "Enter string 1:" starting with T, select the line of text below, copy with ctrl-c, then type ctrl-v THIS IS a test of string 0123456789...
C++ Part B: (String) Program Description: Write a word search program that searches an input data...
C++ Part B: (String) Program Description: Write a word search program that searches an input data file for a word specified by the user. The program should display the number of times the word appears in the input data file. In addition, the program should count and display the number of grammatical characters in the input data file. Your program must do this by providing the following functions : void processFile(ifstream &inFile, string wordSearch, int &wordCount, int &grammaticalCount) ; (15%)...
You are to write a C++ program to produce an inventory report for a local company....
You are to write a C++ program to produce an inventory report for a local company. Your input will be item name, item number, quantity, price per item, safe stock value. The following shows which columns the input will be in: item name             item number         quantity                  price                      safe stock 20 chars                 5 char                     3 char                      6 chars                 3 chars Output will be as follows: item number         item name    quantity   price     price*quantity   %ofStock    flag You will put a symbol in the...
PLEASE DO QUICK LINUX ASSIGNMENT PLEASE ILL THUMBS UP You need to paste the command and...
PLEASE DO QUICK LINUX ASSIGNMENT PLEASE ILL THUMBS UP You need to paste the command and the output in a word document and submit it. Part1: 1. Log in to Linux using your user account name and password. 2. If you logged in using a graphical login screen, open a terminal window by clicking on the icon in the lower left corner of the desktop to open the main menu, then selecting System Tools, then Terminal. A terminal window opens....
The first script you need to write is login.sh, a simple script that you might run...
The first script you need to write is login.sh, a simple script that you might run when you first log in to a machine. We'll expand this script later, but for now it should include your name, username, hostname, current directory, and the current time. Here is some sample output to help guide you. Note that the bolded lines that start with "[user@localhost ~]$" are the terminal prompts where you type in a command, not part of the script. Of...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT