Answer:
This question has two parts, first part is about programming about a Player class and second for reading string from user and decide how many time duck string entered by user and terminate if user press goose string.
The explanation of both program (executable code) is given below in explanation section.
Explanation:
//Program 1
#include <iostream>
using namespace std;
int main()
{
bool isPremiumCustomer;
int nbooksPurchased;
int totalBookPurchasedWithOffer;
// bool cutomerType;
int freeBooks;
cout<<"Press 1 for Premium Customer and 0 for regular Customer";
cin>>isPremiumCustomer;
cout<<"How many books you purchased ";
cin>>nbooksPurchased;
switch(isPremiumCustomer)// what type of customer is
{
case 1://if customer is premium
if (nbooksPurchased >= 5&&nbooksPurchased<8)// purchase book greater between 5 and 8
{
freeBooks=1;//offer free book
totalBookPurchasedWithOffer=nbooksPurchased+freeBooks;//total number of book including free book
cout<<"You purchased total book with offer ";//show total books
cout<<totalBookPurchasedWithOffer;
}
else if (nbooksPurchased >= 8)//if premium customer purchase more than 8 book
{
freeBooks=2;//offer two free book
totalBookPurchasedWithOffer=nbooksPurchased+freeBooks;//total number of book including free book
cout<<"You purchased total book with offer ";
cout<<totalBookPurchasedWithOffer;//show total books
}
else{
cout<<"You purchased total book with no offer ";
cout<<nbooksPurchased;
}
break;
case 0:// if customer is regular customer
if (nbooksPurchased >= 7&&nbooksPurchased<12)//and purchase book between 7 and 12
{
freeBooks=1;// offer 1 free book
totalBookPurchasedWithOffer=nbooksPurchased+freeBooks;
cout<<"You purchased total book with offer ";
cout<<totalBookPurchasedWithOffer;
}
else if (nbooksPurchased >= 12)//if purchase 12 or more than 12 book
{
freeBooks=2;//offer two free book
totalBookPurchasedWithOffer=nbooksPurchased+freeBooks;
cout<<"You purchased total book with offer ";
cout<<totalBookPurchasedWithOffer;
}
else{
cout<<"You purchased total book with no offer ";
cout<<nbooksPurchased;
}
break;
}
return 0;// terminate the program
}
/* program 1 has ended
and program 2 is started from here
#######################################################
*/
#include <iostream>
using namespace std;
int main()
{
string readstring;// take input string from user to enter either "goose" or "duck"
int count=0;//count the number of "duck"
while(readstring!="goose")//run loop, until user do not enter string
{
cout<<"Enter the string either goose or duck ";// prompt user to enter the string
cin>> readstring;// read string from user
if (readstring=="duck")//if string equal to "duck"
{
count=count+1;//count number of duck string enter by user
}
}//exit/terminate the loop, if user enter the goose string
cout<< " Number of duck that were read " ;// show how many duck string entered by user
cout<<count;
return 0;// terminate the program
}