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

Question: C++ open the input file file, READ ALL THE VALUES INTO THREE PARALLEL

ID: 3721884 • Letter: Q

Question

Question: C++ open the input file file, READ ALL THE VALUES INTO THREE PARALLEL ARRAYS, then close the input file. When the user gives you a stock number you should search the arrays for the match and the corresponding description and price.

C++

************(PLEASE READ THE ENTIRE DIRECTIONS BEFORE TRYING TO ANSWER)*************

*************************************************************************************************
*************************************************************************************************

Somebody Please Please Please Help me with this... I have done a lot of the work just need to get everything in the correct spot. We CAN NOT use Strings!!!!!

The Items Description MUST BE read into a Char array... I am assuming with getline().

Instead of opening and closing the input file for each requested item, open the stock.txt file, READ ALL THE VALUES FOR THE 9 STOCK ITEMS INTO THREE PARALLEL ARRAYS, then close the input file. When the user gives you a stock number you should search the arrays for the match and the corresponding description and price.

Use a file called Stock.txt that contains information regarding the 9 different stock items carried by DOLLAR SAVER INCORPORATED. 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 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.
This assignment uses file processing found in chapter 5 and arrays found in chapter 7 of Starting Out With C++.

I just can't grasp this to figure out what I am doing wrong. Any and all help is greatly appreciated and if you can help me figure it out I will review you to fullest extent possible.

Thank You in Advance.

Input file:

stock.txt

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

My code so far:

#include

#include

#include

#include

using namespace std;

const int NUM_ITEMS = 9;

const int MAX_STRING_SIZE = 20;

int itemNum_Array[9];

char description_Array[9][20];

double price_Array[9];

int i,x;

int main ()

{

int itemNumber;   

int itemNum;

string description;

float price;

int amt;

float total = 0;

float subtotal;

ofstream outputFile( "Sales.txt" );

outputFile << "FUNNY STUFF RETAIL, INC." << endl;

outputFile << endl;

  

ifstream inputFile;

  

inputFile.open("Stock.txt");

  

int indexCount;

indexCount = 0;

const int AR_SIZE = 9;

while (inputFile && indexCount < AR_SIZE)

{

inputFile >> itemNum[indexCount];

cin.ignore(100,' ');

getline(inputFile, description[indexCount]);

cout << endl;

inputFile >> price[indexCount];

cin.ignore(100,' ');

indexCount++;

}

}

if ( !inputFile )

{

cout << "The file (stock.txt) Failed to open." << endl;

return 0;

}

for (int x = 0; x < 9; x++)

{

inputFile >> itemNum_Array[x] >> description_Array[x] >> price_Array[x];

}

inputFile.close();

while( true )   

{

cout << "Please give me an item number that you would like me to look up ? (0 when done)" << endl;

cin>> itemNum;

if ( itemNum == 0 ) break;   

bool found = false;   

for (int i = 0; i < 9; i++){

if (itemNum == itemNum_Array[i])

{

found = true;

break;

}

}

if ( found )

{

cout << fixed << showpoint << setprecision (2);

cout << "Item number : " << itemNum << " is pulling up : " << description << ", at $" << price << " per Item." << endl;

cout << "How many " << description << " would you like to purchase? " << endl;

cin >> amt;

total = total + ( amt * price );

found = false;

outputFile << "Item Number : " << itemNum << endl;

outputFile << "Item Description : " << description << endl;

outputFile << "Price per Item : $" <

outputFile << "Amount Purchased : " << amt << endl;

outputFile << "Item Subtotal : $" << (amt * price) << endl;

outputFile << endl;

cout << "OK, I've added " << amt << " " << description << " to your order." << endl;

}

else

{

cout << "I'm sorry, but we do not appear to carry that item in stock." << endl;

}

  

}

outputFile << fixed << setprecision( 2 );

cout << fixed << setprecision( 2 );

cout << fixed << showpoint << setprecision (2);

outputFile << "Combined Subtotal : $" << total <

subtotal = total;

outputFile << fixed << showpoint << setprecision (2);

outputFile << "Tax : $" << (total * .08)<

total = total + (total * .08);

outputFile << fixed << showpoint << setprecision (2);

outputFile << "Total : $" << total <

cout << fixed << showpoint << setprecision (2);

cout << "Your total comes to : $" << total << endl;

cout << "How much would you like to pay? " << endl;

float money, moreMoney, change;

cin >> money;

while ( money + moreMoney <= total )

{

cout << "I'm sorry, but that is not enough money to cover the total. How much more are you going to pay : ";

cin >> moreMoney;

}

change = money - total;

outputFile << fixed << showpoint << setprecision (2);

outputFile << "Amount Tendered : $" << money + moreMoney <

change = money + moreMoney - total;

cout << "Your change is : $" << change << endl;

outputFile << "Your change is : $" << change << endl;

cout << fixed << showpoint << setprecision (2);

cout << "Your change is : $" << change << endl;

outputFile << endl;

outputFile << "Thank You for Shopping with Us" <

outputFile << "Have a Great Day !" <

outputFile.close();

return 0;

}

