Use the Concept of vector and string to do the following question

Use the Concept of vector and string to do the following question

1) Write a program that creates a vector of string 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 located in the forth index which means 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



it is possible if someone give me a guide of what i'm trying to do here? like i dont understand what i need to do. like what will the outcome will be. i'm still confuse with the number that listed. i dont need the code just what i need to do and what will the outcome will be would be great. Thank you


Last edited on
Your program reads from a file. The first thing in the file is a word. There are only valid words, so you must check whic word did you get, and act accordingly.

The "Insert" and "Delete" mean that you have to read some more.

Once you have handled one line, you will read the next line, until the file ends.


Start simple: Write a program that reads from std::cin and prints them.
(You can redirect file to input on command line. Do you know how?)
@keskiverto
so youre saying i create a function.
then i need to take in those file that i have from data.txt.
after that using Insert and Delete to take in those word and arranging them?
OP: when you meet your teacher next please tell him/her that this is a very inefficient exercise in that it suggests using a vector container to insert/delete from the middle of the range. While you can do this as a classroom exercise and small size the ideal container that should be used in such cases is a list
@gunam12
Send me a private message.
Topic archived. No new replies allowed.