The bisection method is an approximation method to find the roots of the given equation by repeatedly dividing the interval. This method will divide the interval until the resulting interval is found, which is extremely small. You are required to: i. write a pseudocode algorithm to determine the roots of a polynomial equation using Bisection Method. ii. develop a trace table to test the algorithm. iii.write C++ computer programs to determine the roots of an equation using Bisection Method.
Create an int array called gamesWon[] of capacity 100, that stores the number of games won in different chess tournaments in the last two years. and fill n elements of this array by prompting a player to enter data and ask to end the data by entering Q. You use a while loop to read the user entered data and assign to the elements of the array. So it is important to use a new variable and initialize it to 0 and use as the index of the array as well. The value of this variable when the sentinel value is read is the actual size of the array. Now you have a partially filled array. Print the array you created using the variable you used as index variable as the size of the array.
1. Finally swap the contents of gamesWon[0] and gamesWon[minIndex] and print the swapped values.
The bisection method is used to find the roots of a polynomial equation. It separates the interval and subdivides the interval in which the root of the equation lies. The principle behind this method is the intermediate theorem for continuous functions. It works by narrowing the gap between the positive and negative intervals until it closes in on the correct answer. This method narrows the gap by taking the average of the positive and negative intervals. For any continuous function f(x), i. Find TWO (2) points, say a and b such that a < b and f(a)* f(b) < 0 ii. Find the midpoint of a and b, say “t” iii. t is the root of the given function if f(t) = 0; else follow the next step iv. Divide the interval [a, b] v. If f(t)*f(b) <0, let a = t vi. Else if f(t) *f(a), let b = t vii. Repeat above three steps until f(t) = 0.
Write a program that initialzies an array with 10 random integers in the range from 1 to 99 inclusive and then prints the following two lines of output:
• Every element at even index all on the same line separated by a space.
• Only the first and the last element on the same line separated by a space.
Given a string, write a program to mirror the characters of the string in alphabetical order to create a secret message.
Note: Mirroring the characters in alphabetical order replacing the letters 'a' with 'z', 'b' with 'y', ... , 'z' with 'a'. You need to mirror both uppercase and lowercase characters. You can ignore mirroring for all characters that are not letters.
abcdefghijklmzyxwvutsrqpon nopqrstuvwxyzmlkjihgfedcbaInput
The input will be a string in the single line containing spaces and letters (both uppercase and lowercase).Output
The output should be a single line containing the secret message. All characters in the output should be in lower case.
Explanation
.
Sample Input 1
pythonoutput
kbgslminput2
python learningoutput2
kbgslm ovzimrmtCreate a Python dictionary that returns a list of values for each key. The key can be whatever type you want.
Design the dictionary so that it could be useful for something meaningful to you. Create at least three different items in it. Invent the dictionary yourself. Do not copy the design or items from some other source.
Next consider the invert_dict function from Section 11.5 of your textbook.
# From Section 11.5 of:
# Downey, A. (2015). Think Python: How to think like a computer scientist. Needham, Massachusetts: Green Tree Press.
def invert_dict(d):
inverse = dict()
for key in d:
val = d[key]
if val not in inverse:
inverse[val] = [key]
else:
inverse[val].append(key)
return inverse
The objective of this activity is to demonstrate the linear search algorithm for arrays.
You are going to implement this as a function with the following definition:
string linSearch(double arr[10], double search[7]);
This function will represent the core functionality of your program. This function will
take two arrays as arguments, both of specified size. The first array will be the array that
should be searched. It will contain double values. The second array will represent a list
of values to search for in the rst array.
Your function will return a string, comma-delimited, which represents the indices of the
searched for elements in the array. The rst index in the string should correspond to the
rst element in the search array and so on. If the array is not found, it should show NA.
For example:
Consider the case of arr={1.1,1.2.1.3,1.4,1.5,1.6,1.7,1.8.1.9,1.11}
and search={1.3,2.1,1.11}
Then the return value of linSearch should be: 2,NA,9
The search array will be of size 7
Polynomial
Given polynomial, write a program that prints polynomial in Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0 format.Input
The first line contains a single integer N.
Next N lines contain two integers Pi, Ci separated with space, where Pi denotes power and Ci denotes coefficient of Pi.Output
Print the polynomial in the format Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0, where Pi's are powers in decreasing order, Ci is coefficient, and C0 is constant. There will be space before and after the plus or minus sign.
If the coefficient is zero, then don't print the term.
If the term with the highest degree is negative, the term should represent -Cix^Pi.
For the term where power is 1, represent it as C1x instead of C1x^1.
If the polynomial degree is zero and the constant term is also zero, then print 0 to represent the polynomial.
For term Cix^Pi, if the coefficient of the term Ci is 1, print x^Pi instead of 1x^Pi.
For this activity, you are required to provide les called sel.cpp as well as a makele to
compile and run it. In your le, sel.cpp, should have a skeleton of a main program as per
normal which you will then ll it in as per the following.
The objective of this activity is to demonstrate the selection sort algorithm for arrays.
Your program will need to read in from a le called list.txt. On each line, will be a
comma-delimited list of integer values. Each list will be 7 elements long. Your objective
is to sort each of these lists using the selection sort algorithm.
Each line should be sorted, and then displayed in sorted (ascending order with the small-
est element at the start of the string) one after the other. Each will be on a new line.
As a hint, implementing a function to do the selection sort itself will make the overall
program easier to implement.
For example:
Given a list: 6.4,3.25,7.5,2.5,1.1,11.6,0.5
The outcome of the sorting should be: 0.5,1.1,2.5,3.25,6.4,7.5,11.6
At the start of your program, you are going to need to declare a 4 by 4 element two
dimensional array. That is, 4 dimensions by 4 dimensions for a total of 16 elements in the
array. Your program needs to read in from a file, values.txt, where each line of the le
will have a comma delimited list of integer values with 4 lines in total.
Each value of each line should be placed into the array, with the line corresponding
to the row index. The first value in the line goes into the first, index 0, column of the
array. So the array is filled row by row, from left to right.
Once furnished, you need to compute the following:
- Row Totals: The sum of all elements per row
- Column Totals: The sum of all elements per column
- Array Average: The average of all elements in the array
The output format should be displayed as follows (with example values):
Row Total 1: 4
Row Total 2: 4
Row Total 3: 4
Row Total 4: 4
Col Total 1: 4
Col Total 2: 4
Col Total 3: 4
Col Total 4: 4
Array Average: 1