Algorithm Solutions for Introduction to Computer Science Assignment
VerifiedAdded on 2023/04/24
|11
|974
|222
Homework Assignment
AI Summary
This assignment solution provides a comprehensive overview of algorithm design and implementation within the context of computer science. It presents three distinct algorithmic solutions, each addressing a specific problem. The first algorithm focuses on calculating commission based on retail costs and transaction codes, using both pseudocode and a desk check to validate the logic. The second algorithm tackles the assignment of grade letters based on exam marks, demonstrating the use of nested IF statements and CASE statements. It also includes a desk check to verify the correctness of the grade assignment. The third algorithm addresses income tax calculation, taking into account income levels and applying different tax rates accordingly, complete with a desk check. The solution also includes a bibliography of relevant academic resources.

Running head: INTRODUCTION TO COMPUTER SCIENCE
Introduction to Computer Science
Name of the Student
Name of the University
Author’s Note
Introduction to Computer Science
Name of the Student
Name of the University
Author’s Note
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

1
INTRODUCTION TO COMPUTER SCIENCE
Solution Algorithm 1:
Defining Problem:
Input Processing Output
Recording transaction
Retail_cost
Transaction_code
Employee_No.
Reading transaction
Calculating commission
Printing details of
transaction
Retail cost
Commission
Employee No.
Pseudo code algorithm:
If the case of solution is not A, B or C then a message is printed and commission set
as 0.
Process transaction record
Read retail_cost, transaction_code and employee_no.
CASE Transaction_Code
A: Commission = retail_cost x 0.06
B: Commission = retail_cost x 0.08
C: Commission = retail_cost x 0.1
Other: Displaying ‘Invalid transaction’, Transaction_code commission = 0
END CASE
Print ‘Retail Price’, retail_cost, ‘Commission’, commission, ‘Employee No.’, Employee_No.
END
INTRODUCTION TO COMPUTER SCIENCE
Solution Algorithm 1:
Defining Problem:
Input Processing Output
Recording transaction
Retail_cost
Transaction_code
Employee_No.
Reading transaction
Calculating commission
Printing details of
transaction
Retail cost
Commission
Employee No.
Pseudo code algorithm:
If the case of solution is not A, B or C then a message is printed and commission set
as 0.
Process transaction record
Read retail_cost, transaction_code and employee_no.
CASE Transaction_Code
A: Commission = retail_cost x 0.06
B: Commission = retail_cost x 0.08
C: Commission = retail_cost x 0.1
Other: Displaying ‘Invalid transaction’, Transaction_code commission = 0
END CASE
Print ‘Retail Price’, retail_cost, ‘Commission’, commission, ‘Employee No.’, Employee_No.
END

2
INTRODUCTION TO COMPUTER SCIENCE
Desk check of the algorithm:
1. INPUT:
1st Set of Data 2nd Set of Data
Retail_cost 50$ ABC
Transaction_code A C
Employee_No. 12345 34567
2. Result Expected
1st Set of Data 2nd Set of Data
Commission 3$ ERROR
3. Check Table
Statement No. Retail_Price Transaction_Cod
e
Emloyee_No. Commission
1st Pass
1. 50$ A 12345
2. 3$
3. Print
2nd Pass
1. ABC C 34567
2. ERROR
3. Print
INTRODUCTION TO COMPUTER SCIENCE
Desk check of the algorithm:
1. INPUT:
1st Set of Data 2nd Set of Data
Retail_cost 50$ ABC
Transaction_code A C
Employee_No. 12345 34567
2. Result Expected
1st Set of Data 2nd Set of Data
Commission 3$ ERROR
3. Check Table
Statement No. Retail_Price Transaction_Cod
e
Emloyee_No. Commission
1st Pass
1. 50$ A 12345
2. 3$
3. Print
2nd Pass
1. ABC C 34567
2. ERROR
3. Print
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

