Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Write pseudocode instructions to carry out each of the following computational operations: a. Determine the area of a triangle given values for the
1. Write pseudocode instructions to carry out each of the following computational operations: a. Determine the area of a triangle given values for the base b and the height h. b. Compute the interest earned in 1 year given the starting account balance B and the annual interest rate I and assuming simple interest, that is, no compounding. Also determine the final balance at the end of the year. c. Determine the flying time between two cities given the mileage M between them and the average speed of the airplane 2. Write an algorithm that gets the price for item A plus the quantity purchased. The algorithm prints the total cost, including a 6% sales tax 3. Write an ifthen/else primitive to do each of the following operations: a. Compute and display the value x + y if the value of y is not 0. If y does have the value 0, then display the message 'Unable to perform the division. b. Compute the area and circumference of a circle given the radius r if the radius is greater than or equal to 1.0; otherwise, you should compute only the circumference. 4. Write an algorithm that uses a loop a. to input 10 pairs of numbers, where each pair represents the score of a football game with the Computer State University (CSU) score listed first, and b. for each pair of numbers, to determine whether CSU won or lost. After reading in these 10 pairs of values, print the won/lost/tie record of CSU. In addition, if this record is a perfect 10-0, then print the message "Congratulations on your undefeated season. Chapter 1 Challenge: One of the most important and widely used classes of algorithms in computer science is sorting, the process of putting a list of elements into a predefined order, usually numeric or alphabetic. There are many different sorting algorithms, and we will look at some of them in Chapter 3. One of the simplest sorting algorithms is called selection sort, and it can be implemented using the tools that you have learned in this chapter. It is also one of the easiest to understand as it mimics how we often sort collections of values when we must do so by hand. Assume that we are given a list named A, containing eight values that we want to sort into ascending order, from smallest to largest 23 A: Position 18 2 66 3 4 21 15 Part 2: Using Idle, create and edit the following program Programming Exercise 4 90 6 We first look for the largest value contained in positions 1-8 of list A. We can do this using something like the Find Largest algorithm that appears in Figure 2.14. In this case, the largest value is 90, and it appears in position 6. Because this is the largest value in list A, we swap it with the value in position 8 so that it is in its correct place at the back of the list. The list is now partially sorted from position 8 to position 8: A: 23 18 9 Position 1 2 32 66 3 21 5 21 5 4 6 32 We now search the array for the second largest value. Because we know that the largest value is contained in position 8, we need to search only positions 1-7 of list A to find the second largest value. In this case, the second largest value is 66, and it appears in position 3. We now swap the value in position 3 with the value in position 7 to get the second largest value into its correct location. This produces the following: A 23 18 32 Position 1 2 3 66 4 8 4 6 90 8 90 8 The list is now partially sorted from position 7 to position 8, with those two locations holding the two largest values. The next search goes from position 1 to position 6 of list A, this time trying to locate the third largest value, and we swap that value with the number in position 6. After repeating this process seven times, the list is completely sorted. (That is because if the last seven items are in their correct place, the item in position 1 must also be in its correct place.) Using the Find Largest algorithm shown in Figure 2.14 (which may have to be slightly modified) and the primitive pseudocode operations listed in Figure 2.9, implement the selection sort algorithm that we have just described. Assume that n, the size of the list, and the n-element list A are input to your algorithm. The output of your algorithm should be the sorted list. Write and test a Python script that, given a number of bytes, outputs the equivalent number of kilobytes, megabytes, gigabytes, and terabytes. Write and test a complementary script that, given a number of terabytes, outputs the equivalent number of GB, MB, KB, and bytes.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Lets start by addressing the pseudocode instructions for the given computational operations a Area of a Triangle Input base b height h Output area are...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started