Hey Guys and Gals
I am new to this site and new to programming. C++ is the first one I am trying to learn. I ran into a problem on one of my assignements. I believe my problem is in the actual calculations. The Bonus part of the program is way off. Could you guys give it a look and see if you can point me in the right direction. I will attach the problem and my source code. I really appreciate this. I look forward to learning from some people who have been doing this a long time.:)
Create an algorithm and a C++ program for the following problem.
TechMed International has five salesmen on their staff. Bonuses are provided each week if a salesman’s total sales are greater than the average sales for the week. Your program should input the first and last name of each salesman along with his or her total sales for the week. It should then compute the average sales for the five salesmen. Finally, it should print each salesperson’s name, his or her sales amount, and the bonus amount. The bonus amount will be zero if the sales amount is less than the average. It will be 5 percent of the salesman’s sales amount if it is greater than the average. Use parallel arrays to solve this problem.
To test your program, it should display the following report, assuming that the sales amount figures were provided as input to the program.
Sales Report
Name
Total Sales
Bonus
Stan Jones
2500
0.00
Bill Smith
3325
166.25
Abe Locker
4155
207.75
Ace Hill
2120
0.00
Bud Wiser
1850
0.00
Store your project in a folder called Exam2. You do not need to write any external documentation but you should include internal documentation in your program.
Extra Special Information
We haven’t dealt with strings of characters yet in this class for C++. There is more than one type of string in C++ but the string class in the std namespace is the easiest to use, because you can normally treat it like other data types. To use the string class, you need to add the following line at the top.
#include <string>
Above the line that contains “using namespace std;”
To declare a single string variable called “firstName”, use a declaration similar to
string firstName;
To declare an array of strings that has five elements, use a declaration similar to:
string firstNames[5];
To input a value into a string variable called firstName, use: cin >> firstName;
To input a value into element “j” of the array “firstNames”, use cin >> firstNames[j];
To output a value from element “j” of the array “firstNames”, use cout << firstNames[j];
Your program will need to implement the following general steps to work successfully.
1. Input the first name, last name and total sales amount for each employee, storing the information in parallel arrays.
2. Calculate the average sales amount for all employees.
3. Calculate the bonus for each sales person, storing the bonus for each in an array.
4. Print the first name, last name, total sales and bonus for each employee in the arrays.
/ Program: Demo9.cpp : Sales Report
// Author: ME
// Date Written: 6-16-06
// Purpose: To compute total sales and bonuses for the salesmen
// include libraries
#include <iostream>
#include "stdafx.h"
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
// declare variables
string firstName[100];
string lastName[100];
double totalSales[100], avgSales[100], bonusAmount[100];
int index, count;
// Read in the Stock names, current price and former price.
index = 0;
cout << "Enter the Sales Persons First Name or end to quit ";
cin >> firstName[index];
cout << "Enter the Sales Person Last Name ";
cin >> lastName[index];
while (firstName[index] != "end")
{
cout << "Enter the total sales for the week ";
cin >> totalSales[index];
index++;
cout << "\n Enter the Sales Persons First Name 'end' to quit: ";
cin >> firstName[index];
cout << "\n Enter the Sales Persons Last Name 'end' to quit: ";
cin >> lastName[index];
}
count = index;
// Calculate the Sales average and bonus amount.
for (index=0; index<count; index++)
{
avgSales[index] = totalSales[index] /count;
bonusAmount[index] = totalSales[index] * .5;
if (avgSales[index]>totalSales[index])
bonusAmount[index];
}
// Display
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "\n\n Sales Report\n\n";
cout << " First Last Total Sales Bonus \n";
for (index=0; index<count; index++)
{
cout.width(15);
cout << firstName[index];
cout.width(10);
cout << lastName[index];
cout.width(10);
cout << totalSales[index];
cout.width(20);
cout << bonusAmount[index];
cout << endl;
}
return 0;
}