3
INTRODUCTION TO COMPUTER SCIENCE
Solution Algorithm 2:
Defining Problem:
Input Processing Output
serial_no. Analyse student record serial_no.
exam_point Computing grade_letter exam_point
Print detailed result grade_letter
Pseudo code algorithm:
Using nested IF framework and CASE statement
Process_student_grade_letter
Read_student_serial_no., student_exam_marks
CASE of grade_letter
HD: exam_marks>84
D: exam_marks>74
C: exam_marks>64
P: exam_marks>59
F: exam_marks<50
ENDCASE
Print student_serial_no., exam_marks, grade_letter
INTRODUCTION TO COMPUTER SCIENCE
Solution Algorithm 2:
Defining Problem:
Input Processing Output
serial_no. Analyse student record serial_no.
exam_point Computing grade_letter exam_point
Print detailed result grade_letter
Pseudo code algorithm:
Using nested IF framework and CASE statement
Process_student_grade_letter
Read_student_serial_no., student_exam_marks
CASE of grade_letter
HD: exam_marks>84
D: exam_marks>74
C: exam_marks>64
P: exam_marks>59
F: exam_marks<50
ENDCASE
Print student_serial_no., exam_marks, grade_letter
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

4
INTRODUCTION TO COMPUTER SCIENCE
End
Using linear nested IF statement:
Process_student_grade_letter
Read_student_serial_no., student_exam_marks
IF exam_marks > ’84’ THEN
exam_marks = HD
ELSE
IF exam_marks > ’74’; THEN
exam_marks = D
ELSE
IF exam_marks > ‘64’ THEN
exam_marks = C
ELSE
IF exam_marks > ‘59’ THEN
exam_marks = P
ELSE
IF exam_marks < ‘50’ THEN
exam_marks = F
ENDIF
ENDIF
INTRODUCTION TO COMPUTER SCIENCE
End
Using linear nested IF statement:
Process_student_grade_letter
Read_student_serial_no., student_exam_marks
IF exam_marks > ’84’ THEN
exam_marks = HD
ELSE
IF exam_marks > ’74’; THEN
exam_marks = D
ELSE
IF exam_marks > ‘64’ THEN
exam_marks = C
ELSE
IF exam_marks > ‘59’ THEN
exam_marks = P
ELSE
IF exam_marks < ‘50’ THEN
exam_marks = F
ENDIF
ENDIF

5
INTRODUCTION TO COMPUTER SCIENCE
ENDIF
ENDIF
ENDIF
exam_marks = grade_letter
Print student_serial_no., exam_marks, grade_letter
End
Desk check of the algorithm:
1. INPUT:
1st set of data 2nd Set of data
Exam_marks 77 AD
Grade_letter D HD
2. Result Expected
1st set of data 2nd Set of data
Exam_marks 77 Invalid
Grade_letter D HD
3. Check Table
Statement exam_marks Grade_ letter Execution of CASE statement
1st Pass
INTRODUCTION TO COMPUTER SCIENCE
ENDIF
ENDIF
ENDIF
exam_marks = grade_letter
Print student_serial_no., exam_marks, grade_letter
End
Desk check of the algorithm:
1. INPUT:
1st set of data 2nd Set of data
Exam_marks 77 AD
Grade_letter D HD
2. Result Expected
1st set of data 2nd Set of data
Exam_marks 77 Invalid
Grade_letter D HD
3. Check Table
Statement exam_marks Grade_ letter Execution of CASE statement
1st Pass
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

6
INTRODUCTION TO COMPUTER SCIENCE
Read 77
CASE CASE D
Grade_letter D
Print yes yes
2nd Pass
Read AD
CASE
Grade_letter
Print yes yes
Solution Algorithm 3:
Defining Problem:
Two integer items are taken into a loop using an array for calculating the income from
the user and computing the income tax and displaying the income tax. The chargeable
income, income tax and gross tax payable is analysed for checking the validation and
optimizing the codes.
Input Processing Output
Integer 1
Integer 2
Sum
Difference
Display
INTRODUCTION TO COMPUTER SCIENCE
Read 77
CASE CASE D
Grade_letter D
Print yes yes
2nd Pass
Read AD
CASE
Grade_letter
Print yes yes
Solution Algorithm 3:
Defining Problem:
Two integer items are taken into a loop using an array for calculating the income from
the user and computing the income tax and displaying the income tax. The chargeable
income, income tax and gross tax payable is analysed for checking the validation and
optimizing the codes.
Input Processing Output
Integer 1
Integer 2
Sum
Difference
Display
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