Explanation / Answer

Given below is the fixed code along with output.... It generates output file Sales.txt. Please do rate if it helped. Thank you

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

const int NUM_ITEMS = 9;
const int MAX_STRING_SIZE = 20;

int i,x;

int main ()

{
  
int itemNumber[NUM_ITEMS];
char description[NUM_ITEMS][MAX_STRING_SIZE];
float price[NUM_ITEMS];

int num;
  
  
int qty;
float total = 0;
float subtotal, tax;
  
ofstream outputFile( "Sales.txt" );
  
outputFile << "FUNNY STUFF RETAIL, INC." << endl;
outputFile << endl;
  
  
  
ifstream inputFile;
inputFile.open("Stock.txt");
  
if(inputFile.fail())
{
cout << "Error: could not open input file Stock.txt" << endl;
return 1;
}
  
int count = 0;
  
  
cout << "Item Numbers in file" << endl;
while (count < NUM_ITEMS && inputFile >> itemNumber[count])
{
  
inputFile.ignore(100,' ');
inputFile.getline(description[count], MAX_STRING_SIZE);
  
inputFile >> price[count];
inputFile.ignore(100,' ');
cout << itemNumber[count] << endl;
count++;

}
inputFile.close();
  
//set the precision in the beginning before any output
cout << fixed << showpoint << setprecision (2);
outputFile << fixed << showpoint << setprecision(2);
  
while( true )
{
  
cout << "Please give me an item number that you would like me to look up ? (0 when done)" << endl;
cin>> num;
  
if ( num == 0 ) break;
  
int index = -1;
  
for (int i = 0; i < count; i++){
  
if (num == itemNumber[i])
{
  
index = i;
break;
}
}
  
if ( index != -1 ) //found
{
  
  
cout << "Item number : " << itemNumber[index] << " is pulling up : " << description[index] << ", at $" << price[index] << " per Item." << endl;
  
cout << "How many " << description[index] << " would you like to purchase? " << endl;
cin >> qty;
  
subtotal = qty * price[index];
total += subtotal;
  
outputFile << "Item Number : " << itemNumber[index] << endl;
outputFile << "Item Description : " << description[index] << endl;
outputFile << "Price per Item : $" << price[index ] << endl;
outputFile << "Quantity Purchased : " << qty << endl;
outputFile << "Item Subtotal : $" << subtotal << endl;
outputFile << endl;
  
cout << "OK, I've added " << qty << " " << description[index] << " to your order." << endl;
  
}
else
{
cout << "I'm sorry, but we do not appear to carry that item in stock." << endl;
}
  
}
  
  
  
outputFile << "Combined Subtotal : $" << total << endl;
subtotal = total;
tax = 0.08 * subtotal;
total = subtotal + tax;
  
outputFile << "Tax : $" << tax << endl;
outputFile << "Total : $" << total << endl;
cout << "Your total comes to : $" << total << endl;
  
cout << "How much would you like to pay? " << endl;
  
float money, moreMoney = 0, change;
cin >> money;
  
while ( money + moreMoney < total )
{
  
cout << "I'm sorry, but that is not enough money to cover the total. How much more are you going to pay : ";
cin >> moreMoney;
}
money += moreMoney;
change = money - total;
  
outputFile << "Amount Tendered : $" << money << endl;
  
cout << "Your change is : $" << change << endl;
outputFile << "Your change is : $" << change << endl;
  
  
outputFile << endl << "Thank You for Shopping with Us" << endl;
outputFile << "Have a Great Day !" << endl;
outputFile.close();
  
return 0;
  
}
  


input file: Stock.txt
====================
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


output
======
Item Numbers in file
1234
2865
4020
3640
5109
4930
6600
5020
2336
Please give me an item number that you would like me to look up ? (0 when done)
4020
Item number : 4020 is pulling up : Dress, at $23.00 per Item.
How many Dress would you like to purchase?
2
OK, I've added 2 Dress to your order.
Please give me an item number that you would like me to look up ? (0 when done)
6000
I'm sorry, but we do not appear to carry that item in stock.
Please give me an item number that you would like me to look up ? (0 when done)
2865
Item number : 2865 is pulling up : Pajamas, at $17.99 per Item.
How many Pajamas would you like to purchase?
4
OK, I've added 4 Pajamas to your order.
Please give me an item number that you would like me to look up ? (0 when done)
0
Your total comes to : $127.40
How much would you like to pay?
100
I'm sorry, but that is not enough money to cover the total. How much more are you going to pay : 50
Your change is : $22.60

output file generated: Sales.txt
===============
FUNNY STUFF RETAIL, INC.

Item Number : 4020
Item Description : Dress
Price per Item : $23.00
Quantity Purchased : 2
Item Subtotal : $46.00

Item Number : 2865
Item Description : Pajamas
Price per Item : $17.99
Quantity Purchased : 4
Item Subtotal : $71.96

Combined Subtotal : $117.96
Tax : $9.44
Total : $127.40
Amount Tendered : $150.00
Your change is : $22.60

Thank You for Shopping with Us
Have a Great Day !

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