I'm still a beginner at c++ and i'm required to write a program that compares two files, an orders.txt and dictionary.txt that
1.)validates orders, if correct send to valid.txt
and
2.)review invalid orders and either correct the order if it is different by two or less orders, if three or more sent it to invalid.txt
3.)supply correction %
Problems I'm having:
Dictionary.txt is set up as
Component 1 = {AAAAC or AAAAB or AAAAD}
Component 2 = {CCCC5 or CCC14}
etc.
Orders.txt is set up as
AAAAC BBBBE CCCC5 ABCD4 QQQ3R ERFG8
AAAAB CCC14 QQQQD ZZZZ4 ZE_B12
AAAAC BBBBE CCCC5 ABCD4 QQQ3R ERFG8 PPP14 REWD2
etc.
-I need to extract just the order "AAAAC" from dictionary and store it into a variable. If i use getline to loop through the file it has to be a string, it can't be a char array therefor a can't use strtkn and also can't use a char array to compare individual characters.
-Also I don't know how to output the valid.txt in the same fashion it was given in. The way i currently have it, it appends to one continuous line instead of a
'/n' after the item "ERFG8" to go to the next line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;
int main()
{
string strOrders;
string strDictionary;
ifstream orders;
int pos;
ofstream valid;
bool found=false;
int iNum1=0;
orders.open("Orders.txt");
while(getline(orders,strOrders,' '))
{
found = false;
ifstream dictionary;
dictionary.open("Dict_Orig.txt");
while(getline(dictionary,strDictionary) && found == false)
{
if(pos=strDictionary.find(strOrders))
{
if (pos != -1)
{
valid.open("Valid.txt", ios::out | ios::app);
valid<<strOrders<<" ";
valid.close();
found = true;
}
else
{
string subStringOrder;
subStringOrder=strDictionary.substr(pos);
}
}
}
}
system("PAUSE");
return 0;
}
|