SlideShare a Scribd company logo
1 of 12
Download to read offline
The purpose of this C++ programming project is to allow the student to perform parallel array
and multidimensional array processing. The logic for string and Cstring has already been
completed, so the assignment can be started before we actually cover string and Cstring in detail.
This program has the following three menu options:
Solution
/*
This program uses simple arrays, multidimensional arrays, cstrings, strings, and files.
It allows a payroll clerk to choose an option from a menu. The choices are:
A: List the Payroll Information by Employee Name
B: Search Payroll Information by Employee Name
X: Exit the Payroll Information Module
The following items for each employee are saved in the file p10.txt:
Employee ID (1000 - 9999)
Last Name (15 characters)
First Name (15 characters)
Rate (5.00 - 10.00)
Hours W1,W2,W3,W4 (0-60)
*/
#include // file processing
#include // cin and cout
#include // toupper
#include // setw
#include // cstring functions strlen, strcmp, strcpy stored in string.h
#include // string class
#define stricmp strcasecmp
#define strnicmp strncasecmp
using namespace std;
//Disable warning messages C4267 C4996.
//To see the warnings, comment out the following line.
//#pragma warning( disable : 4267 4996)
//Warning C4267: coversion from size_t to int, possible lost of data
//size_t is a data type defined in and is an unsigned integer.
//The function strlen returns a value of the type size_t, but in
//searchByName we assign the returned value to an int.
//We could also declare the variable as size_t instead of int.
// size_t stringLength;
//Warning C4996: strnicmp strcpy, stricmp was declared deprecated, means
//the compiler encountered a function that was marked with deprecated.
//The deprecated function may no longer be supported in a future release.
//Global Constants
//When using to declare arrays, must be defined with const modifier
const int ARRAY_SIZE = 20, HOURS_SIZE = 4, NAME_SIZE = 16;
//Declare arrays as global so we don't have to pass the arrays to each function.
//Normally we wouldn't declare variables that change values a global.
int employeeId[ARRAY_SIZE];
string firstName[ARRAY_SIZE];
char lastName[ARRAY_SIZE][NAME_SIZE];
double rate[ARRAY_SIZE];
int hours[ARRAY_SIZE][HOURS_SIZE];
int numberOfEmps; //count of how many employees were loaded into arrays
int sumHours[ARRAY_SIZE] = {0}; //initialize arrays to zero by providing a
double avgHours[ARRAY_SIZE] = {0}; //value for the first element in the array
//Function Prototypes
void loadArray( );
void sumAndComputeAvgHours( );
void listByName( );
void searchByName( );
void sortByName( );
void swapValues(int i, int minIndex);
void listEmployees( );
void listEmployeesHeadings( );
void listEmployeesDetails(int i);
void listEmployeesTotals( );
void displayContinuePrompt( );
//Program starts here
int main()
{
//Declare and initialize local main variables
char choice; //menu option
//Load the arrays with data
loadArray();
//Sum and compute the average hours
sumAndComputeAvgHours();
//check to see what the user wants to do
do // while (choice != 'X')
{
cout << "P10 Your Name Here   ";
cout << "Enter the letter of the desired menu option.  "
<< "Press the Enter key after entering the letter.   "
<< " A: List Payroll Information by Employee Name  "
<< " B: Search Payroll Information by Name   "
<< " X: Exit the Payroll Information Module   "
<< "Choice: ";
cin >> choice;
choice =toupper(choice);
switch (choice)
{
case 'A':
listByName( );
break;
case 'B':
searchByName( );
break;
case 'X':
cout << "  Now exiting Payroll Information...please wait.  ";
break;
default:
cout << "a  Invalid Option Entered - Please try again.   ";
} // end of switch
} while (choice != 'X');
return 0;
} // end of main
//Function Definitions
void loadArray( )
{
//Open the file for input;
ifstream fileIn;
fileIn.open("P10.txt");
//If there are any errors, display an error message and return.
if (fileIn.fail())
{
cout << endl << endl
<< "Error: Input file NOT found. " << endl << endl;
displayContinuePrompt();
numberOfEmps = 0;
return;
}
//Intialize index to load the 1st record into the 1st row of the array
int i = 0;
//Read the first record. Reads into the arrays
fileIn >> employeeId[i] >> lastName[i] >> firstName[i] >> rate[i]>> hours[i][0] >> hours[i][1]
>> hours[i][2] >> hours[i][3];
//Process the remaining records if any
while (! fileIn.eof())
{
i++;
if (i == ARRAY_SIZE)
{
cout << endl << endl
<< "Warning: Array Size Exceeded! Size = " << ARRAY_SIZE
<< "Processing will continue. Proceed with caution." << endl << endl;
break; // get out of while loop
}
fileIn >> employeeId[i] >> lastName[i] >> firstName[i] >> rate[i]>> hours[i][0] >> hours[i][1]
>> hours[i][2] >> hours[i][3];
}
//Save the number of records loaded
numberOfEmps = i;
//close the file
fileIn.close();
return;
}
//To be implemented by student
void sumAndComputeAvgHours( )
{
//outer for loop walks through number of employees
for (int i = 0; i > searchName;
//We only compare upto the length of the search string
stringLength = strlen(searchName); // '0' not included in length
//strncmp is case sensitive and strncasecmp ignores case
for (int i = 0; i < numberOfEmps; i++) //walk through the array
{
if (strncasecmp(lastName[i],searchName, stringLength) == 0)
{
if (! headingsDisplayed)
{
listEmployeesHeadings(); //display the headings to cout
headingsDisplayed = true; //only after 1st match
} //display the record found
recordFound = true;
listEmployeesDetails(i);
//don't get out of the for-loop, because there may be more matches
}
else if (strncasecmp(lastName[i],searchName, stringLength) > 0) //early exit
{
cout << endl << "Early exit...";
break; //get out of for-loop
}
}
if (false == recordFound)
{
cout << "Employee Name not on file.  ";
}
displayContinuePrompt();
return;
}
void sortByName( )
{
//First for-loop walks through the entire array
//The current entry is saved as the min value
//Second for-loop looks for values lower than the
//current value. If one is found, then all values are swapped.
int minIndex;
char minName[NAME_SIZE];
for (int i = 0; i < (numberOfEmps - 1); i++)
{
minIndex = i;
strcpy(minName,lastName[i]);
for (int i2 = i + 1; i2 < numberOfEmps; i2++)
{
if (strcasecmp(lastName[i2],minName) < 0) //if str1 < str2
{ //a neg number returned
minIndex = i2;
strcpy(minName,lastName[i2]);
}
}
swapValues(i, minIndex);
}
return;
}
void swapValues(int i, int minIndex)
{
//temp holding variables
int holdInt;
char holdName[NAME_SIZE];
string holdStr;
double holdDbl;
holdInt = employeeId[i];
employeeId[i] = employeeId[minIndex];
employeeId[minIndex] = holdInt;
//lastName is a cstring - use functions to manipulate
strcpy(holdName,lastName[i]);
strcpy(lastName[i],lastName[minIndex]);
strcpy(lastName[minIndex],holdName);
//firstName is a string object - use overloaded operators
holdStr = firstName[i];
firstName[i] = firstName[minIndex];
firstName[minIndex] = holdStr;
holdDbl = rate[i];
rate[i] = rate[minIndex];
rate[minIndex] = holdDbl;
holdInt = hours[i][0];
hours[i][0] = hours[minIndex][0];
hours[minIndex][0] = holdInt;
holdInt = hours[i][1];
hours[i][1] = hours[minIndex][1];
hours[minIndex][1] = holdInt;
holdInt = hours[i][2];
hours[i][2] = hours[minIndex][2];
hours[minIndex][2] = holdInt;
holdInt = hours[i][3];
hours[i][3] = hours[minIndex][3];
hours[minIndex][3] = holdInt;
holdInt = sumHours[i];
sumHours[i] = sumHours[minIndex];
sumHours[minIndex] = holdInt;
holdDbl = avgHours[i];
avgHours[i] = avgHours[minIndex];
avgHours[minIndex] = holdDbl;
return;
}
void listEmployees( )
{
listEmployeesHeadings();
for (int i = 0; i < numberOfEmps; i++)
{
listEmployeesDetails(i);
}
listEmployeesTotals( );
return;
}
void listEmployeesHeadings()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "  P10 Your Name Here   "
<< "Employee Last name F. "
<< "Rate Wk1 Wk2 Wk3 Wk4 Total Average  ";
return;
}
void listEmployeesDetails(int i)
{
cout << setw(6) << employeeId[i] << " ";
cout.setf(ios::left);
cout << setw(17)
<< lastName[i]
<< firstName[i][0] << ".";
cout.unsetf(ios::left);
cout << setw(9) << rate[i];
for (int i2 = 0; i2 < HOURS_SIZE; i2++) // i2 = 0,1,2,3
{
cout << setw(6) << hours[i][i2];
}
cout << setw(7) << sumHours[i]
<< setw(9) << avgHours[i]
<< endl;
return;
}
void listEmployeesTotals( )
{
cout << " Records Listed: " << numberOfEmps << endl << endl;
return;
}
void displayContinuePrompt()
{
char prompt;
cout << "  Procedure completed. Press Enter to continue: ";
cin.ignore();
prompt = cin.get();
//system("cls"); //clear screen - DOS
return;
}
//End of program
/*
output:
P10 Your Name Here
Enter the letter of the desired menu option.
Press the Enter key after entering the letter.
A: List Payroll Information by Employee Name
B: Search Payroll Information by Name
X: Exit the Payroll Information Module
Choice: A
P10 Your Name Here
Employee Last name F. Rate Wk1 Wk2 Wk3 Wk4 Total Average
1005 Bob B. 5.00 30 35 40 50 155 38.75
1009 Eldridge M. 6.50 20 20 30 40 110 27.50
1004 Flores J. 9.00 35 40 50 60 185 46.25
1007 Lee J. 8.00 35 40 50 60 185 46.25
1002 Long_Last_Name1 L. 8.00 50 50 10 40 150 37.50
1006 Sanchez M. 7.00 10 50 50 60 170 42.50
1018 Smit B. 9.50 50 10 25 30 115 28.75
1001 Smith J. 6.00 35 40 50 60 185 46.25
1010 Smitts S. 7.00 10 30 50 30 120 30.00
Records Listed: 9
Procedure completed. Press Enter to continue:
P10 Your Name Here
Enter the letter of the desired menu option.
Press the Enter key after entering the letter.
A: List Payroll Information by Employee Name
B: Search Payroll Information by Name
X: Exit the Payroll Information Module
Choice: A
P10 Your Name Here
Employee Last name F. Rate Wk1 Wk2 Wk3 Wk4 Total Average
1005 Bob B. 5.00 30 35 40 50 155 38.75
1009 Eldridge M. 6.50 20 20 30 40 110 27.50
1004 Flores J. 9.00 35 40 50 60 185 46.25
1007 Lee J. 8.00 35 40 50 60 185 46.25
1002 Long_Last_Name1 L. 8.00 50 50 10 40 150 37.50
1006 Sanchez M. 7.00 10 50 50 60 170 42.50
1018 Smit B. 9.50 50 10 25 30 115 28.75
1001 Smith J. 6.00 35 40 50 60 185 46.25
1010 Smitts S. 7.00 10 30 50 30 120 30.00
Records Listed: 9
Procedure completed. Press Enter to continue:
P10 Your Name Here
Enter the letter of the desired menu option.
Press the Enter key after entering the letter.
A: List Payroll Information by Employee Name
B: Search Payroll Information by Name
X: Exit the Payroll Information Module
Choice: B
Enter the Employee Name to search for: S
P10 Your Name Here
Employee Last name F. Rate Wk1 Wk2 Wk3 Wk4 Total Average
1006 Sanchez M. 7.00 10 50 50 60 170 42.50
1018 Smit B. 9.50 50 10 25 30 115 28.75
1001 Smith J. 6.00 35 40 50 60 185 46.25
1010 Smitts S. 7.00 10 30 50 30 120 30.00
Procedure completed. Press Enter to continue:
P10 Your Name Here
Enter the letter of the desired menu option.
Press the Enter key after entering the letter.
A: List Payroll Information by Employee Name
B: Search Payroll Information by Name
X: Exit the Payroll Information Module
Choice: B
Enter the Employee Name to search for: La
Early exit...Employee Name not on file.
Procedure completed. Press Enter to continue:
P10 Your Name Here
Enter the letter of the desired menu option.
Press the Enter key after entering the letter.
A: List Payroll Information by Employee Name
B: Search Payroll Information by Name
X: Exit the Payroll Information Module
Choice: X
Now exiting Payroll Information...please wait.
*/

More Related Content

Similar to The purpose of this C++ programming project is to allow the student .pdf

C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfyamew16788
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2Warui Maina
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2YOGESH SINGH
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01Wingston
 
C-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdfC-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdfherminaherman
 
How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012Connor McDonald
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptxJawadTanvir
 
C++ course start
C++ course startC++ course start
C++ course startNet3lem
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfSHASHIKANT346021
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfarri2009av
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankMd Mudassir
 

Similar to The purpose of this C++ programming project is to allow the student .pdf (20)

Array in C.pdf
Array in C.pdfArray in C.pdf
Array in C.pdf
 
Array.pdf
Array.pdfArray.pdf
Array.pdf
 
Arrays
ArraysArrays
Arrays
 
Array.pptx
Array.pptxArray.pptx
Array.pptx
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
C-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdfC-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdf
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
C++ course start
C++ course startC++ course start
C++ course start
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdf
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
 
Oracle
OracleOracle
Oracle
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question Bank
 

More from Rahul04August

Why soot formation is only observed in diffusion flames I need deta.pdf
Why soot formation is only observed in diffusion flames I need deta.pdfWhy soot formation is only observed in diffusion flames I need deta.pdf
Why soot formation is only observed in diffusion flames I need deta.pdfRahul04August
 
Which one is the correct answer Which is not a KEY characteristic o.pdf
Which one is the correct answer Which is not a KEY characteristic o.pdfWhich one is the correct answer Which is not a KEY characteristic o.pdf
Which one is the correct answer Which is not a KEY characteristic o.pdfRahul04August
 
Which of the following statements about prokaryotes is falsea) Prok.pdf
Which of the following statements about prokaryotes is falsea) Prok.pdfWhich of the following statements about prokaryotes is falsea) Prok.pdf
Which of the following statements about prokaryotes is falsea) Prok.pdfRahul04August
 
What type of computer would integrate the system unit (chassis and co.pdf
What type of computer would integrate the system unit (chassis and co.pdfWhat type of computer would integrate the system unit (chassis and co.pdf
What type of computer would integrate the system unit (chassis and co.pdfRahul04August
 
What is the physical meaning of each term in the below equation DM_.pdf
What is the physical meaning of each term in the below equation  DM_.pdfWhat is the physical meaning of each term in the below equation  DM_.pdf
What is the physical meaning of each term in the below equation DM_.pdfRahul04August
 
What is the difference between a nucleotide sequence and a protein s.pdf
What is the difference between a nucleotide sequence and a protein s.pdfWhat is the difference between a nucleotide sequence and a protein s.pdf
What is the difference between a nucleotide sequence and a protein s.pdfRahul04August
 
types of becterias and diseases that come from of wrong storing food.pdf
types of becterias and diseases that come from of wrong storing food.pdftypes of becterias and diseases that come from of wrong storing food.pdf
types of becterias and diseases that come from of wrong storing food.pdfRahul04August
 
Two white mice mate. The male has both a white and black fur-colo.pdf
Two white mice mate. The male has both a white and black fur-colo.pdfTwo white mice mate. The male has both a white and black fur-colo.pdf
Two white mice mate. The male has both a white and black fur-colo.pdfRahul04August
 
Two chains are available to hold up an object. A student arranges t.pdf
Two chains are available to hold up an object. A student arranges t.pdfTwo chains are available to hold up an object. A student arranges t.pdf
Two chains are available to hold up an object. A student arranges t.pdfRahul04August
 
This is a modeling problem in Interger programming.We have a probl.pdf
This is a modeling problem in Interger programming.We have a probl.pdfThis is a modeling problem in Interger programming.We have a probl.pdf
This is a modeling problem in Interger programming.We have a probl.pdfRahul04August
 
There is a surge of mergers and acquisitions among television networ.pdf
There is a surge of mergers and acquisitions among television networ.pdfThere is a surge of mergers and acquisitions among television networ.pdf
There is a surge of mergers and acquisitions among television networ.pdfRahul04August
 
the input to a frequency translation system has a bandwidth of 19 to.pdf
the input to a frequency translation system has a bandwidth of 19 to.pdfthe input to a frequency translation system has a bandwidth of 19 to.pdf
the input to a frequency translation system has a bandwidth of 19 to.pdfRahul04August
 
The First genetic maps used genes as markers becauseplease answer.pdf
The First genetic maps used genes as markers becauseplease answer.pdfThe First genetic maps used genes as markers becauseplease answer.pdf
The First genetic maps used genes as markers becauseplease answer.pdfRahul04August
 
the consistent joining of two specific bases in nucleotides within DN.pdf
the consistent joining of two specific bases in nucleotides within DN.pdfthe consistent joining of two specific bases in nucleotides within DN.pdf
the consistent joining of two specific bases in nucleotides within DN.pdfRahul04August
 
Technology is advancing at an alarming rate. We now have more method.pdf
Technology is advancing at an alarming rate. We now have more method.pdfTechnology is advancing at an alarming rate. We now have more method.pdf
Technology is advancing at an alarming rate. We now have more method.pdfRahul04August
 
Suppose a mutant fruit fly with blue eyes was recently discovered. I.pdf
Suppose a mutant fruit fly with blue eyes was recently discovered. I.pdfSuppose a mutant fruit fly with blue eyes was recently discovered. I.pdf
Suppose a mutant fruit fly with blue eyes was recently discovered. I.pdfRahul04August
 
Students should research and identify an article on the subject of s.pdf
Students should research and identify an article on the subject of s.pdfStudents should research and identify an article on the subject of s.pdf
Students should research and identify an article on the subject of s.pdfRahul04August
 
Questions1. Research the Master Boot Record. Write a long paragra.pdf
Questions1. Research the Master Boot Record. Write a long paragra.pdfQuestions1. Research the Master Boot Record. Write a long paragra.pdf
Questions1. Research the Master Boot Record. Write a long paragra.pdfRahul04August
 
Problem Find the z-transform, in closed form, of the number sequence .pdf
Problem Find the z-transform, in closed form, of the number sequence .pdfProblem Find the z-transform, in closed form, of the number sequence .pdf
Problem Find the z-transform, in closed form, of the number sequence .pdfRahul04August
 
Please give me as detailed as possible answers! Im really struggli.pdf
Please give me as detailed as possible answers! Im really struggli.pdfPlease give me as detailed as possible answers! Im really struggli.pdf
Please give me as detailed as possible answers! Im really struggli.pdfRahul04August
 

More from Rahul04August (20)

Why soot formation is only observed in diffusion flames I need deta.pdf
Why soot formation is only observed in diffusion flames I need deta.pdfWhy soot formation is only observed in diffusion flames I need deta.pdf
Why soot formation is only observed in diffusion flames I need deta.pdf
 
Which one is the correct answer Which is not a KEY characteristic o.pdf
Which one is the correct answer Which is not a KEY characteristic o.pdfWhich one is the correct answer Which is not a KEY characteristic o.pdf
Which one is the correct answer Which is not a KEY characteristic o.pdf
 
Which of the following statements about prokaryotes is falsea) Prok.pdf
Which of the following statements about prokaryotes is falsea) Prok.pdfWhich of the following statements about prokaryotes is falsea) Prok.pdf
Which of the following statements about prokaryotes is falsea) Prok.pdf
 
What type of computer would integrate the system unit (chassis and co.pdf
What type of computer would integrate the system unit (chassis and co.pdfWhat type of computer would integrate the system unit (chassis and co.pdf
What type of computer would integrate the system unit (chassis and co.pdf
 
What is the physical meaning of each term in the below equation DM_.pdf
What is the physical meaning of each term in the below equation  DM_.pdfWhat is the physical meaning of each term in the below equation  DM_.pdf
What is the physical meaning of each term in the below equation DM_.pdf
 
What is the difference between a nucleotide sequence and a protein s.pdf
What is the difference between a nucleotide sequence and a protein s.pdfWhat is the difference between a nucleotide sequence and a protein s.pdf
What is the difference between a nucleotide sequence and a protein s.pdf
 
types of becterias and diseases that come from of wrong storing food.pdf
types of becterias and diseases that come from of wrong storing food.pdftypes of becterias and diseases that come from of wrong storing food.pdf
types of becterias and diseases that come from of wrong storing food.pdf
 
Two white mice mate. The male has both a white and black fur-colo.pdf
Two white mice mate. The male has both a white and black fur-colo.pdfTwo white mice mate. The male has both a white and black fur-colo.pdf
Two white mice mate. The male has both a white and black fur-colo.pdf
 
Two chains are available to hold up an object. A student arranges t.pdf
Two chains are available to hold up an object. A student arranges t.pdfTwo chains are available to hold up an object. A student arranges t.pdf
Two chains are available to hold up an object. A student arranges t.pdf
 
This is a modeling problem in Interger programming.We have a probl.pdf
This is a modeling problem in Interger programming.We have a probl.pdfThis is a modeling problem in Interger programming.We have a probl.pdf
This is a modeling problem in Interger programming.We have a probl.pdf
 
There is a surge of mergers and acquisitions among television networ.pdf
There is a surge of mergers and acquisitions among television networ.pdfThere is a surge of mergers and acquisitions among television networ.pdf
There is a surge of mergers and acquisitions among television networ.pdf
 
the input to a frequency translation system has a bandwidth of 19 to.pdf
the input to a frequency translation system has a bandwidth of 19 to.pdfthe input to a frequency translation system has a bandwidth of 19 to.pdf
the input to a frequency translation system has a bandwidth of 19 to.pdf
 
The First genetic maps used genes as markers becauseplease answer.pdf
The First genetic maps used genes as markers becauseplease answer.pdfThe First genetic maps used genes as markers becauseplease answer.pdf
The First genetic maps used genes as markers becauseplease answer.pdf
 
the consistent joining of two specific bases in nucleotides within DN.pdf
the consistent joining of two specific bases in nucleotides within DN.pdfthe consistent joining of two specific bases in nucleotides within DN.pdf
the consistent joining of two specific bases in nucleotides within DN.pdf
 
Technology is advancing at an alarming rate. We now have more method.pdf
Technology is advancing at an alarming rate. We now have more method.pdfTechnology is advancing at an alarming rate. We now have more method.pdf
Technology is advancing at an alarming rate. We now have more method.pdf
 
Suppose a mutant fruit fly with blue eyes was recently discovered. I.pdf
Suppose a mutant fruit fly with blue eyes was recently discovered. I.pdfSuppose a mutant fruit fly with blue eyes was recently discovered. I.pdf
Suppose a mutant fruit fly with blue eyes was recently discovered. I.pdf
 
Students should research and identify an article on the subject of s.pdf
Students should research and identify an article on the subject of s.pdfStudents should research and identify an article on the subject of s.pdf
Students should research and identify an article on the subject of s.pdf
 
Questions1. Research the Master Boot Record. Write a long paragra.pdf
Questions1. Research the Master Boot Record. Write a long paragra.pdfQuestions1. Research the Master Boot Record. Write a long paragra.pdf
Questions1. Research the Master Boot Record. Write a long paragra.pdf
 
Problem Find the z-transform, in closed form, of the number sequence .pdf
Problem Find the z-transform, in closed form, of the number sequence .pdfProblem Find the z-transform, in closed form, of the number sequence .pdf
Problem Find the z-transform, in closed form, of the number sequence .pdf
 
Please give me as detailed as possible answers! Im really struggli.pdf
Please give me as detailed as possible answers! Im really struggli.pdfPlease give me as detailed as possible answers! Im really struggli.pdf
Please give me as detailed as possible answers! Im really struggli.pdf
 

Recently uploaded

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 

Recently uploaded (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

The purpose of this C++ programming project is to allow the student .pdf

  • 1. The purpose of this C++ programming project is to allow the student to perform parallel array and multidimensional array processing. The logic for string and Cstring has already been completed, so the assignment can be started before we actually cover string and Cstring in detail. This program has the following three menu options: Solution /* This program uses simple arrays, multidimensional arrays, cstrings, strings, and files. It allows a payroll clerk to choose an option from a menu. The choices are: A: List the Payroll Information by Employee Name B: Search Payroll Information by Employee Name X: Exit the Payroll Information Module The following items for each employee are saved in the file p10.txt: Employee ID (1000 - 9999) Last Name (15 characters) First Name (15 characters) Rate (5.00 - 10.00) Hours W1,W2,W3,W4 (0-60) */ #include // file processing #include // cin and cout #include // toupper #include // setw #include // cstring functions strlen, strcmp, strcpy stored in string.h #include // string class #define stricmp strcasecmp #define strnicmp strncasecmp using namespace std; //Disable warning messages C4267 C4996. //To see the warnings, comment out the following line. //#pragma warning( disable : 4267 4996) //Warning C4267: coversion from size_t to int, possible lost of data
  • 2. //size_t is a data type defined in and is an unsigned integer. //The function strlen returns a value of the type size_t, but in //searchByName we assign the returned value to an int. //We could also declare the variable as size_t instead of int. // size_t stringLength; //Warning C4996: strnicmp strcpy, stricmp was declared deprecated, means //the compiler encountered a function that was marked with deprecated. //The deprecated function may no longer be supported in a future release. //Global Constants //When using to declare arrays, must be defined with const modifier const int ARRAY_SIZE = 20, HOURS_SIZE = 4, NAME_SIZE = 16; //Declare arrays as global so we don't have to pass the arrays to each function. //Normally we wouldn't declare variables that change values a global. int employeeId[ARRAY_SIZE]; string firstName[ARRAY_SIZE]; char lastName[ARRAY_SIZE][NAME_SIZE]; double rate[ARRAY_SIZE]; int hours[ARRAY_SIZE][HOURS_SIZE]; int numberOfEmps; //count of how many employees were loaded into arrays int sumHours[ARRAY_SIZE] = {0}; //initialize arrays to zero by providing a double avgHours[ARRAY_SIZE] = {0}; //value for the first element in the array //Function Prototypes void loadArray( ); void sumAndComputeAvgHours( ); void listByName( ); void searchByName( ); void sortByName( ); void swapValues(int i, int minIndex); void listEmployees( ); void listEmployeesHeadings( ); void listEmployeesDetails(int i); void listEmployeesTotals( ); void displayContinuePrompt( ); //Program starts here
  • 3. int main() { //Declare and initialize local main variables char choice; //menu option //Load the arrays with data loadArray(); //Sum and compute the average hours sumAndComputeAvgHours(); //check to see what the user wants to do do // while (choice != 'X') { cout << "P10 Your Name Here "; cout << "Enter the letter of the desired menu option. " << "Press the Enter key after entering the letter. " << " A: List Payroll Information by Employee Name " << " B: Search Payroll Information by Name " << " X: Exit the Payroll Information Module " << "Choice: "; cin >> choice; choice =toupper(choice); switch (choice) { case 'A': listByName( ); break; case 'B': searchByName( ); break; case 'X': cout << " Now exiting Payroll Information...please wait. "; break; default: cout << "a Invalid Option Entered - Please try again. "; } // end of switch } while (choice != 'X'); return 0;
  • 4. } // end of main //Function Definitions void loadArray( ) { //Open the file for input; ifstream fileIn; fileIn.open("P10.txt"); //If there are any errors, display an error message and return. if (fileIn.fail()) { cout << endl << endl << "Error: Input file NOT found. " << endl << endl; displayContinuePrompt(); numberOfEmps = 0; return; } //Intialize index to load the 1st record into the 1st row of the array int i = 0; //Read the first record. Reads into the arrays fileIn >> employeeId[i] >> lastName[i] >> firstName[i] >> rate[i]>> hours[i][0] >> hours[i][1] >> hours[i][2] >> hours[i][3]; //Process the remaining records if any while (! fileIn.eof()) { i++; if (i == ARRAY_SIZE) { cout << endl << endl << "Warning: Array Size Exceeded! Size = " << ARRAY_SIZE << "Processing will continue. Proceed with caution." << endl << endl; break; // get out of while loop } fileIn >> employeeId[i] >> lastName[i] >> firstName[i] >> rate[i]>> hours[i][0] >> hours[i][1] >> hours[i][2] >> hours[i][3]; }
  • 5. //Save the number of records loaded numberOfEmps = i; //close the file fileIn.close(); return; } //To be implemented by student void sumAndComputeAvgHours( ) { //outer for loop walks through number of employees for (int i = 0; i > searchName; //We only compare upto the length of the search string stringLength = strlen(searchName); // '0' not included in length //strncmp is case sensitive and strncasecmp ignores case for (int i = 0; i < numberOfEmps; i++) //walk through the array { if (strncasecmp(lastName[i],searchName, stringLength) == 0) { if (! headingsDisplayed) { listEmployeesHeadings(); //display the headings to cout headingsDisplayed = true; //only after 1st match } //display the record found recordFound = true; listEmployeesDetails(i); //don't get out of the for-loop, because there may be more matches } else if (strncasecmp(lastName[i],searchName, stringLength) > 0) //early exit { cout << endl << "Early exit..."; break; //get out of for-loop } } if (false == recordFound) {
  • 6. cout << "Employee Name not on file. "; } displayContinuePrompt(); return; } void sortByName( ) { //First for-loop walks through the entire array //The current entry is saved as the min value //Second for-loop looks for values lower than the //current value. If one is found, then all values are swapped. int minIndex; char minName[NAME_SIZE]; for (int i = 0; i < (numberOfEmps - 1); i++) { minIndex = i; strcpy(minName,lastName[i]); for (int i2 = i + 1; i2 < numberOfEmps; i2++) { if (strcasecmp(lastName[i2],minName) < 0) //if str1 < str2 { //a neg number returned minIndex = i2; strcpy(minName,lastName[i2]); } } swapValues(i, minIndex); } return; } void swapValues(int i, int minIndex) { //temp holding variables int holdInt; char holdName[NAME_SIZE];
  • 7. string holdStr; double holdDbl; holdInt = employeeId[i]; employeeId[i] = employeeId[minIndex]; employeeId[minIndex] = holdInt; //lastName is a cstring - use functions to manipulate strcpy(holdName,lastName[i]); strcpy(lastName[i],lastName[minIndex]); strcpy(lastName[minIndex],holdName); //firstName is a string object - use overloaded operators holdStr = firstName[i]; firstName[i] = firstName[minIndex]; firstName[minIndex] = holdStr; holdDbl = rate[i]; rate[i] = rate[minIndex]; rate[minIndex] = holdDbl; holdInt = hours[i][0]; hours[i][0] = hours[minIndex][0]; hours[minIndex][0] = holdInt; holdInt = hours[i][1]; hours[i][1] = hours[minIndex][1]; hours[minIndex][1] = holdInt; holdInt = hours[i][2]; hours[i][2] = hours[minIndex][2]; hours[minIndex][2] = holdInt; holdInt = hours[i][3]; hours[i][3] = hours[minIndex][3]; hours[minIndex][3] = holdInt; holdInt = sumHours[i]; sumHours[i] = sumHours[minIndex]; sumHours[minIndex] = holdInt; holdDbl = avgHours[i]; avgHours[i] = avgHours[minIndex]; avgHours[minIndex] = holdDbl; return; }
  • 8. void listEmployees( ) { listEmployeesHeadings(); for (int i = 0; i < numberOfEmps; i++) { listEmployeesDetails(i); } listEmployeesTotals( ); return; } void listEmployeesHeadings() { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << " P10 Your Name Here " << "Employee Last name F. " << "Rate Wk1 Wk2 Wk3 Wk4 Total Average "; return; } void listEmployeesDetails(int i) { cout << setw(6) << employeeId[i] << " "; cout.setf(ios::left); cout << setw(17) << lastName[i] << firstName[i][0] << "."; cout.unsetf(ios::left); cout << setw(9) << rate[i]; for (int i2 = 0; i2 < HOURS_SIZE; i2++) // i2 = 0,1,2,3 { cout << setw(6) << hours[i][i2]; }
  • 9. cout << setw(7) << sumHours[i] << setw(9) << avgHours[i] << endl; return; } void listEmployeesTotals( ) { cout << " Records Listed: " << numberOfEmps << endl << endl; return; } void displayContinuePrompt() { char prompt; cout << " Procedure completed. Press Enter to continue: "; cin.ignore(); prompt = cin.get(); //system("cls"); //clear screen - DOS return; } //End of program /* output: P10 Your Name Here Enter the letter of the desired menu option. Press the Enter key after entering the letter. A: List Payroll Information by Employee Name B: Search Payroll Information by Name X: Exit the Payroll Information Module Choice: A P10 Your Name Here
  • 10. Employee Last name F. Rate Wk1 Wk2 Wk3 Wk4 Total Average 1005 Bob B. 5.00 30 35 40 50 155 38.75 1009 Eldridge M. 6.50 20 20 30 40 110 27.50 1004 Flores J. 9.00 35 40 50 60 185 46.25 1007 Lee J. 8.00 35 40 50 60 185 46.25 1002 Long_Last_Name1 L. 8.00 50 50 10 40 150 37.50 1006 Sanchez M. 7.00 10 50 50 60 170 42.50 1018 Smit B. 9.50 50 10 25 30 115 28.75 1001 Smith J. 6.00 35 40 50 60 185 46.25 1010 Smitts S. 7.00 10 30 50 30 120 30.00 Records Listed: 9 Procedure completed. Press Enter to continue: P10 Your Name Here Enter the letter of the desired menu option. Press the Enter key after entering the letter. A: List Payroll Information by Employee Name B: Search Payroll Information by Name X: Exit the Payroll Information Module Choice: A P10 Your Name Here Employee Last name F. Rate Wk1 Wk2 Wk3 Wk4 Total Average 1005 Bob B. 5.00 30 35 40 50 155 38.75 1009 Eldridge M. 6.50 20 20 30 40 110 27.50 1004 Flores J. 9.00 35 40 50 60 185 46.25 1007 Lee J. 8.00 35 40 50 60 185 46.25 1002 Long_Last_Name1 L. 8.00 50 50 10 40 150 37.50 1006 Sanchez M. 7.00 10 50 50 60 170 42.50 1018 Smit B. 9.50 50 10 25 30 115 28.75 1001 Smith J. 6.00 35 40 50 60 185 46.25 1010 Smitts S. 7.00 10 30 50 30 120 30.00 Records Listed: 9 Procedure completed. Press Enter to continue: P10 Your Name Here
  • 11. Enter the letter of the desired menu option. Press the Enter key after entering the letter. A: List Payroll Information by Employee Name B: Search Payroll Information by Name X: Exit the Payroll Information Module Choice: B Enter the Employee Name to search for: S P10 Your Name Here Employee Last name F. Rate Wk1 Wk2 Wk3 Wk4 Total Average 1006 Sanchez M. 7.00 10 50 50 60 170 42.50 1018 Smit B. 9.50 50 10 25 30 115 28.75 1001 Smith J. 6.00 35 40 50 60 185 46.25 1010 Smitts S. 7.00 10 30 50 30 120 30.00 Procedure completed. Press Enter to continue: P10 Your Name Here Enter the letter of the desired menu option. Press the Enter key after entering the letter. A: List Payroll Information by Employee Name B: Search Payroll Information by Name X: Exit the Payroll Information Module Choice: B Enter the Employee Name to search for: La Early exit...Employee Name not on file. Procedure completed. Press Enter to continue: P10 Your Name Here Enter the letter of the desired menu option. Press the Enter key after entering the letter.
  • 12. A: List Payroll Information by Employee Name B: Search Payroll Information by Name X: Exit the Payroll Information Module Choice: X Now exiting Payroll Information...please wait. */