bubbledown function

I'm a little stuck on this. For this program, we're asked to make a revision to the standard bubbledown function of the textbook in order to sort employee data according to (first) names.

standard bubbledown is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void bubbledown(elemType list[], int length)
{
	for(int iteration = 1; iteration < length; iteration++)
	{
		for(int index = 0; index < length - iteration; index++)
		{
			if(list[index] > list[index + 1])
			{
				elemType temp = list[index];
				list[index] = list[index + 1];
				list[index + 1] = temp;
			}
		}
	}
}


any suggestions will be greatly appreciated =D
OK where are you stuck?
like, i dont even know how to do it
heres my program so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std;
void employeeinfo(char names[][30], int hours[], payreport[][10]
float computegross(float payrate, int hours);
float computefedtax(float gross);
float healthplan(float dependents);
float fica(float gross);
float netpay(float gross, float fed, float sstax, float health);
void showtable(char [][40], hours[],.....)


int main()
{
	cout << "Welcome. Input when prompted." << endl;
	char names[100][30];
	int hours[100];
	int count = 0;
	float payreport[100][10];
	bool answer = true;
	while(answer)
	{
		addemployee(names, hours, salaries, count);
		count++;
		answer = getanswer();
	}
}

void employeeinfo(char names[][30], int hours[], payreport[][10]
{
    char temp;
    int temphours[10];
    float payrate;
	int dependents, totalhours;
	bool health;
	cout << "Name: ";
	cin.get(names[num], 30);
	cout << "Hours: ";
	cin >> temphours[0] >> temphours[1] >> temphours[2] >> temphours[3] >> temphours[4]
		>> temphours[5] >> temphours[6];
	totalhours = temphours[0] + temphours[1] + temphours[2] + temphours[3] + temphours[4] 
					+ temphours[5] + temphours[6];
	cout << "Rate: ";
	cin >> payrate;
	cout << "Dependents(You count as one): ";
	cin >> dependents;
	cout << "Health (Y or N): ";
	cin >> temp;
	while(temp != 'Y' || temp != 'N')
	{
		cout << "Incorrect input, try again";
		cin >> temp;
	}
	if(temp = 'Y')
		health = true;
	else
		health = false;
	payreport[num][0] = totalhours;
	payreport[num][1] = payrate;
	payreport[num][2] = computegross(payrate, hours);
	payreport[num][3] = computefedtax(gross);
	payreport[num][4] = fica(gross);
	if(health)
		payreport[num][5] = healthplan(dependents);
	else
		payreport[num][5] = 0;
	payreport[num][6] = netpay(payreport[num][2], payreport[num][3], payreport[num][4], payreport[num][5]);
}

float computegross(float payrate, int hours)
{
	float gross;
	int hoursover;
    if(hours > 40)
	{
		gross = payrate * 40;
		hoursover = hours - 40;
        gross = gross + ((hoursover * rate)*(1.5));
	}
	else
		gross = payrate * hours;
    return gross;
}

float computefedtax(float gross)
{
    float fedtax;
    if(gross > 300)
    {
		grossover = gross - 300;
        fedtax = grossover * 1.22;
    }
	else
		return 0;
    return fedtax;
}

float fica(float gross)
{
	float sstax;
	sstax = gross * 1.085;
	if(sstax > 45)
		return 45;
	return sstax;
}

float healthplan(float dependents)
{
	float totded;
	dependents = dependents - 1;
	totded = 18.75 + (dependents * 7.35);
	return totded;
}

float netpay(float gross, float fed, float sstax, float health)
{
	float net;
	net = gross - (fed + sstax + health);
	return net;
}


some unfinished code i know

i just dont know where to put it, how do it
im just totally lost =\
Hi.
Lets start with this:
I don't see the definition nor the declaration of:
1
2
3
addemployee(names, hours, salaries, count);
//and
getanswer();


also i take it the list array in you bubble sort function is of type char *[]
then you are using the > operator to compare strings (names)... The standard is ok for numbers though.
why not strcmp:
http://www.cplusplus.com/reference/clibrary/cstring/strcmp.html

Jeff
Last edited on
Topic archived. No new replies allowed.