Solution
/*
Programmer: Jennifer Leopold
Date: February 4, 2016
File: hw3.cpp
Purpose: Simulate a telemarketing service making phone
calls. Tally the number of calls made, the
number of calls answered, and the number of
sales made.
To compile: g++ hw3.cpp -o hw3
To execute: ./hw3
*/
#include <iostream>
using namespace std;
// Constants used to "randomly" generate a 7-digit phone #
const unsigned long INIT_PHONE_NUMBER = 1111111;
const unsigned long PHONE_NUMBER_MAX = 8999999;
const unsigned long PHONE_NUMBER_MIN = 1000000;
const unsigned long TELEMARKETER_OFFSET = 104729;
const unsigned long TELEMARKETER_INDEX = 15485863;
const int TELEMARKETER_MULTIPLIER = 7919;
// Requirements for continuing the simulation
const short MIN_CALL_REQUIREMENT = 300;
const short MIN_SALES_REQUIREMENT = 30;
// 3 connection outcomes: 0 = busy, 1 = no answer, 2 = answered
const short CONNECTION_STATUS_TYPES = 3;
const short ANSWERED = 2;
// If last 2 digits of phone number end > this value, then
// assume a sale was made
const short PHONE_NUMBER_SALE_INDICATOR = 75;
int main()
{
short numCallsMade = 0; // counts to maintain
short numCallsAnswered = 0; // during simulation
short numAnsweredCallsSale = 0;
short numAnsweredCallsNoSale = 0;
unsigned long phoneNumber = INIT_PHONE_NUMBER;
// Greeting
cout << "Welcome to the Telemarketer Simulation!\n\n";
// Continue making calls until minimum requirements met
// for calls made or sales made
while ((numCallsMade < MIN_CALL_REQUIREMENT) &&
(numAnsweredCallsSale < MIN_SALES_REQUIREMENT))
{
// Call a "randomly generated" number
phoneNumber = ((phoneNumber * TELEMARKETER_MULTIPLIER +
TELEMARKETER_OFFSET) % TELEMARKETER_INDEX) %
PHONE_NUMBER_MAX + PHONE_NUMBER_MIN;
cout << "Calling " << phoneNumber << "...\n";
numCallsMade++;
// Determine whether or not the call is answered
if ((phoneNumber % CONNECTION_STATUS_TYPES) == ANSWERED)
{
numCallsAnswered++;
// Determine whether a sale is made based on
// the last 2 digits of the phone number
if (phoneNumber % 100 > PHONE_NUMBER_SALE_INDICATOR)
{
numAnsweredCallsSale++;
cout << "Sale made at phone number "
<< phoneNumber << endl;
}
else numAnsweredCallsNoSale++;
}
}
// Output results of simulation
cout << "\nSimulation results:\n";
cout << " Number of calls made: " << numCallsMade << endl;
cout << " Number of calls answered: "
<< numCallsAnswered << endl;
cout << " Number of answered calls resulting in sale: "
<< numAnsweredCallsSale << endl;
cout << " Number of answered calls not resulting in sale: "
<< numAnsweredCallsNoSale << endl;
cout << " Overall effectiveness: "
<< (static_cast<float>(numAnsweredCallsSale) /
numCallsMade) * 100
<< "%\n";
// Sign-off
cout << "\nHave a nice day!\n";
return 0;
}