OBJECTIVES In this lab assignment, students will learn: How to declare one-dimensional and two-dimensional Arrays - How
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
OBJECTIVES In this lab assignment, students will learn: How to declare one-dimensional and two-dimensional Arrays - How
Here is example template:
c++ Question Help
OBJECTIVES In this lab assignment, students will learn: How to declare one-dimensional and two-dimensional Arrays - How to save data in one-dimensional and two-dimensional Arrays How to use a for loop to iterate one-dimensional and two-dimensional Arrays How to access and retrieve data from one-dimensional and two-dimensional Arrays How to pass one-dimensional and two-dimensional Arrays to a function How to use parallel arrays - How to declare and use the c-string COURSE PREPARATION Read the following documents: • Chapter 8 of the lecture slides and textbook. CSC134-Coding Guidelines.doc posted in Course Resources -> Tutorials and Guidelines to Create and Submit C++ Programs. GRADING RUBRIC Indent code and insert comments to document your program. [10 pts] Program must be implemented and run as instructed. Program that does not compile and run will not receive any credit. [Programming Skills, 80 pts] Submit the C++ programs to Blackboard correctly. [10 pts] INSTRUCTIONS Develop a C++ program “YourLastname-Lab6" which reads data from the attached text file "job-salaries.txt", then performs the following data analytic tasks:
● ● • • ● Administrative Assistant 29000-56000 Software Engineer 61000-126000 Project Manager, (Unspecified Type / General) 49000-112000 Operations Manager 42000-103000 Office Manager 34000-69000 Financial Analyst 46000-81000 Software Developer 50000-104000 Customer Service Representative (CSR) 28000-54000 Senior Software Engineer 85000-156000 Executive Assistant 39000-79000 Do not use any non-constant global variables. All arrays should be parallel arrays, the specific job and its salary data should use the same index in all parallel arrays. Read all job titles and salary ranges from the data file and store the jobs and salary ranges into two arrays, the maximum number of jobs that can be processed by this program is 20. O Store job titles in a one-dimensional string type array jobs [20]. o Store low salary and high salary in a two-dimensional double type array salary Ranges [20][2]. Sample output Calculate the average salary for each job using averageSalary = (lowSalary + highSalary)/2.0, store the average salary in another one-dimensional array avgSalary[20]. Display the job title, low salary, high salary and average salary on the screen. Identify and display the lowest and highest average salary from the array avgSalary[ ]. Sort all jobs by average salary in ascending order and then display the sorted jobs with corresponding low salary, high salary and average salary. o You are required to define a function to perform the job sorting. This should be a void function. o o It requests all three arrays and number of jobs as parameters. o The code template below used selection sorting algorithm.
Administrative Assistant 29000 - 56000 Software Engineer 61000 - 126000 Project Manager, (Unspecified Type / General) 49000 - 112000 Operations Manager 42000 - 103000 Office Manager 34000 - 69000 Financial Analyst 46000 - 81000 Software Developer 50000 104000 Customer Service Representative (CSR) 28000 - 54000 Senior Software Engineer 85000 - 156000 Executive Assistant 39000 - 79000
Jab Minnsoft Visual Studio Debug Console Administrative Assistant Software Engineer Project Manager. Unspecified Type General) Operations Manager Office Manager Financial Analyst Software Developer Customer Service Representative (CSR) Senior Software Engineer Executive Assistant This job has the highest average salary: Senior Software Engineer This job has the lowest average salary: Customer Service Representative (CSR) 41000 The jobs are sorted by average salary in aosending order: Job Oustomer Service Representative (CSR) Administrative Assistant Office Manager Executive Assistant Financial Analyst Operations Manager Software Developer Project Manager, Unspecified Type / General) Software Engineer Senior Software Engineer This is the code template------ +includeciostream> #include<stream> Finclude<string> #include<iomanip> using namespace std; // declare function prototype Write your code hare .... int main() { // declare variables Write your code here.... Lov Salary High Salary 56000 126000 112000 while (infile) { 120500 // open the file and read jubs data. -------- write your code here ------- 29000 61000 49000 42000 34000 46000 50000 28000 85000 39000 Low Salary 20000 29000 34000 39000 46000 42000 50000 49000 61000 85000 103000 103000 69000 81000 104000 54000 155000 79000 High Salary 54000 56000 69000 79000 81000 103000 104000 112000 126000 156000 Average Salary 42500 93500 80500 72500 51500 63500 77030 41000 120500 59000 Average Salary 41000 42500 51500 59000 men 63500 72500 77000 80500 93500 120500 // read job title and store in jobs[] array getline (infile, jobs[index]); // read the salary ranga line and store in a string variable rangeline. ------- write your code here ------ // find the index of "-" from the salary range line ------ write your code here ----- if (rangelino - "") { } // retrieve the low salary lowsalary // retrieve the high salary ‒‒‒‒‒‒ write your code here----- stod (rengeLine.substr(0, pcs)); // store the low and high salary in the salaryaanges array salarytangas[index][0] = lousalary: ------ write your code here --- // calculate averageSalary ----- write your code here ----- // store averageSalary in the avgSalary array avgsalary(index] = averageSalary: index++; } numJobs index - 1: // display the hoader. Write your code here - // display job title, low for (int i = 0; i < nữobs, high salary and average salary ( ------ write your code here ----- i++) } cout << andl; // szauna the first average salary in the highest and lowest average salary highestAvgSalary - avgSalary [0]; ------ write your code here -----
for (------ write your code here ----} ( // if any average salary is higher the current highest average salary, assign it to the highest average salary // store the index of the highest and lowest average salary if (avgalary> highes:Avysalary) { រ highestAvgsalary - avgsalary; highton = 1; write your code here // display the jobs which has the highest average salary ------ write your code here ----- // call the function to sort jobs ------ write your code here ----- // display the worted jobs and their corresponding low, high and average salary ------ write your code here ----- return 0; } // define the function sortJobs void scrtaobs (string jobs[], double salaryRanges [] [2], double avgSalary[], int nurJobs) { int index: int smallest Index; int location; double sempAvgalary; string empJob; double TempRangeLow: double tempRangeHigh: for (index = 0; index < numitaba 1: index++) ( //step a smallestIndex - index: for (location - index + 1; location < numJobs: location++) if (avgsalary(location) < avgšalary(smallest Index)) smallest Index = location; //Step b // sert avgalary array tempAvqSalary - avqsalary [smallest Index). avgsalary(smallestIndex]-avgsalary[index]; avgsalary[index] = tempAvgalary; // sert jobs array ------ write your code here ----- // sert the salaryRanges array ------ write your code here ----- • Compress the whole project folder into a zip file "YourLastname-Lab6.zip" and submit it through Lab 6 link at BB for credits.