Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- //VECTOR++ CODE WRITTEN BY BEN BOLLINGER
- using namespace std;
- void createVec(vector<int>&); //Creates and sets values for a new vector of integers
- void showVec(const vector<int>&); //Displays the vector
- void mulVec(const vector<int>&); //Multiplies vector values with user input
- void createString(vector<string>&); //Creates and sets values for a new vector of string
- void showString(const vector<string>&); //Displays the vector
- void joinString(const vector<string>&); //Joins all string pieces together
- void insertString(vector<string>&); //Inserts new string into vector
- void insertInt(vector<int>&); //Inserts new integer into vector
- void replaceInt(vector<int>&); //Replaces existing integer with new integer in vector
- int main()
- {
- cout << "----- WELCOME TO VECTOR++ BY BEN BOLLINGER v1.3 -----" << endl;
- cout << endl;
- cout << "TYPE string OR int" << endl;
- string vecType;
- cin >> vecType;
- if(vecType == "string"){
- cout << "ENTER STRING (x to stop): ";
- vector<string> userString;
- createString(userString);
- showString(userString);
- cout << "------------------------" << endl;
- cout << "JOIN STRING? (yes or no): ";
- string yOr;
- cin >> yOr;
- if(yOr == "yes"){
- cout << "------------------------" << endl;
- joinString(userString);
- }else{
- cout << "------------------------" << endl;
- cout << "INSERT CHAR? (yes or no): ";
- string inSer;
- cin >> inSer;
- if(inSer == "yes"){
- cout << "------------------------" << endl;
- insertString(userString);
- }else{
- cout << "------------------------" << endl;
- cout << "COMPLETED";
- }
- }
- }else if(vecType == "int"){
- cout << "ENTER INTEGERS (-1 to stop): ";
- vector<int> userNums;
- createVec(userNums);
- showVec(userNums);
- cout << "------------------------" << endl;
- cout << "MULTIPLY? (enter yes or no): ";
- string yOr;
- cin >> yOr;
- if(yOr == "yes"){
- cout << "------------------------" << endl;
- mulVec(userNums);
- }else{
- cout << "------------------------" << endl;
- cout << "REPLACE NUMBERS? (yes or no): ";
- string yOr;
- cin >> yOr;
- if(yOr == "yes"){
- replaceInt(userNums);
- }else{
- cout << "------------------------" << endl;
- cout << "COMPLETE" << endl;
- }
- }
- }else{
- cout << "INVALID TYPE" << endl;
- }
- system("pause");
- }
- void createVec(vector<int>& newVec){
- int uInput;
- cin >> uInput;
- while(uInput != -1){
- newVec.push_back(uInput);
- cin >> uInput;
- }
- }
- void showVec(const vector<int>& newVec){
- cout << "VECTOR BEGINNING" << endl;
- cout << "------------------------" << endl;
- cout << "CONTENTS: ";
- for(unsigned int i = 0; i < newVec.size(); i++){
- cout << newVec[i] << " ";
- }
- cout << endl;
- cout << "------------------------" << endl;
- cout << "VECTOR DISPLAY COMPELETE" << endl;
- }
- void createString(vector<string>& newVec){
- string uInput;
- cin >> uInput;
- while(uInput != "x"){
- newVec.push_back(uInput);
- cin >> uInput;
- }
- }
- void showString(const vector<string>& newVec){
- cout << "VECTOR BEGINNING:" << endl;
- cout << "------------------------" << endl;
- cout << "CONTENTS: ";
- for(unsigned int i = 0; i < newVec.size(); i++){
- cout << newVec[i] << " ";
- }
- cout << endl;
- cout << "------------------------" << endl;
- cout << "VECTOR DISPLAY COMPELETE" << endl;
- }
- void mulVec(const vector<int>& newVec){
- cout << "BY WHAT NUMBER?: ";
- int mulNum;
- cin >> mulNum;
- cout << "------------------------" << endl;
- cout << "NEW CONTENTS: ";
- for(unsigned int i = 0; i < newVec.size(); i++){
- cout << newVec[i] * mulNum << " ";
- }
- cout << endl;
- cout << "------------------------" << endl;
- cout << "VECTOR DISPLAY COMPELETE" << endl;
- }
- void joinString(const vector<string>& newVec){
- string joinedS;
- for(unsigned int i = 0; i < newVec.size(); i++){
- joinedS += newVec[i];
- }
- cout << "JOINED STRING: " << joinedS << endl;
- }
- void insertString(vector<string>& newVec){
- cout << "ENTER VECTOR POSITION: ";
- int vecPos;
- cin >> vecPos;
- cout << "------------------------" << endl;
- cout << "ENTER DATA TO INSERT: ";
- string intData;
- cin >> intData;
- if(intData.length() == 1){
- newVec.insert(newVec.begin() + vecPos, intData);
- cout << "------------------------" << endl;
- cout << "NEW CONTENTS: ";
- for(unsigned int i = 0; i < newVec.size(); i++){
- cout << newVec[i];
- }
- }else{
- cout << "------------------------" << endl;
- cout << "INSERT MAY ONLY BE 1 CHAR";
- }
- }
- void replaceInt(vector<int>& newVec){
- cout << "------------------------" << endl;
- cout << "ENTER NUMBER TO REPLACE: ";
- int repNum;
- cin >> repNum;
- cout << "------------------------" << endl;
- cout << "ENTER NUMBER TO REPLACE WITH: ";
- int newNum;
- cin >> newNum;
- cout << "------------------------" << endl;
- for(unsigned int i = 0; i < newVec.size(); i++){
- if(newVec[i] == repNum){
- newVec[i] = newNum;
- }
- cout << newVec[i] << " ";
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement