Hello, you should use C++ code to do this. It\'s begging of C++ course. using ar
ID: 3619655 • Letter: H
Question
Hello, you should use C++ code to do this. It's begging of C++ course. using arrays, structures, open in,out files, etc.If I completed this assignment I can get an 'A' for my class. If not, it will be a just B !!
Please help me out!!! *crying* , I'll give ya all my karma points if I can.
PLEASE !!!! YOU DON'T HAVE TO BE PERFECT BUT PLEASE TRY TO BE !!!!!
Please give me the codes !! help me out...
Following are the project description:
This program will compare two files for identical entries. Output will be written to three different output files: entry is in file 1 only, entry is in file 2 only or entry is in both input files. One entry consists of an id number (an integer) and an identifying phrase which is a single word.
When opening an input or output file, the user is continually prompted for a file name until one is successfully entered. Output of your program is to match that of the sample solution (which means to echo print out the file name entered). Once the files are opened, they are processed to determine if an entry in the first file is present in the second file. Output is written to the correct output file as determined by whether an entry is present in both files or just one. The program will handle empty input files as indicated by the sample solution (a message is output to the terminal and program continues for empty input files). If both input files are empty, all output files will be empty. NOTE: the input files are not processed (just opened) until after all files have been opened.
•Global variables are not allowed. Using global variables will result in a grade of 0. Incomplete programs will be given minimal credit if any.
•Five file stream variables (2 input, 3 output) are required.
•The first output file is for holding entries only in the first input file, the second output file is for holding entries in the second input file, and the third output file holds entries contained in both input files.
•Information written to the first two output files is the id of the entry and the entry name. For the third output file the information is the id from file 1, the entry name and the id from file 2. The output fields are a width of 6 for the id’s and a width of 25 for the name – all left justified.
•Information in one input file can be held in two separate one dimensional arrays – one for the id and one for the phrase of the entries. Or, a one-dimensional array of structures can be used to hold the id and phrase for each entry.
•Maximum number of entries to store is 300 (300 entries consisting of an id and a phrase)
•Processing the files is done with 2 nested loops. Outer loop provides the indexing for one input file and the inner loop provides the indexing for the other input file. Comparison is made inside the inner loop to determine if an entry is in both files.
•Easiest way to process the files is to find all common entries and entries that are only in the first input file (using the nested loop idea mentioned above). Then repeat the same code but swap the roles of the two input files and obtain those entries that are only in the second input file.
•Write a function that opens a single input file and use a static variable to keep track of how many input files have been opened. Repeat for opening of an output file. Then the open input file function is called twice and the open output file function is called three times.
•Write a function to read in the entries for one input file. Then call it twice – once for each input file.
<Project 11 Extra Extra Credit>
This applies to valid completed attempts only
• if you use a one dimensional array of structures to hold the information for each input file and use this array for all processing of the information you will receive an additional +5 points
• If you use a structure to hold all necessary file stream variables and use these structure members only for file stream operations you will receive an additional +3 points
• If you use functions that are meaningful and perform various necessary tasks, you will receive an addition +3 points (examples:OpenInputFile, OpenOutputFile, ReadFileInformation, ProcessFiles)
Explanation / Answer
please rate - thanks if you need any modifications message me best I could do without the answers to the questions I messaged you #include <iostream>#include <fstream>
#include<iomanip>
using namespace std;
struct sample
{int id;
string word;
bool found;
};
void openinput(ifstream&,int);
void openoutput(ofstream&,int);
void writedata(ofstream&, sample);
int main()
{sample input1[300],input2;
int count1=0,i;
bool empty2=true;
ifstream in1,in2;
ofstream out1,out2,out3;
openinput(in1,1);
openinput(in2,2);
openoutput(out1,1);
out1<<"id word ";
openoutput(out2,2);
out2<<"id word ";
openoutput(out3,3);
out3<<"id1 id2 word ";
in1>>input1[count1].id;
while(in1&&count1<300)
{in1>>input1[count1].word;
input1[count1].found=false;
count1++;
in1>>input1[count1].id;
}
if(count1==0)
out1<<"file 1 empty ";
in2>>input2.id;
while(in2)
{empty2=false;
in2>>input2.word;
for(i=0;i<count1;i++)
{if(input1[i].word.compare(input2.word)==0) //in both?
{out3<<setw(6)<<left<<input1[i].id<<setw(6)<<left<<input2.id<<setw(25)<<left<<input1[i].word<<endl;
input1[i].found=true;
i=count1+10;
}
}
if(i==count1)
writedata(out2,input2);
in2>>input2.id;
}
if(empty2)
out2<<"file 2 empty ";
for(i=0;i<count1;i++)
if(!input1[i].found)
writedata(out1,input1[i]);
out1.close();
out2.close();
out3.close();
in1.close();
in2.close();
system("pause");
return 0;
}
void writedata(ofstream& out, sample n)
{out<<setw(6)<<left<<n.id<<setw(25)<<left<<n.word<<endl;
}
void openinput(ifstream& in,int n)
{char filename[30];
cout<<"what is the name of input file "<<n<<" you are using? ";
cin>>filename;
cout<<"file name entered: "<<filename<<endl;
in.open(filename);
while(in.fail())
{ in.clear();
cout<<"input file did not open please check it ";
cout<<"what is the name of input file "<<n<<" you are using? ";
cin>>filename;
cout<<"file name entered: "<<filename<<endl;
in.open(filename);
}
}
void openoutput(ofstream& out,int n)
{char filename[30];
cout<<"what is the name of output file "<<n<<" you are using? ";
cin>>filename;
cout<<"file name entered: "<<filename<<endl;
out.open(filename);
while(out.fail())
{out.clear();
cout<<"output file did not open please check it ";
cout<<"what is the name of output file "<<n<<" you are using? ";
cin>>filename;
cout<<"file name entered: "<<filename<<endl;
out.open(filename);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.