# C modify the daily life magazine program so that is

• Homework Help
• 57
• 91% (47) 43 out of 47 people found this document helpful

This preview shows page 34 - 41 out of 57 pages.

c. Modify the Daily Life Magazine program so that is produces a count of readers by annual income groups as follows: under \$30,000, \$30,000–\$49,999, 50,000–\$69,999, and \$70,000 and up. Answer: A sample solution follows Flowchart: 34
Programming Logic and Design, 7e Solutions 6- Pseudocode: start Declarations num age num income num x string gender string maritalStatus num SIZE = 4 num incomeCnt[SIZE] = 0 num INCOME_RANGE[SIZE] = 0, 30000, 50000, 70000 35
Programming Logic and Design, 7e Solutions 6- string INCOME_GROUPS[SIZE] = “under \$30,000”, “\$30,000-\$49,999”, “\$50,000- \$69,999”, “\$70,000 and up” getReady() while not eof detailLoop() endwhile finishUp() stop getReady() output “Enter the age, gender, marital status, and income of a reader” input age, gender, maritalStatus, income return detailLoop() x = SIZE – 1 while age < INCOME_RANGE[x] x = x – 1 endwhile incomeCnt[x] = incomeCnt[x] + 1 output “Enter the age, gender, marital status, and income of a reader” input age, gender, maritalStatus, income return finishUp() x = 0 while x < SIZE output INCOME_GROUPS[x], incomeCnt[x] x = x + 1 endwhile return 11. Glen Ross Vacation Property Sales employs seven salespeople, as shown in the accompanying table. ID Number Salesperson Name 103 Darwin 104 Kratz 201 Shulstad 319 Fortune 367 Wickert 388 Miller 435 Vick When a salesperson makes a sale, a record is created including the date, time, and dollar amount of the sale. The time is expressed in hours and minutes, based on a 24- hour clock. The sale amount is expressed in whole dollars. Salespeople earn a commission that differs for each sale, based on the rate schedule in the accompanying table. 36
Programming Logic and Design, 7e Solutions 6- Sale Amount (\$) Commission Rate (%) 0 – 50,999 4 51,000 - 125,999 5 126,000 - 200,999 6 201,000 and up 7 Design an application that produces each of the following: a. A list of each salesperson number, name, total sales, and total commissions 37
Programming Logic and Design, 7e Solutions 6- Pseudocode: 38
Programming Logic and Design, 7e Solutions 6- start Declarations num date num hours num minutes num saleAmt num idNum num person num x string date num SSIZE = 4 num PSIZE = 7 num totalSales[PSIZE] = 0 num totalComm[PSIZE] = 0 num ID_NUM[PSIZE] = 103, 104, 201, 319, 367, 388, 435 string NAME[PSIZE] = “Darwin”, “Kratz”, “Shulstad”, “Fortune”, “Wickert”, “Miller”, “Vick” num SALE_AMT[SSIZE] = 0, 51000, 126000, 201000 num COMM_RATE[SSIZE] = 0.04, 0.05, 0.06, 0.07 getReady() while not eof detailLoop() endwhile finishUp() stop getReady() output “Enter the salesperson ID number” input idNum return detailLoop() person = 0 while person < PSIZE AND idNum not equal to ID_NUM[person] person = person + 1 endwhile if person = PSIZE then output “An invalid number has been entered, please try again” else input date, hours, minutes, saleAmt totalSales[person] = totalSales[person] + saleAmt x = SSIZE – 1 while saleAmt < SALE_AMT[x] x = x – 1 endwhile totalComm[person] = totalComm[person] + (COMM_RATE[x] * saleAmt) endif output “Enter the salesperson ID number” input idNum return finishUp() x = 0 while x < PSIZE output ID_NUM[x], NAME[x], totalSales[x], totalComm[x] 39
Programming Logic and Design, 7e