Programming Exercises for ITCS111
Programming Exercises for ITCS111
The program extracts the birth year from the first two digits of the CPR number. It assumes that all persons were born between the years 1910 and 1999. Consequently, the extracted two-digit prefix (e.g., '74' in CPR number '740707573') is prefixed with '19' to obtain the complete birth year ('1974').
The program first reads two currency codes, an exchange rate from the first currency to the second, and the amount of money to be converted. It then calculates the equivalent value in both currencies using the formulas: First Currency Amount = Currency Amount × Exchange Rate and Second Currency Amount = Currency Amount / Exchange Rate. The result is formatted to four decimal places .
Ticket sales and total revenue are computed by multiplying the number of tickets sold at each price category by the price of each ticket. For example, a line indicating '250 5750' means 5750 tickets were sold at $250 each. The program aggregates these computations for all ticket types (Box, Sideline, Premium, general Admission) to determine the total sales revenue, outputted with two decimal places .
To calculate how long it takes for a cyclist to stop, the program needs the cyclist's initial speed (Vinitial), the final speed (Vfinal), and the duration of coasting in minutes. The rate of acceleration is calculated using the formula: acceleration = (Vfinal - Vinitial) / duration. The stopping time is then calculated with: time = Vinitial / acceleration. This is reported in a formatted output as shown in the document .
The net pay on a monthly paycheck is calculated by deducting specific amounts from the gross salary. The deductions applied include 2.75% of the gross amount for Medicare/Medicaid Tax, 6% for Pension Plan, and a fixed BD. 75 for Health Insurance. The program subtracts these deductions from the gross salary to determine and print the net pay .
The area of a triangle is calculated programmatically by taking half the product of its base and height using the formula Area = 1/2 × base × height. Relevant input values required are the base and height of the triangle. This program reads these values to compute the area .
Salespeople's commission-based earnings are calculated by providing a fixed weekly base of BD. 75/600 plus 9% of their gross sales for that week. For example, if a salesperson sells BD. 1890 in chemicals, they receive the base amount plus 9% of 1890, totaling BD. 245/700. The program inputs the gross sales from each salesperson to compute their weekly earnings .
The components for calculating a student's total points include quizzes, the midterm exam, and the final exam. Quizzes are weighted at 25%, the midterm at 35%, and the final exam at 40%. The program calculates the total points by combining these weighted scores out of 100 .
The duration of a degree program in years is calculated by dividing the total program credits by the expected credits completed yearly. The expected graduation year is calculated by adding the calculated duration to the base year 2015. This program thus outputs the student's name, degree duration in years, and expected graduation year .
The program calculates average salaries by summing three input salaries and dividing by three. The output is formatted uniquely with three decimal places, enhancing precision as shown in the sample input/output (e.g., Average ...........779.157).