I am extremely new to C ++ (and generally programming in general), and I'm working on a project that puzzled me (it's not hard to make ha). The project includes direct access files. We must create a file consisting of a series of part records. Here are some of the features:
Must contain a header record (24 bytes filled) indicating the number of valid elements.
Each record (24 bytes) will contain the stock number (maximum 4 digits), description (maximum 8 characters), counter (4 digits) and the indicator of the “test part” (4 digits max => -1 - end of file).
Initially, this file will contain 20 empty (dummy) entries and will be created sequentially.
Once the file has been created, a sequential text file update will be available based on stock numbers and new entries will be inserted into the file.
When the update is completed, the valid part records will be printed in order, starting from the stock record "1".
Refresh by reading the text update file (prog4.dat) and finding the file position based on the stock number (do not forget the header entry)
For instance:
Initial (empty)
Input (updates)
1 widgits 25 3
6 gidgits 12 8
8 kidgits 6 -1
3 didgits 11 6
Output
1 widgits 25
3 didgits 11
6 gidgits 12
8 kidgits 6
I don’t know anything about direct access files, so I looked at a couple of different links that I found on Google ( http://cee-ux49.cee.illinois.edu/cee490/public_html/pdfs_vgs/aL23_Direct_Access_Files.pdf and http: // www .learncpp.com / cpp-tutorial / 137-random-file-io / ), but it's hard for me to figure out how to make this work for this particular program.
, , , , , , , , ( , , , , (, ?)), .
#include <iostream>
#include <string>
#include <fstream>
#include <stream>
using namespace std;
class records {
public:
int getStckNumber() {
return stockNumber;
}
void setStockNumber(int stockNum) {
stockNumber = stockNum;
}
string getItemDespcription() {
return itemDescription;
}
void setItemDespcription(string itemDescrip) {
itemDescription = itemDescrip;
}
int getItemAmount() {
return itemAmount;
}
void setItemAmount(int itemAmt) {
itemAmount = itemAmt;
}
int getNext() {
return next;
}
void setNext(int nxt) {
next = nxt;
}
private:
int stockNumber;
string itemDescription;
int itemAmount;
int next;
int recNum;
}
int main() {
int stockNumber;
string itemDescription;
int itemAmount;
int next;
int recNum;
int recSize = sizeof(int) + sizeof(string) + sizeof(int) + sizeof(int) + sizeof(int);
istream updateFile;
updateFile.open("prog4.dat");
if(!updateFile) {
cerr << "Open Failure" << endl;
exit(1);
}
}
, :
10 zidgits 17 -1
14 lidgits 2 7
6 gidgits 12 8
1 bidgits 25 3
16 widgits 9 10
7 midgits 0 2
3 didgits 11 6
5 tidgits 5 16
2 pidgits 7 5
8 kidgits 6 14
, :
updateFile , ( )?
, updateFile.
, , 1, 1 bidgits. (3) (didgits) ..
, , , . . , 5 , , ( , , ), .