Introduction to Computer Science - Programming Assignment Analysis

Verified

Added on  2023/06/10

|5
|531
|69
Homework Assignment
AI Summary
This document presents a solved programming assignment for an introductory computer science course. The assignment involves three distinct programs. The first program calculates commission based on retail price and transaction codes (A, B, C), validating inputs and applying different commission rates. The second program calculates student grades based on entered marks, incorporating input validation and if-else statements for grading logic. The third program calculates payable tax based on income, using a chart-based approach and input validation, with a loop to allow multiple calculations. Each program includes input validation, conditional statements, and output displays, demonstrating core programming concepts. The assignment also includes the problem description and pseudo code for the first question.
tabler-icon-diamond-filled.svg

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
Running head: PROGRAMMING
Programming
Name of the student:
Name of the University:
Author note:
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
1
PROGRAMMING
Program 1
The program first asks the user to enter the retail price and checks if a valid price has
been entered. This is achieved through thorough checking of each entry inside of a while loop.
The user then enters the transaction code. The transaction code is converted into the respective
uppercase character. This entry is then checked against the valid codes and if an invalid code has
been entered, the user is asked to re-enter through an error message. This continues unless the
user enters a valid code and the loop counter exits. Here the code is checked using individual
conditional statements and commission calculations are made accordingly.
Output:
Document Page
2
PROGRAMMING
Program 2
The user’s is by default set to “yes” in order to feed the first iteration of the loop. The
user is then asked to enter the student id and further is required to enter the marks. Here it is
checked whether the marks entered is valid or no and accordingly the program proceeds. Finally
the marks entered is checked for their relating range as per the program requirements and the
grade is calculated accordingly. In order to achieve code optimization, the if-else statements have
been carefully designed with lesser checks to commit to. The conditions are only set to check if
the marks entered is greater than certain milestones. Henceforth, having done with all the above
tasks, the program prints the Grade associated with the marks. The user can then enter his or her
Document Page
3
PROGRAMMING
choice to continue. The while loop condition is further checked if the choice entered is ‘yes’
ignorant of the case. If the user enters ‘yes’ or ‘Yes’ the program is run again otherwise the
program exits. Everytime that the loop iterates for a new entry, the marks is intentionally set to -
1 in order to enter the marks validation loop and then the user is allowed to update it.
Output:
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
4
PROGRAMMING
Program 3
In this program, the user is first required to enter a positive amount as the income.
Otherwise the opening while loop will keep iterating unless a valid amount is entered. Once the
valid amount is entered, the program proceeds into the algorithmic calculations to sort out the
payable tax according to the chart. The program subsequently checks for the category under
which the income lands and calculates the tax. Each if statement checks if the income is greater
than a specific amount and also greater than its next milestone. If so, then respective adjustments
are made to the tax value. The value is updated at each subsequent level. Finally on displaying
the tax value the user is asked to input a new income value. If the user enters a -1, the program
exists otherwise the process repeats.
Output:
chevron_up_icon
1 out of 5
circle_padding
hide_on_mobile
zoom_out_icon
logo.png

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]