Answer to Question #275195 in C++ for Lax

Question #275195

Display the total amount per section code and the overall total


4. At the end of each event five (5) lucky customers are randomly chosen from the name


array to win daily prizes. Call a function to accomplish this.


5. Display the names of the five lucky winners.(15

1
Expert's answer
2021-12-03T18:53:44-0500
#include <iostream>
#include <string>

class Customer
{
  std::string name = "a";
  bool win = false;
public:
  void set_win()
  {
    win = true;
  }
  const bool& get_win()
  {
    return win;
  }
  const std::string & get_name()
  {
    return name;
  }
};

int main()
{
  Customer customers[100] = {};
  int event_number = 0;
  std::cout << "Enter the event number: ";
  std::cin >> event_number;
  for(int i = 1; i <= event_number; i++)
  {
    for(int j = 0; j != 5; ++j)
    {
      int i = std::rand() % 100;
      if(!customers[i].get_win())
      {
        customers[i].set_win();
        std::cout<<"The winner is: "<<customers[i].get_name()<<i<<std::endl;
      }
    }

  }
   
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment