Write a program that creates a vector of strings called V. Vector V grows and shrinks as the user processes the transactions from a data file called “data.txt”. The transaction file can only include three commands: Insert, Delete and Print. With Insert command, you get two more information, the information you need to insert and the position it should be inserted. With Delete, you get one more information that indicates which element (index) should be deleted. Print command means the content of the vector should be printed on the screen. For example, you may have the following information in your file:
Insert Hello 4
Delete 5
Print
The first line indicates that The word “Hello” should be inserted in V[4]. Of course you should check if this insert is possible. This insert is possible if the position you are attempting to insert the element is not beyond the size of the vector.
The second line means V[5] should be removed. Again this operation should only be allowed if the index is not beyond the current size of the vector.
Test your program with the following transaction file:
Insert Total 0
Insert Normal 0
Insert Perfect 1
Insert Program 1
Insert Book 2
Print
Insert Perfect 5
Delete 1
Delete 7
Insert Money 2
Delete 3
Print
Note: Each command must be implemented in a separate function.
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
|
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
void insert( string, string, int);
int main()
{
vector <string>v;
string operation, value;
int index;
ifstream inputFile;
inputFile.open("data3.txt");
if(!inputFile)
{
cout << "ERROR";
}
else
{
while (inputFile >> operation >> value>> index)
{
v.push_back("operation");
v.push_back("value");
v.push_back("index");
}
if ((operation >= value) && (value <= operation))
{
cout<< " there is imore";
}
}
inputFile.close();
return 0;
}
void insert( string operation, string value, int index)
{
}
|
The part I do not understand is : The transaction file can only include three commands: Insert, Delete and Print. With Insert command, you get two more information, the information you need to insert and the position it should be inserted. With Delete, you get one more information that indicates which element (index) should be deleted.
how do i do that?
I know my prototype and my function is wrong I need guidance there as well. I looked in my book but i can't find any string vectors with commands. please help.