Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8939827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:54:18+00:00 2026-06-15T10:54:18+00:00

Been working on this program which requires the use of a function that compares

  • 0

Been working on this program which requires the use of a function that compares a string input by the user and gives the user the opportunity to leave the characters that he/she doesn’t know out of the input, replacing them with * . The input represents a license-plate of a car that has 6 characters (for instance ABC123) and the user is allowed to leave any of those characters out (for instance AB** 23 or ** C12* etc.). So the function needs to return all objects that match the characters in the right position, but it cannot return if, say, A is in the right position but any of the other characters are not. The user is, however, allowed to only enter A* * * * *, for instance, and the function should return all objects that have A in the first position.
What I did was use a function to remove all the asterisks from the input string, then create sub-strings and send them to the function as a vector.

    string removeAsterisk(string &rStr)// Function to remove asterisks from the string, if any.
    {
        stringstream strStream;
        string delimiters = "*";
        size_t current;
        size_t next = -1;
        do
    {
         current = next + 1;
         next = rStr.find_first_of( delimiters, current );
         strStream << rStr.substr( current, next - current ) << " ";
}
while (next != string::npos);

return strStream.str();

}

     int main()
    {
            string newLicensePlateIn;
            newLicensePlateIn = removeAsterisk(licensePlateIn);
            string buf; // Have a buffer string
            stringstream ss(newLicensePlateIn); // Insert the string into a stream

            vector<string> tokens; // Create vector to hold our words

            while (ss >> buf)
                tokens.push_back(buf);
            myRegister.showAllLicense(tokens); 
    }

The class function that receives the vector currently looks something like this:

    void VehicleRegister::showAllLicense(vector<string>& tokens)//NOT FUNCTIONAL
    {
        cout << "\nShowing all matching vehicles: " << endl;
        for (int i = 0; i < nrOfVehicles; i++)
        {

            if(tokens[i].compare(vehicles[i]->getLicensePlate()) == 0)
            {
                cout << vehicles[i]->toString() << endl;
            }
        }
    }

If anyone understand what I’m trying to do and might have some ideas, please feel free to reply, I would appreciate any advice.
Thanks for reading this/ A.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:54:19+00:00Added an answer on June 15, 2026 at 10:54 am

    Just iterate through the characters, comparing one at a time. If either character is an asterisk, consider that a match, otherwise compare them for equality. For example:

    bool LicensePlateMatch(std::string const & lhs, std::string const & rhs)
    {
        assert(lhs.size() == 6);
        assert(rhs.size() == 6);
        for (int i=0; i<6; ++i)
        {
            if (lhs[i] == '*' || rhs[i] == '*')
                continue;
            if (lhs[i] != rhs[i])
                return false;
        }
        return true;
    }
    

    Actually, you don’t have to restrict it to 6 characters. You may want to allow for vanity plates. In that case, just ensure both strings have the same length, then iterate through all the character positions instead of hardcoding 6 in there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on this application that enables user to log in into
I've been working on an android program. One portion of this program interacts with
Hi I have been working on this code that creates a table with radio
Total newb to .NET programming (and AJAX) but I've been working on this program
I have this problem to solve There is an input word from user which
I've been working on a program in C# that involves image editing and animating.
I've been working on this elevator program for quite some time now and finally
I've been working on a small program which gets a list of url's from
I have been working on a multiple inheritance code which looks similar to this:
I've recently been working on a C#/VS2008 project which requires 3 ActiveX controls. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.