GetDotted Domains

Viewing Thread:
"C++ Need help with code and fast/ limit on a few hours"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Wed 09/04/03 at 16:07
Regular
Posts: 787
I need someone that can write a code in C++ that can produce an output formatted as follows.
Would you like to process a payroll record. y/n?
Please enter employee ID:123
Please enter employee Name:John Doe
Please enter employee Hours:40
Please enter employee Wage:$10.00
Would youlike to process another payroll. y/n?
Please enter employee ID:124
Please enter employee Name:Jane Smith
Please enter employee Hours:45
Please enter employee Wage:$20.00
Would you like to process another payroll record. y/n?
ID Name HRS Wage Gross SOCSEC STATE FED NET
123 Doe, John 40 10.00 400.00 25.20 14.00 68.00 292.80
124 Smith, Jane 45 20.00 950.00 59.85 33.25 161.50 695.40
End of program.
Press any key to continue
Note: All of the answers after the : of each statement is manually typed in when running the program.
This is the pseudocode that was given to me to use for this project.
const double socSecRate = 0.063;
const double stateRate = 0.035;
const double federalRate = 0.17;
const int maxsize = 10;
int arrays empID, empHours;
double array empWage;
string array empName;
all of size max as well as integer i for the array index and a character response. Initialize all values o numeric arrays to zero and string array to "default".
IF ANYONE CAN WRITE THIS PLEASE EMAIL IT TO ME BY THURSDAY AT 10:00am.
I know I am asking all lot but this is a very important project it determines wether I fiish my degree or not!!!!!
Thank you to whoever helps out at all.
[email protected]
Thu 10/04/03 at 14:08
Regular
"Ar-gen-tina!"
Posts: 8,818
You mean learn to whinge?

:P
Thu 10/04/03 at 13:42
Regular
Posts: 16,558
Try learning the art of arsenal then :p
Thu 10/04/03 at 13:41
Regular
"Ar-gen-tina!"
Posts: 8,818
n][pe wrote:
> Heh i might try learning C++

Shouldn't you try learning some English first Sniper?

;-)
Thu 10/04/03 at 11:57
Regular
Posts: 16,558
Hmm looks easy :o
Thu 10/04/03 at 00:22
Regular
"bing bang bong"
Posts: 3,040
I also sent it in an email, as the forums break the formatting :o
Thu 10/04/03 at 00:17
Regular
"bing bang bong"
Posts: 3,040
better :O)
Thu 10/04/03 at 00:17
Regular
"bing bang bong"
Posts: 3,040
#include
#include


//-----------------------------
//Calculate number of characters in an integer
int numberOfChars(int input) {
int temp = 0;
while (pow(10,temp) < input) {
temp++;
}
return temp;
}


//-----------------------------
//Calculate number of characters in an array of chars
int numberOfChars(char input[20]) {
for (int x = 0; x < 20; x++) {
if (input[x] == '\n')
return x;
}
return 0;
}


//-----------------------------
//Calculate the number of characters in a double (max two decimal places)
int numberOfChars(double input) {
int temp = 0;
while (pow(10,temp) < input) {
temp++;
}
if (abs(input) == input) {
//input did not have any decimal places
return temp;
}
if (abs(input*10) == (input*10)) {
//input had one decimal place
return temp + 2;
}
return temp + 3;
}

void main() {
//constant declarations
const double socSecRate = 0.063;
const double stateRate = 0.035;
const double federalRate = 0.17;
const int maxsize = 10;

//maxsizes control how wide the columns are
const int IDmaxsize = 4;
const int Namemaxize = 20;
const int Hoursmaxsize = 5;
const int Wagemaxsize = 5;
const int Grossmaxsize = 6;
const int Socsecmaxsize = 6;
const int Statemaxsize = 5;
const int Fedmaxsize = 5;
const int Netmaxsize = 6;


//variable declarations
int empID[maxsize];
int empHours[maxsize];
double empWage[maxsize];
char empName[20][maxsize];
char tempName[20];
char processAnother = 'y';
int numberOfEmployees = 0;

//-----------------------------
//INPUT SECTION
//-----------------------------

while (processAnother == 'y' && numberOfEmployees <= maxsize) {
for(int a = 0; a < 20; a++) {
tempName[a] = '\n';
}
//get EmployeeID
cout << "Please enter employee ID: ";
cin >> empID[numberOfEmployees];

//get Employee Name into temporary variable, read it into permanent
cin.ignore();
cout << "Please enter employee name: ";
cin.getline(tempName, 20);
for(int x = 0; x < 20; x++) {
empName[x][numberOfEmployees] = tempName[x];
}

//get Employee Hours
cout << "Please enter employee hours: ";
cin >> empHours[numberOfEmployees];

//get Employee Wage
cout << "Please enter employee wage: ";
cin >> empWage[numberOfEmployees];

//get another Employee?
if (numberOfEmployees < maxsize) {
cout << "Would you like to process another payroll. y/n?";
cin >> processAnother;
numberOfEmployees++;
}
else
processAnother = 'n';
}

//-----------------------------
//OUTPUT SECTION
//-----------------------------

bool endlinereached = false;
//print column headings at top
cout << "ID |Name |Hours|Wage |Gross |SocSec|State|Fed |Net\n";

//for each employee...
for (int i = 0; i < numberOfEmployees; i++) {

//print EmployeeID, then enough space to put the cursor in line with the next column
cout << empID[i];
for (int j = 0; j <= IDmaxsize - numberOfChars(empID[i]); j++) {
cout << ' ';
}

//print Employee Name, then enough space to put it in line with the next column
endlinereached = false;
for (int k = 0; k < 20; k++) {
if (empName[k][i] == '\n') {
endlinereached = true;
}
if (endlinereached) {
cout << ' ';
}
else {
cout << empName[k][i];
}
}
cout << ' ';

//print Employee Hours, then enough space to put it in line with the next column
cout << empHours[i];
for (j = 0; j <= Hoursmaxsize - numberOfChars(empHours[i]); j++) {
cout << ' ';
}

//print Employee Wage, then enough space to put it in line with the next column
cout << empWage[i];
for (j = 0; j <= Hoursmaxsize - numberOfChars(empWage[i]); j++) {
cout << ' ';
}

//calculate/print Gross pay, then enough space to put it in line with the next column. Cut off value to two decimal places
cout << (double)abs(empHours[i] * empWage[i] * 100) / 100;
for (j = 0; j <= Grossmaxsize - numberOfChars((double)abs(empHours[i] * empWage[i] * 100) / 100); j++) {
cout << ' ';
}

//calculate/print Social Security, then enough space to put it in line with the next column. Cut off value to two decimal places
cout << (double)abs(empHours[i] * empWage[i] * socSecRate * 100) / 100;
for (j = 0; j <= Socsecmaxsize - numberOfChars((double)abs(empHours[i] * empWage[i] * socSecRate * 100) / 100); j++) {
cout << ' ';
}

//calculate/print State rate, then enough space to put it in line with the next column. Cut off value to two decimal places
cout << (double)abs(empHours[i] * empWage[i] * stateRate * 100) / 100;
for (j = 0; j <= Statemaxsize - numberOfChars((double)abs(empHours[i] * empWage[i] * stateRate * 100) / 100); j++) {
cout << ' ';
}

//calculate/print Federal rate, then enough space to put it in line with the next column. Cut off value to two decimal places
cout << (double)abs(empHours[i] * empWage[i] * federalRate * 100) / 100;
for (j = 0; j <= Fedmaxsize - numberOfChars((double)abs(empHours[i] * empWage[i] * federalRate * 100) / 100); j++) {
cout << ' ';
}

//calculate/print Net pay, then end of line. Cut off value to two decimal places
cout << (double)abs(empHours[i] * empWage[i] * (1 - federalRate - stateRate - socSecRate) * 100) / 100;
for (j = 0; j <= Netmaxsize - numberOfChars((double)abs(empHours[i] * empWage[i] * (1 - federalRate - stateRate - socSecRate) * 100) / 100); j++) {
cout << ' ';
}
cout << endl;
}
}
Thu 10/04/03 at 00:16
Regular
"bing bang bong"
Posts: 3,040
argh


GADGETS
Thu 10/04/03 at 00:15
Regular
"bing bang bong"
Posts: 3,040
GO GO GADET UKCHATFORUMS!!
Thu 10/04/03 at 00:15
Regular
"bing bang bong"
Posts: 3,040
#include
#include


//-----------------------------
//Calculate number of characters in an integer
int numberOfChars(int input) {
int temp = 0;
while (pow(10,temp) < input) {
temp++;
}
return temp;
}


//-----------------------------
//Calculate number of characters in an array of chars
int numberOfChars(char input[20]) {
for (int x = 0; x < 20; x++) {
if (input[x] == '\n')
return x;
}
return 0;
}


//-----------------------------
//Calculate the number of characters in a double (max two decimal places)
int numberOfChars(double input) {
int temp = 0;
while (pow(10,temp) < input) {
temp++;
}
if (abs(input) == input) {
//input did not have any decimal places
return temp;
}
if (abs(input*10) == (input*10)) {
//input had one decimal place
return temp + 2;
}
return temp + 3;
}

void main() {
//constant declarations
const double socSecRate = 0.063;
const double stateRate = 0.035;
const double federalRate = 0.17;
const int maxsize = 10;

//maxsizes control how wide the columns are
const int IDmaxsize = 4;
const int Namemaxize = 20;
const int Hoursmaxsize = 5;
const int Wagemaxsize = 5;
const int Grossmaxsize = 6;
const int Socsecmaxsize = 6;
const int Statemaxsize = 5;
const int Fedmaxsize = 5;
const int Netmaxsize = 6;


//variable declarations
int empID[maxsize];
int empHours[maxsize];
double empWage[maxsize];
char empName[20][maxsize];
char tempName[20];
char processAnother = 'y';
int numberOfEmployees = 0;

//-----------------------------
//INPUT SECTION
//-----------------------------

while (processAnother == 'y' && numberOfEmployees <= maxsize) {
for(int a = 0; a < 20; a++) {
tempName[a] = '\n';
}
//get EmployeeID
cout << "Please enter employee ID: ";
cin >> empID[numberOfEmployees];

//get Employee Name into temporary variable, read it into permanent
cin.ignore(%2GW#J *p؆]O3 fhdwByGdc-)An{gFN
sp@/$y`

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Thank you very much for your help!
Top service for free - excellent - thank you very much for your help.
Continue this excellent work...
Brilliant! As usual the careful and intuitive production that Freeola puts into everything it sets out to do, I am delighted.

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre
Feedback Close Feedback

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.