7
INTRODUCTION TO COMPUTER SCIENCE
Product
Quotient
Pseudo code algorithm:
Calculating_payable_tax
Prompt for income
Get income
If (income >=0 & income <=20,000) then
Print Tax = 0
Else if (income >= 20,000 & income <=30,000)
Then
Print tax = 0 + (income -20,000) *2%
Else if (income >= 30,000 & income <=40,000)
Then
Print tax = 200+ (income – 30,000) *3.5%
Else if (income >= 40,000 & income <=80,000)
Then
Print tax = 550+ (income – 40,000) * 7%
Else if (income >= 80,000 & income <=120,000)
Then
Print tax = 3,350+ (income – 80,000) *11.5%
INTRODUCTION TO COMPUTER SCIENCE
Product
Quotient
Pseudo code algorithm:
Calculating_payable_tax
Prompt for income
Get income
If (income >=0 & income <=20,000) then
Print Tax = 0
Else if (income >= 20,000 & income <=30,000)
Then
Print tax = 0 + (income -20,000) *2%
Else if (income >= 30,000 & income <=40,000)
Then
Print tax = 200+ (income – 30,000) *3.5%
Else if (income >= 40,000 & income <=80,000)
Then
Print tax = 550+ (income – 40,000) * 7%
Else if (income >= 80,000 & income <=120,000)
Then
Print tax = 3,350+ (income – 80,000) *11.5%

8
INTRODUCTION TO COMPUTER SCIENCE
Else if (income >= 120,000 & income <=160,000)
Then
Print tax = 7,950+ (income – 120,000) *15%
Else if (income >= 160,000 & income <=200,000)
Then
Print tax = 13,950+ (income – 160,000) *17%
Else if (income >= 200,000 & income <=320,000)
Then
Print tax = 20,750+ (income – 200,000) *18%
Else if (income >= 320,000)
Then
Print tax = 42,350+ (income – 320,000) *20%
Desk check of the algorithm:
1. INPUT:
1st Set of Data 2nd Set of Data
income 320,500 AB
income 160,500 0
2. Result Expected:
1st Set of Data 2nd Set of Data
Tax 50,920 Error
Tax 16406.5 Error
INTRODUCTION TO COMPUTER SCIENCE
Else if (income >= 120,000 & income <=160,000)
Then
Print tax = 7,950+ (income – 120,000) *15%
Else if (income >= 160,000 & income <=200,000)
Then
Print tax = 13,950+ (income – 160,000) *17%
Else if (income >= 200,000 & income <=320,000)
Then
Print tax = 20,750+ (income – 200,000) *18%
Else if (income >= 320,000)
Then
Print tax = 42,350+ (income – 320,000) *20%
Desk check of the algorithm:
1. INPUT:
1st Set of Data 2nd Set of Data
income 320,500 AB
income 160,500 0
2. Result Expected:
1st Set of Data 2nd Set of Data
Tax 50,920 Error
Tax 16406.5 Error
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

9
INTRODUCTION TO COMPUTER SCIENCE
3. Check Table:
Statement Income Tax
1st Pass
1, 2 Get /Prompt 320500
3 Check
4 Calculate
5 Print 50,920
2nd Pass
1, 2 Get /Prompt AB
3 Check
4 Calculate
5 Print Error
INTRODUCTION TO COMPUTER SCIENCE
3. Check Table:
Statement Income Tax
1st Pass
1, 2 Get /Prompt 320500
3 Check
4 Calculate
5 Print 50,920
2nd Pass
1, 2 Get /Prompt AB
3 Check
4 Calculate
5 Print Error
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

10
INTRODUCTION TO COMPUTER SCIENCE
Bibliography
Adulyasak, Y., Cordeau, J. F., & Jans, R. (2015). The production routing problem: A review
of formulations and solution algorithms. Computers & Operations Research, 55, 141-
152.
Gunawan, A., Lau, H. C., & Vansteenwegen, P. (2016). Orienteering problem: A survey of
recent variants, solution approaches and applications. European Journal of
Operational Research, 255(2), 315-332.
INTRODUCTION TO COMPUTER SCIENCE
Bibliography
Adulyasak, Y., Cordeau, J. F., & Jans, R. (2015). The production routing problem: A review
of formulations and solution algorithms. Computers & Operations Research, 55, 141-
152.
Gunawan, A., Lau, H. C., & Vansteenwegen, P. (2016). Orienteering problem: A survey of
recent variants, solution approaches and applications. European Journal of
Operational Research, 255(2), 315-332.
1 out of 11
Related Documents

Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.