Could someone help me understand this? I'm really new to c++ and have no idea where to even start so here is the problem my teacher has given me.
"XML is a standard for representing documents and data stores in a textual format. XML is very web friendly and is becoming a defacto standard for transmitting data between programs using http or https. XML is also often used as an intermediate format for translating data from disparate systems. Note that many languages provide "toolkits" to manipulate xml and databases as a datatype unto itself. We will not be using "XMLReader" and "XMLWriter" toolkits, but rather produce brute force XML in a text file as output. Brute force XML will still be a valid XML file.
For example, there is little coding difference between
Outputfile << "The price is " << price << "dollars." << endl;
Both produce text output in a file, but the later can be interpreted as XML, That is brute force XML.
Write a C++ program which uses filestreams to read data from two text sequential data files and writes a XML file combining data from both files as described below. but rather produce brute force XML in a text file as output. Since we are not doing any math with the input values, conversion of file input values to numeric data types will not be required.
The file ITEMS.DAT is a fixed field length text file with the following format:
Columns Description
1- 8 Part Number
6 Color code imbedded in part number
9-26 Item description
27-34 Price in format 9999.99
36-45 Available Date in format 12/31/2016
46 end of line marker
Color codes are 1=Red, 2=Blue, 3=White, 4=Black
You will need to convert the color code into a color name for the XML file.
The CUSTOMER.pip file is a pipe delimited text file containing
lastname|firstname|partnumber|TransactionDate
the TransactionDate is in the form MM/DD/YYYY, for example 10/21/2016
Read data from ITEMS.DAT and CUSTOMER.pip to create a file named Transactions.XML with the structures detailed below. Sample input files should produce the XML output below. Your program should react to any input files and produce an XML file appropriate to the input data. Note that leading or trailing spaces on the extracted input data are acceptable at this point in the course.
ITEMS.DAT
PC12K2RTUsed Car 02350.00m412/31/2016
CUSTOMER.pip
Bright|Rich|PC12K2RT|10/21/2011
Your program must generate the following Transactions.XML file.
I would start with creating a struct Item and read it from the file items.dat.
Then I would create a struct Customer and read it from customer.zip.
Finally you write some code to output Item and Customer to XML and write it to transactions.xml
I don't mean write it for me. I can't learn anything that way. I don't understand what XML files are. do I have to make an XML file and if so how do I do that.
The job is pretty much what your brief says. Read some date from the file(s) which are in a set format, convert the data read in to xml tagged lines and save those to another file.
Your first job is just getting the program to read in and coordinate the two files.
Once you've got control over those strings you add tags <> etc to the front and back of the strings, then save them to the output file.
The data is structured so, as said above, struct's are ideal.
xml files are just text files with tags, like HTML.
the tags look like this:
<tag> data of any sort </tag>
where /tag means close the tag, without opens it.
think of them as {} in C++ ... begin/end markers of a sort. They can be nested more or less indefinitely.
you do need to write an xml file, this appears to be the desired output of your code project. But don't be afraid of it, its just a formatted text file with a goofy name.
notepad++ is one of many tools that can check simple xml files and help you read them and validate your work. You may need to install an extension but its all free and works pretty well.
Start by opening the two files and reading each line by line, and then printing out each line.
Use the tutorials here if you don't know how to do that. The sample data is given to you above. Use notepad to make the files. Maybe write a few extra sample lines following the pattern of the samples in each case.
Write the code for that and show us then we can discuss the next step. Up to you.
here is what I have so far. Not sure if i need a log file or anything but I really do not understand any of this so this is my attempt of getting the code ready then moving on to the files
// Program2.cpp : Defines the entry point for the console application.
//4/6/17
If you don't understand what's going on then that indicates to me you need to spend some study time on the question you are given and having a look in the tutorials here, your class notes etc.
By now you should have a plan. If you haven't then the best thing to do is write one with 5 or 6 steps so you know where you are going. You have enough information to do it. Don't write more code until the plan is done.
Here's a bit more of a start. It is by no means complete and you will have to find a way to break up the lines in the data files into meaningful parts and cross-referencing items vs customers. 'delimiters' and sub-strings are useful things to find out about in breaking down the lines. The assignment brief gives relevant details.
Okay, I am also in the class. And I have most of the code done, but I am running into a "Unhandled exception at at 0x776FA882 in ConsoleApplication25.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0093EDF4." Could someone help me figure out just where my problem is, and how to go about solving it? The project is due tonight, and I would have posted sooner but have been solving little problems here and there. Thanks so much!
Okay, I've determined that my problem lie in this line of code, customerInfo=customerInfo.substr(nextPipePosition+0,customerInfo.length()-nextPipePosition+0);
I suggest you write a short test program with a hard coded source string, devoted to testing just that expression. Print out each variable value for the substring locations etc, comparing what you expect with what you get.
A small observation, why are you adding zero in the expression?