Given the code 1- write the function seen(x,winner,i) that is used by the draw()
ID: 3612322 • Letter: G
Question
Given the code
1- write the function seen(x,winner,i) that is used by the draw()member function to check if the item x is seen in the winner arrayby searching the first i element in the arraywinner
so it will give the followingouput:
How many members in the draw:40
How many Gifts you are willing to give:10
Winners are:
member 25
member 9
member 37
member 27
member 28
member 23
member 40
member 5
member 7
member 38
2- write the function that has thisprototype
void saveResults(Campane x)
that will write into a file winners.txt all winner members withoutusing the display() member function, you might create other memberfunctions to help you get the value of gifts ormembers
Explanation / Answer
#include<iostream>
#include<ctime>
#include<fstream>
using namespace std;
bool seen(int x, int a[],int n){
int i;
for(i=0;i<n;i++)
if(a[i]==x)
returntrue;
return false;
}
class Campane{
private:
int members;
int prizes;
int winner[100];
public:
Campane(){
members=0;
prizes=0;
for(int i=0; i<100;i++)
winner[i]=0;
}
int getprizes(){return prizes;}
void setMembers(int x){members=x;}
void setGifts(int x){prizes=x;}
void draw(){
int x;
for(int i=0;i<prizes;i++){
x=rand()%members +1;
if (seen(x,winner,i))
i--;
else
winner[i]=x;
}
}
void displayWinners(){
cout<<"Winners are: ";
for(int i=0;i<prizes;i++){
cout<<"member "<<winner[i]<<endl;}
}
};
//void saveResults(Campanex); /* this is only prototype do not change*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.