The application supports a table of records using class to input data in data field.

The application supports a table of records. Define a class called
StoreItem, the instance of which is a record. The maximum number of records in a table is not predefined.Program can use a vector or a dynamic array to implement a table, supporting dynamically the increase and the decrease of the number of records in a table.

The requirement are as below:

1. Insertion of a new record
2. Update of a data field in a record
3. Deletion of a data field in a record
4. Deletion of a record
5. Saving the table into a text file
6. Loading the table from a text file

Please help me
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <fstream>
#include <vector>

struct StoreItem
{
    int data_field;
};

void insert_record( std::vector<StoreItem> & v_records, int item)
{
    StoreItem storeItem;
    storeItem.data_field = item;
    v_records.push_back( storeItem);
}
void update_data_field( std::vector<StoreItem> & v_records, std::size_t pos, int item)
{
    if (pos < v_records.size()) v_records[pos] = item;
}
void delete_data_field( std::vector<StoreItem> & v_records, std::size_t pos)
{
    if (pos < v_records..size()) v_records[pos] = 0;
}
void delete_record(std::vector<StoreItem> & v_records, int item)
{
    auto itr = std::find(v_records.begin(), v_records.end(), item);
    if (itr != v_records.end()) { v_records.erase( itr); }
}
// for saving and loading from file
std::ostream& operator<< (std::ostream& ostr, const std::vector<StoreItem>& v)
{
    for( auto storeItem : v) ostr << storeItem.data_field << '\n';
    return ostr;
}
std::istream& operator>> (std::istream& istr, std::vector<StoreItem>& v)
{
    StoreItem si;
    while( istr >> si.data_field) v.push_back( si );
    return istr;
}
int main()
{
    std::vector<StoreItem> v;
    for (int i = 0; i < 5)  // reads 5 records from input
    {
        StoreItem si;
        std::cin >> si.data_field;
        v.push_back(si);
    }

    // storing to file
    std::ofstream ofile("my_file.txt"); 
    ofile << v;
    ofile.close();
    v.clear();

    // loading from file
    std::ifstream ifile("my_file.txt");
    ifile >> v;
    ifile.close();
    std::cout << v;
}
can u make one program as requirement below. Please.

supports a table of records. Define a class called StoreItem, the instance of which is a record.The maximum number of records in a table is not predefined. Your program can use a vector or a dynamic array to implement a table, supporting dynamically the increase and the decrease of the number of records in a table. You program should consist of three files, which are Inventory.cpp, StoreItem.h and StoreItem.cpp.
The user need to input are as below:

1.Item ID
2.Item Name
3.Item Description
4.Category
5.Manufacturer
6.Selling Price
7.Cost Price
8.Units in Store
9.Units Sold
10.Year of Date First Introduced
11.Month of Date First Introduced
12.Day of Date First Introduced

The features required are as below:

1. Insertion of a new record
2. Update of a data field in a record
3. Deletion of a data field in a record
4. Deletion of a record
5. Displaying on screen the table of records showing
6. Saving the table into a text file
7. Loading the table from a text file
Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.
Topic archived. No new replies allowed.