You are the manager of a travel agency with 20 employees. You have announced a p
ID: 3553279 • Letter: Y
Question
You are the manager of a travel agency with 20 employees. You have announced a promotional campaign for your agents to sell vacation packages. Each day you will enter the ID number of the agent (#1-#20), the number of packages sold, and the dollar value of the package. Entries will be in a random order and the total $ value is accumulated for a 3 week period. At the end of the campaign you want a print out of those agents who sold less than $1000.00 in the 3 week time frame. You will also want a list of those that did not participate in the campaign. Input and output are done using files.
Explanation / Answer
Dropbox links:
1. Input file: https://dl.dropboxusercontent.com/u/78383401/chegg/cpp/input.txt
2. Code file: https://dl.dropboxusercontent.com/u/78383401/chegg/cpp/cpsc2.cpp
3. Output file: https://dl.dropboxusercontent.com/u/78383401/chegg/cpp/result.txt
____________________________________________________________________________________________
Code:
#include<iostream>
#include<fstream>
#include<conio.h>
#include<iomanip>
#include<cmath>
#include<algorithm>
// Associating program identifiers with external file names
#define in_file "input.txt"//input file name
#define out_file "result.txt"//output file name
using namespace std;
ifstream ins;// associates ins as an input stream
ofstream outs;// associates outs as an output stream
const int size=20;
int entries=0;
int agent[size]={0};
int sales[size]={0};
int tot_sales[size]={0};
float value[size]={0.0};
float amount[size]={0.0};
float sorted[size]={0.0};
float temp[size]={0.0};
bool myfunction (float i,float j) { return (j<i); }
void key_fun(ifstream& ins, ofstream& outs){//pass by reference
ins.open(in_file);
int i=0;
int ag=0,sa=0;
float va=0.0;
/*for(int j=0;j<size;j++){
agent[j]=j+1;
}*/
outs<<"KWANTLEN TRAVEL AGENCY"<<endl<<endl;;
outs<<"LIST OF INVALID ENTRIES"<<endl;
while(!ins.eof()){
ins>>ag>>sa>>va;
//cout<<ag<<endl;
outs<<fixed<<showpoint;
outs<<setprecision(2);
if(ag>=1 && ag<=20 && va>=0){
agent[ag-1]=ag;
sales[ag-1]=sa;
tot_sales[ag-1] += sa;
value[ag-1]=va;
amount[ag-1]+= sa*va;
}
else if((ag<1)|| (ag>20))
{
outs<<setw(2)<<ag<<" "<<setw(2)<<sa<<" "<<setw(7)<<va;
outs<<" **invalid agent #**"<<endl;
}
else if(va <0)
{
outs<<setw(2)<<ag<<" "<<setw(2)<<sa<<" "<<setw(7)<<va;
outs<<" **invalid price**"<<endl;
}
i++;
entries++;
}
outs<<endl;
ins.clear();
ins.close();
}
void display()
{
outs<<"TOTAL SALES BY AGENT"<<endl<<endl;
outs<<"AGENT NUMBER #SALES VALUE/SALE AMOUNT"<<endl;
for(int i=0;i<size;i++)
{
outs<<fixed<<showpoint;
outs<<setprecision(2);
if((agent[i]>0)&&(agent[i]<21) && value[i]>=0)
{
if(tot_sales[i]>0)
outs<<setw(2)<<agent[i]<<" "<<setw(2)<<tot_sales[i]<<" "<<setw(7)<<amount[i]/tot_sales[i]<<" "<<setw(7)<<amount[i]<<endl;
else
outs<<setw(2)<<agent[i]<<" "<<setw(2)<<" 0 "<<setw(7)<<" 0 "<<setw(7)<<" 0 "<<endl;
}
}
outs<<endl;
}
void total()
{
int total_sales=0;
float average_sales;
float total_volume=0;
for(int i=0;i<size;i++)
{
outs<<fixed<<showpoint;
outs<<setprecision(2);
total_sales+=tot_sales[i];
total_volume+=amount[i];
average_sales=total_volume/total_sales;
}
outs<<"TOTAL SALES "<<total_sales<<endl;
outs<<"AVERAGE SALES VALUE "<<average_sales<<endl;
outs<<"TOTAL VOLUME IN SALES "<<total_volume<<endl;
outs<<endl;
}
void top3()
{
outs<<"TOP 3 WINNER OF THE SALES CAMPAIGN"<<endl<<endl;
outs<<"AGENT DOLLAR VOLUME SOLD"<<endl;
for(int i=0;i<size;i++)
{
temp[i]=amount[i];
outs<<fixed<<showpoint;
outs<<setprecision(2);
}
sort(temp,temp+size,myfunction);
int k;
for(k=0;k<3;k++){
for(int j=0;j<size;j++){
//cout<<agent[j]<<":"<<amount[j]<<" ";
if(temp[k]==amount[j]){
outs<<setw(2)<<agent[j]<<" "<<"$"<<" "<<amount[j]<<endl;
break;
}
}
}
outs<<endl;
}
void lessthan()
{
outs<<"AGENTS WHOSE SALES WERE BELOW $1000.00 "<<endl<<endl;
outs<<"AGENT DOLLAR VOLUME SOLD"<<endl;
for(int i=0;i<size;i++)
{
outs<<fixed<<showpoint;
outs<<setprecision(2);
if(amount[i]<1000 && agent[i]!=0)
{
outs<<setw(2)<<agent[i]<<" "<<"$"<<" "<<amount[i]<<endl;
}
}
outs<<endl;
}
void participate(){
outs<<"AGENTS WHO DID NOT PARTICIPATE IN THE CAMPAIGN"<<endl;
for(int i=0;i<size;i++){
if(agent[i]==0)
outs<<i+1<<setw(4);
}
outs<<endl;
}
int main()
{
outs.open(out_file);
key_fun(ins,outs);//passing input and output file by reference
display();
total();
top3();
lessthan();
participate();
outs.close();
}
_____________________________________________________________________________________________
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.