Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Do not use arrays or tables, functions are not required. Please show comments in

ID: 3882323 • Letter: D

Question

Do not use arrays or tables, functions are not required. Please show comments in code.

Use a file called Stock.txt (I'll write the actual file down below) that contains information regarding the 9 different stock items carried by GROCERY INC. The file is a repeating sequence of three records such that

the first record represents an item code number,

the second record represents the description of each item

and the third record contains the current selling price.

Then the sequence repeats. Your program is to simulate the checkout register allowing the check out clerk to input item codes to obtain the current selling prices and descriptions. If an incorrect code is entered, the clerk should be notified by an appropriate message on the screen. If the item is found, the clerk will enter the number of items with that description and price and continue to the next item. When all items have been entered the clerk terminates the transaction by entering an item code of 0 (zero).

The program will build a sales slip called Sales.txt (output file) enumerating the item code, description, unit price, quantity purchased, and total extended price. The bill will be subtotaled and an 8% sales tax added for a final total. Amount tendered by the customer and change given will be finally added to the invoice. This invoice should be written out to an output file called Sales.txt. The final total and change should appear on the screen as well.


Your output file should line up all columns and output formatted for dollars and cents on money amounts, using setprecision, showpoint, and fixed. Make sure you format your output to the screen as well.
Do not use arrays or tables.

stock.txt (input file):

1234
Stockings
12.39
2865
Pajamas
17.99
4020
Dress
23.00
3640
Sweater
20.50
5109
Shorts
56.99
4930
TV
88.20
6600
ToothBrush
94.55
5020
AluminumPan
16.79
2336
Pencils
4.55

Explanation / Answer

#include <stdio.h>

#include <cstdlib>
#include<iostream>
#include<iomanip>
#include<fstream>
#include<string.h>


using namespace std;

struct product {
int code;
string Description;
float sellingPrice;
};

int main(int argc, char** argv) {
int codeNumber; //for accepting input
std::ifstream is("in.txt", std::ifstream::binary);//input file
std::ofstream os("sales.txt", std::ofstream::binary | std::ofstream::out);//outputfile
product p; //declare the variable for structure
bool Cont = true; // to check the user has input.
bool found = false; //to check the itemcode found in the file
int numberOfItem; //for accepting the number of items to sold
float totalAmount = 0; //for calculating the total
//for formatting the file with header
os << "CODE";
os.width(20);
os << "DEscription";
os.width(20);
os << "Selling Price";
os.width(10);
os << "numberOfItem";
os.width(15);
os << "TotalPrice";
os << " " << " ";

//if the file exist the opens the file
if (is) {
while (Cont) {//continues until the user enters 0 for itemcode
//prompts the user for item code
cout << " Enter the product id :";
cin>>codeNumber;
  
//if the code enter is 0 then exit from the loop
if (codeNumber == 0)
Cont = false;
//moves the pointer the beginning of the file
is.seekg(0, is.beg);
//performs the loop until eof or user enters 0
while (!is.eof() && Cont) {

is >> p.code;
is >> p.Description;
is >> p.sellingPrice;
if (codeNumber == p.code) { //checks the code with file itemcode
found = true;
break;


}

}
//if item code has been found then write the data into the file
if (found && Cont) {
cout << " Enter the number of item :";
cin>>numberOfItem;
os << p.code;
os.width(20);
os << p.Description;
os.precision(2);
os.width(20);
os.showpoint;
os << p.sellingPrice;
os.width(10);
os << numberOfItem;
os.precision(5);
os.width(15);
os.showpoint;
os << (numberOfItem * p.sellingPrice);
os << " " << " ";
totalAmount = totalAmount + (numberOfItem * p.sellingPrice);
found = false;

} else if (Cont) { //if item code not found
cout << " Sorry!! item not found.";
}


}

//write the amount, tax amount to the file
os << " The Amount :" << totalAmount;
os << " The tax Amount :" << (totalAmount * .08);
os << " The total amount to be paid :" << totalAmount + (totalAmount * .08);

//close the file
is.close();
os.close();

}

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote