Advertisement
TermSpar

Vector Extended

Apr 20th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. #include<string>
  4. #include<vector>
  5. #include<windows.h>
  6.  
  7. using namespace std;
  8.  
  9. void createVec(vector<int>&);
  10. void showVec(const vector<int>&);
  11. void multVec(const vector<int>&);
  12.  
  13. int main(){
  14.  
  15.     cout << "ENTER VALUES (-1 to stop): ";
  16.  
  17.     vector<int> uVec;
  18.  
  19.     createVec(uVec);
  20.     showVec(uVec);
  21.  
  22.     cout << "MULTIPLY? (yes or no): ";
  23.  
  24.     string yOr;
  25.     cin >> yOr;
  26.  
  27.     if(yOr == "yes"){
  28.         multVec(uVec);
  29.     }else{
  30.         cout << "COMPLETED";
  31.     }
  32.  
  33.     system("pause");
  34.     return 0;
  35. }
  36.  
  37. void createVec(vector<int>& newVec){
  38.    
  39.     int uInput;
  40.     cin >> uInput;
  41.  
  42.     while(uInput != -1){
  43.         newVec.push_back(uInput);
  44.         cin >> uInput;
  45.     }
  46.  
  47. }
  48.  
  49. void showVec(const vector<int>& newVec){
  50.    
  51.     cout << "VECTOR: ";
  52.  
  53.     for(unsigned int i = 0; i < newVec.size(); i++){
  54.         cout << newVec[i] << " ";
  55.     }
  56.  
  57. }
  58.  
  59. void multVec(const vector<int>& newVec){
  60.    
  61.     cout << "BY WHAT NUMBER?: ";
  62.  
  63.     int uInput;
  64.     cin >> uInput;
  65.  
  66.     for(unsigned int i = 0; i < newVec.size(); i++){
  67.         cout << newVec[i] * uInput << " ";
  68.     }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement