You are to enhance the original to include an array for 5 names and an arrayfor
ID: 3615548 • Letter: Y
Question
You are to enhance the original to include an array for 5 names and an arrayfor the 5 corresponding sales which you are to input data from the keyboardusing a looping structure. Once the data is entered, the program is toprint out all 5 names and corresponding bonuses using an additional functionto step through the arrays and the old function to calculate the bonus asbefore. The old #3:Scenario: "Flowers Forever" wants a program that the clerks can use tocalculate and display each salesperson's annual bonus. The clerk will needto enter the salesperson's name and sales. The application should calculatethe bonus based on the amount of sales as follows:SALES BONUS0-3000 03001-5000 505001-9999 10010000+ 250The program should echo input and output the calculated bonus. Call a functionto do the calculations. Turn in PDL, code and sample data and results.
Here is the original:
#include <iostream>
#include <string>
using namespace std;
char name [50]; int sales=0;
int main () {
cout << "Enter the salesperson's name. ";
cin.getline (name, 50);
cout << "Enter the person's sales amount. ";
cin >> sales;
if (sales>=0&&sales<3001){
cout << name << "'s bonus is $O." << endl;
}
if (sales>=3001&&sales<5001){
cout << name << "'s bonus is $50." << endl;
}
if (sales>=5001&&sales<10000){
cout << name << "'s bonus is $100." << endl;
}
if (sales>=10000){
cout << name << "'s bonus is $250." << endl;
}
return 0;
}
Explanation / Answer
#include<iostream>
#include <string>
using namespace std;
void calculatedbonus(string,int);
void calbonus(string[],int[],int);
string name[5];int sales[5];
int main () {
int i;
for(i=0;i<5;i++)
{cout <<"Enter the salesperson's name. ";
getline(cin,name[i]);
cout <<"Enter the person's sales amount. ";
cin >>sales[i];
cin.ignore(25,' ');
}
calbonus(name,sales,5);
system("pause");
return 0;
}
void calbonus(string name[],int sales[],int n)
{int i,bonus;
for(i=0;i<n;i++)
calculatedbonus(name[i],sales[i]);
}
void calculatedbonus(string name,int sales)
{
if (sales>=0&&sales<3001){
cout << name<< "'s bonus is $O." << endl;
}
if(sales>=3001&&sales<5001){
cout << name<< "'s bonus is $50." << endl;
}
if(sales>=5001&&sales<10000){
cout << name<< "'s bonus is $100." << endl;
}
if(sales>=10000){
cout << name<< "'s bonus is $250." << endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.