Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help on c++, call by reference please and thank you Use the Concept of vect

ID: 3746419 • Letter: N

Question

Need help on c++, call by reference please and thank you
Use the Concept of vector and string to do the following question 1) Write a program that creates a vector of string called “Vec”. Vector “Vec” grows and shrinks as the user processes the transactions from a data file called “Transaction.txt”. The transaction file can only include three types of commands: Add, Remove, and Print. With “Add” command, you get two more information, the information you need to put into the vector and the position the information should be inserted. With “Remove”, 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: AddHello4 Remove5 Print The first line indicates that the word “Hello” should be located in the forth index which means Vec [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 Vec [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: AddStudent0 AddKid0 AddFinal1 AddGrow1 AddNote2 Print AddRich5 Remove1 Remove7 AddMind2 Remove3 Print Need help on c++, call by reference please and thank you
Use the Concept of vector and string to do the following question 1) Write a program that creates a vector of string called “Vec”. Vector “Vec” grows and shrinks as the user processes the transactions from a data file called “Transaction.txt”. The transaction file can only include three types of commands: Add, Remove, and Print. With “Add” command, you get two more information, the information you need to put into the vector and the position the information should be inserted. With “Remove”, 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: AddHello4 Remove5 Print The first line indicates that the word “Hello” should be located in the forth index which means Vec [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 Vec [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: AddStudent0 AddKid0 AddFinal1 AddGrow1 AddNote2 Print AddRich5 Remove1 Remove7 AddMind2 Remove3 Print Need help on c++, call by reference please and thank you
Use the Concept of vector and string to do the following question 1) Write a program that creates a vector of string called “Vec”. Vector “Vec” grows and shrinks as the user processes the transactions from a data file called “Transaction.txt”. The transaction file can only include three types of commands: Add, Remove, and Print. With “Add” command, you get two more information, the information you need to put into the vector and the position the information should be inserted. With “Remove”, 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: AddHello4 Remove5 Print The first line indicates that the word “Hello” should be located in the forth index which means Vec [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 Vec [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: AddStudent0 AddKid0 AddFinal1 AddGrow1 AddNote2 Print AddRich5 Remove1 Remove7 AddMind2 Remove3 Print
Use the Concept of vector and string to do the following question 1) Write a program that creates a vector of string called “Vec”. Vector “Vec” grows and shrinks as the user processes the transactions from a data file called “Transaction.txt”. The transaction file can only include three types of commands: Add, Remove, and Print. With “Add” command, you get two more information, the information you need to put into the vector and the position the information should be inserted. With “Remove”, 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: AddHello4 Remove5 Print The first line indicates that the word “Hello” should be located in the forth index which means Vec [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 Vec [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: AddStudent0 AddKid0 AddFinal1 AddGrow1 AddNote2 Print AddRich5 Remove1 Remove7 AddMind2 Remove3 Print Use the Concept of vector and string to do the following question 1) Write a program that creates a vector of string called “Vec”. Vector “Vec” grows and shrinks as the user processes the transactions from a data file called “Transaction.txt”. The transaction file can only include three types of commands: Add, Remove, and Print. With “Add” command, you get two more information, the information you need to put into the vector and the position the information should be inserted. With “Remove”, 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: AddHello4 Remove5 Print The first line indicates that the word “Hello” should be located in the forth index which means Vec [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 Vec [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: AddStudent0 AddKid0 AddFinal1 AddGrow1 AddNote2 Print AddRich5 Remove1 Remove7 AddMind2 Remove3 Print

Explanation / Answer

SOURECE CODE:

#include<iostream>

#include<vector>

#include<string>

#include<fstream>

using namespace std;

int main()

{

vector<string> V;

char filename[] = "DATA_4.txt";

string word;

string name;

int index;

ifstream ifs(filename);

if (ifs)

{

while(ifs>>word)

{

if(word=="Add")

{

ifs>>name>>index;

if(index<=V.size())

{

V.insert(V.begin()+index,name);

}

else

{

cout<<"Wrong index"<<endl;

}

}

else if(word=="Remove")

{

ifs>>index;

if(index<V.size())

{

V.erase(V.begin()+index);

}

else

{

cout<<"Wrong Position to delete"<<endl;

}

}

else if(word=="Print")

{

for(int i=0; i<V.size(); i++)

{

cout<<V.at(i)<<" ";

}

cout<<endl;

}

}

}

else

{

cout<<"can't open file"<<endl;

}

return 0;

}

OUTPUT :

Kid Grow Note Final Student

Wrong Position is delete

Kid Note Mind Student Rich

-------------------------------------------

Process exited after 0.2515 sec with the return value 0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote