Question

Need help with this Home wrok question pls. Whitelisting his ask S known as white in . t s a so used as part of spam iters s a ters at come it email clients a e For this exercise you will write co e or en ing usernames a ainst a st o ex s ng usernames blacklists of senders and keywords to look for in emails. t w s sand You are given a list of usernames that are trying to get access to a system and you need to verify that those users are in the list of existing usernames. You will return a list of only those that are. Write a function that will take two string vectors as arguments. usernames and existingusers and it will return a vector with the list of values in the first vector that are also in the second vector. The signature of the function is as follows. vector validateUaera (vector username, vector exiatingusera) Input and Output example output Ben, Kim, existingusers n, Matt, Jen, Kim, Ben, Tim, Tom, Max, Zion, Rose, Karl, m) Ben, Tom, Jen Write a main program to test your function with one of the examples above PARTIAL SOLUTION: Km (Ben, Tim, Tom, Max, Zion, Rose, Karl, Kim Ben, Tom) include vector> finclude so include namespace std; vector*string validateUsers(vectorstrings usernames, vector srng existingusers), int main 0 vector stringvBen, Tom, Jen vector string v2Ben, Tim, Tom, Max, Zion, Rose, Karl, Kim, Tom]; vector stringresul vaidateUsers(v, v2) for (int i=0,沁result size(), i++) { cout « result

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <vector>
#include <string>
using namespace std;
void validateuser(vector<string>,vector<string>);

int main()
{
vector<string> v1;
vector<string> v2;
v1.push_back("ben");
v1.push_back("tom");
v1.push_back("jen");
//-------------------------
v2.push_back("ben");
v2.push_back("tim");
v2.push_back("tom");
v2.push_back("max");
v2.push_back("jeon");
v2.push_back("jos");
v2.push_back("karl");
v2.push_back("kim");
  
  
  
validateuser(v1,v2);

return 0;
}
void validateuser(vector<string> v1,vector<string> v2){
for(int i=0;i<v1.size();i++){
for(int j=0;j<v2.size();j++){
if(v1[i].compare(v2[j])==0){
cout<<v1[i]<<endl;
break;
}
}
}
  
}


output:

Computer Science ques: Χ nline C+. Compiler- X 、00 Vector in C++ STL-Gee >. w string::compare-C++ RX c..-How to pass a vec X

/* main function call validate userfunction
and validate userfunction loop through both the vectors and print out the string which contains both in first and second vector
*/

Add a comment
Know the answer?
Add Answer to:
Need help with this Home wrok question pls. For this exercise you will write code or...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is a c++ code /**    Write a function sort that sorts the elements of...

    This is a c++ code /**    Write a function sort that sorts the elements of a std::list without using std::list::sort or std::vector. Instead use list<int>::iterator(s) */ using namespace std; #include <iostream> #include <iomanip> #include <string> #include <list> void print_forward (list<int>& l) { // Print forward for (auto value : l) { cout << value << ' '; } cout << endl; } void sort(list<int>& l) { write code here -- do not use the built-in list sort function }...

  • Any help in the compiler error //Driver Program //***************** /** * * CSCI 241 Assignment 8...

    Any help in the compiler error //Driver Program //***************** /** * * CSCI 241 Assignment 8, Part 3 * * Author: your name * z-ID: your z-ID * Date: due date of assignment * * This program builds, sorts and prints lists using the quicksort and * merge sort algorithms. */ #include <iostream> #include <iomanip> #include <vector> #include <string> #include "sorts.h" #include "quicksort.h" #include "mergesort.h" using std::cout; using std::fixed; using std::left; using std::setprecision; using std::string; using std::vector; // Data files...

  • Fix my code, if I the song or the artist name is not on the vector,...

    Fix my code, if I the song or the artist name is not on the vector, I want to user re-enter the correct song or artist name in the list, so no bug found in the program #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class musicList{ private: vector<string> songName; vector<string> artistName; public: void addSong(string sName, string aName){ songName.push_back(sName); artistName.push_back(aName); } void deleteSongName(string sName){ vector<string>::iterator result = find(songName.begin(), songName.end(), sName); if (result == songName.end()){ cout << "The...

  • Please Help. C++. Need 3 attributes and 3 methods added to the code below. Need the...

    Please Help. C++. Need 3 attributes and 3 methods added to the code below. Need the prototype added to the .h file......and the implementation in the .cpp file....thanks! edited: I just need the above and then I was told to use the methods in the main program; for the vehicle. Any 3 attributes and any three methofds. source.cpp file // Header Comment #include #include #include #include "Automobile.h" using namespace std; struct Address{ string street; string city; string state; string zip;...

  • Write a c++ code into the given code  to find composite numbers from the given random number...

    Write a c++ code into the given code  to find composite numbers from the given random number list. The composite numbers is only counted once if there is a repeated number. I need to use this code and add on a code to find if the numbers generated is a composite function. Please help #include <cmath> #include <cstdlib> #include <ctime> #include <iostream> #include <vector> using namespace std; int main() {    srand(time(NULL)); int size_of_list = 0; // the number of random...

  • The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried t...

    The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...

  • 4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std;...

    4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std; int main() { string playerName; cout << "Enter name"; cin >> playerName; cout << endl « playerName; return 0; } a. Tom - Sawyer b. Tom Sawyer c. Tom d. Sawyer 5) Which XXX generates "Adam is 30 years old." as the output? #include <iostream> using namespace std; int main() { string name = "Adam"; int age = 30; XXX return 0; } a....

  • Can anyone help me with this one? I really appreciate it! Find and fix errors and...

    Can anyone help me with this one? I really appreciate it! Find and fix errors and Simplify the createGroups() function using only one loop instead of two #include using namespace std; const double NO_STU = 40; void createGroups(const string myClass[], int no_stu, string group1, string group2); void printList(const string [], int); int main() { int no_stu = 8; string myClass[NO_STU] = { "Linda", "Bob", "Mary", "Jo", "Tim", "Jamie", "Ann", "Tom" }; string group1[NO_STU % 2]; string group2[NO_STU % 2]; createGroups(no_stu,...

  • I need to add a for or a while loop to the following code. please help...

    I need to add a for or a while loop to the following code. please help needs to be in c++. #include <iostream> #include <string.h> using namespace std; int main() {    char input[100]; cout << "Please enter a character string: "; cin >> input; char *head = &input[0], *tail = &input[strlen(input) - 1]; char temp = *head; *head = *tail; *tail = temp; tail--; head++; cout << "CString = " << input << "\n"; }

  • This is assignment and code from this site but it will not compile....can you help? home...

    This is assignment and code from this site but it will not compile....can you help? home / study / engineering / computer science / computer science questions and answers / c++ this assignment requires several classes which interact with each other. two class aggregations ... Question: C++ This assignment requires several classes which interact with each other. Two class aggregatio... (1 bookmark) C++ This assignment requires several classes which interact with each other. Two class aggregations are formed. The program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT