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

  • SEARCH
  • Home
  • 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 7052135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:20:50+00:00 2026-05-28T03:20:50+00:00

I have an issue how to implement to compare two static arrays, ie. string

  • 0

I have an issue how to implement to compare two static arrays, ie.

string bufferNames[]={"apple","orange","banana","pomegranate","pear"};
string bufferPictures[] = {"apple.bmp","orange.bmp","banana.bmp","pomegranate.bmp","pear.bmp"};

Each item in the bufferNames presents the choice that to someone has been given, when the picture from the bufferPictures has been loaded onto the screen. So, if I for example get orange.bmp using rand() function that iterates through that list, how can I get the same one corresponding element orange and two other random not correct elements. Any help would be appreciated.

Thanks in advance.

P.S. If further breaking in of the problem is needed, just say it so.

  • 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-05-28T03:20:51+00:00Added an answer on May 28, 2026 at 3:20 am

    This should do it. The code makes use of the C++11 features. You will
    need to adapt it, to pass it off as homework.

    #include <string>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    
    struct Picture {
      std::string name, file;
      bool operator==(const Picture& x) const { return this->name == x.name && this->file == x.file; }
      bool operator!=(const Picture& x) const { return !(*this == x); }
    
    };
    
    int main()
    {
      std::vector< Picture > pics = 
        {
          {"apple", "apple.bmp"},
          {"orange", "orange.bmp"},
          {"banana", "banana.bmp"},
          {"pear", "pear.bmp"},
        };
    
      // determined by random choice
      const Picture& choice = pics[0];
    
      std::vector< Picture > woChoice;
      std::copy_if(pics.begin(), pics.end(), std::back_inserter(woChoice), 
                   [&choice](const Picture& x) {
                     return x != choice;
                   });
    
      // random shuffle the remainder and pick the first
      // two. alternatively and for more efficience use std::random to
      // generate indices
      std::random_shuffle(woChoice.begin(), woChoice.end());
      std::cout << woChoice[0].name << std::endl;
      std::cout << woChoice[1].name << std::endl;
    
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Someone please help. I have an interesting issue. I am trying to implement an
We have an issue using the PEAR libraries on Windows from PHP . Pear
I have a design issue. I need to implement a listener. I saw the
My function to implement the search is below. The issue I have is I
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
I have an issue that is driving me a bit nuts: Using a UserProfileManager
We have an issue related to a Java application running under a (rather old)
We have an issue on our page whereby the first time a button posts
I have some issue with a Perl script. It modifies the content of a
I have an issue with using AWK to simply remove a field from a

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.