#include<iostream>
#include<fstream>
#include<cstdlib>
#include<iomanip>
using namespace std;
int main()
{
ifstream in_stream; // reads ITEMSLIST.txt
ofstream out_stream1; // writes in listWititems.txt
ifstream in_stream2; // reads PRICELIST.txt
ofstream out_stream3;// writes in listWitprices.txt
ifstream in_stream4;// read display.txt
ofstream out_stream5;// write showitems.txt
double p1=0.0,p2=0.0;
int wrong=0;
int count =0;
char next;
in_stream.open("ITEMLIST.txt", ios::in); // list of avaliable items
/*if( in_stream.fail() )// check to see if itemlist.txt is open
{
wrong++; // counts number of errors
cout << " the error occured here0, you have " << wrong++ << " errors" << endl;
cout << "Error opening the file\n" << endl;
exit(1);
}
else{
cout << " System ran correctly " << endl;
}
*/
out_stream1.open("listWititems.txt", ios::out); // list of avaliable items
/* if( out_stream1.fail() )// check to see if itemlist.txt is open
{
wrong++;
cout << " the error occured here0, you have " << wrong++ << " errors" << endl;
cout << "Error opening the file\n" << endl;
exit(1);
}
else{
cout << " System ran correctly " << endl;
}
*/
in_stream2.open("PRICELIST.txt", ios::in);
/*if( in_stream2.fail() )// check to see if itemlist.txt is open
{
wrong++;
cout << " the error occured here0, you have " << wrong++ << " errors" << endl;
cout << "Error opening the file\n" << endl;
exit(1);
}
else{
cout << " System ran correctly " << endl;
}
*/
out_stream3.open("listWitdollars.txt", ios::out);
/*if( out_stream3.fail() )// check to see if itemlist.txt is open
{
wrong++;
cout << " the error occured here0, you have " << wrong++ << " errors" << endl;
cout << "Error opening the file\n" << endl;
exit(1);
}
else{
cout << " System ran correctly " << endl;
}
*/
in_stream4.open("display.txt", ios::in);
/*if( in_stream4.fail() )// check to see if itemlist.txt is open
{
wrong++;
cout << " the error occured here0, you have " << wrong++ << " errors" << endl;
cout << "Error opening the file\n" << endl;
exit(1);
}
else{
cout << " System ran correctly " << endl;
}
*/
out_stream5.open("showitems.txt", ios::out);
/*if( out_stream5.fail() )// check to see if itemlist.txt is open
{
wrong++;
cout << " the error occured here0, you have " << wrong++ << " errors" << endl;
cout << "Error opening the file\n" << endl;
exit(1);
}
else{
cout << " System ran correctly " << endl;
}*/
in_stream.setf(ios::fixed);
while(!in_stream.eof()) // reads to end of file and gets p1 which is itemnum, clears and gets next character
{
in_stream >> p1;
cin.clear();
cin >> next;
}
out_stream1.setf(ios::fixed);
while (!out_stream1.eof())
{
out_stream1 << p1;
cin.clear();
cin >> next;
}
in_stream2.setf(ios::fixed);
in_stream2.setf(ios::showpoint);
in_stream2.precision(2);
while(!in_stream2.eof()) // reads file to end of file
{
in_stream2 >> p1 >> p2 >> count; // gets p1,p2, and count which is current total
in_stream2 >> p2;
p1 += p2;
p2++;
cin.clear(); // allows more reading
cin >> next;
return p1, p2;
}
out_stream3.setf(ios::fixed);
out_stream3.setf(ios::showpoint);
out_stream3.precision(2);
while(!out_stream3.eof()) // reads file to end of file
{
out_stream3 << p1 << p2 << count;
out_stream3 << p2;
p1 += p2;
p2++;
cin.clear(); // allows more reading
cin >> next;
return p1, p2;
}
in_stream4.setf(ios::fixed);
in_stream4.setf(ios::showpoint);
in_stream4.precision(2);
while (!in_stream4.eof())
{
in_stream4 >> p1 >> p2 >> count;
cin.clear();
cin >> next;
}
out_stream5.setf(ios::fixed);
out_stream5.setf(ios::showpoint);
out_stream5.precision(2);
out_stream5 <<setw(5)<< " itemnum " <<setw(5)<<" price "<<setw(5)<<" curr_total " <<endl; // sends items and prices to receipt.txt
out_stream5 << setw(5) << p1 << setw(5) <<p2 << setw(5)<< count; // sends items and prices to receipt.txt
out_stream5 << " You have a total of " << wrong++ << " errors " << endl;
in_stream.close(); // closing files.
out_stream1.close();
in_stream2.close();
out_stream3.close();
in_stream4.close();
out_stream5.close();
system("pause");
}