Write a C++ function that evaluates polynomials an a n x n + a n-1 x n-1 , … , a 2 x 2 ,a 1 x 1 , a 0
x 0 . It should take following inputs:
Value of x.
Highest power n.
Coefficients in descending order a n , a n-1 , … , a 2 , a 1 , a 0 (coefficients will ne
n+1)
For instance, if x=4 , n=3 & coefficients are [2,3,1,2], then output should be 182 which is
obtained by evaluating the polynomial 2 * 4 3 + 3 * 4 2 + 1 * 4 1 + 2 * 4 0
Function Prototype: double evaluatePolynomial();
without using array in c++
Write down the code to traverse the arrayuntill X located ?
Task 2: Find median in a 2D array
Write a function median_2d()that computes the median for a 2D numeric array (matrix). The inputs to the function are a pointer to the start of the array, and its dimensions (rows and cols). Your function should not modify the contents of the original matrix! The function prototype is given below.
float median_2d(float * ptr_array, int rows, int cols);
Domain knowledge:
The median is the middle number in a sorted, ascending or descending, list of numbers and can be more descriptive of that data set than the average.
If there is an odd amount of numbers, the median value is the number that is in the middle, with the same amount of numbers below and above.
If there is an even amount of numbers in the list, the middle pair must be determined, added together, and divided by two to find the median value.
Hint: In memory a 2D array is stored just like a 1D array.
Task 1: Convert a number string to number
Write a C function str_to_float() that takes a numeric string as input and converts it to a floating point number. The function should return the floating point number by reference. If the conversion is successful, the function should return 0, and -1 otherwise (e.g. the string does not contain a valid number). The prototype of the function is given below
int str_to_float(char * str, float * number);
Task 2: Test for Palindrome (recursive)
Write a function isPalindrom() that takes as input a C string and its size, and recursively tests whether it is a palindrome (a word or phrase which remains the same if reversed. e.g. radar, kayak etc). The function returns the Boolean data type which is either true or false. The required header “stdbool.h” has already been included in tasks.h.
The function has the following prototype:
bool isPalindrom(char * ptr_array, int size);
The recursive definition of a palindrome is:
The string is a palindrome if it has only one character or is an empty string.
The string is a palindrome if the first and the last characters are the same and the characters in between form a palindrome
Task 1: Reverse a character string.
Write a function called str_rev() that takes a pointer to a string as input and reverses the string in-place (this change should be reflected in the original string that was passed to the function, not to a copy of the string). No library functions for string reversal should be used. The function should also return a pointer to the reversed string.
Function prototype is given below:
char * str_rev(char * str);
Let A and B be the two matrix. The size of matrix A is m and size of matrix B. Then, find subtraction of C, is a A and B is defined as C(ij) = A(ij) - B(ij).
Bob employs a painting company that wants to use your services to help create an
invoice generating system. The painters submit an invoice weekly. They charge $30 per
hour worked. They also charge tax – 15%. Bob likes to see an invoice that displays all the
information – number of hours, the charge per hour, the total BEFORE tax and the total
AFTER tax. Since this is an invoice, we also need to display the name of the company
(Painting Xperts) at the top of the invoice. Display all of the information on the screen.
Using Pseudocode, develop an algorithm for this problem.
1. Create a class Company with Private members as staffName[20] (character array for name), stDesig[15] (character array for designation), staffSalary(integer type variable for salary) and selectData[2] (a static class member array of integer type, used for identifying staff with highest and lowest salary). A function to find and store numbers in selectData to identify the person with highest salary and one with lowest salary. Public members of class are: a function to initialize staffName, stDesig&staffSalary with values taken at runtime. A function result() to display all details of staff members with highest and lowest salary. Create a program for entering data for 5 staff members and display the details of staff having highest and lowest salary.
From a set of array elements, find the number of occurrences of each element present in the given array.