Create a Program
You will create a program that displays amount of a cable bill. The Amount is based on the type of customer, as shown in the figure. For a residential customer, the user will need to enter the number of premium channels only. For a business customer, the user will need to enter the number of connections and the number of premium channels. Also enter appropraite comments and any additional instructions in your c++ program. Test the program appropriately before submission.
You are living off-campus and drive your car to ODU campus everyday of a week. You wonder how many mileages you travel in a week (just to campus and back home) and how much you need to pay for the gas. You log your travel mileage every day during a week (just to campus and back home). This information has been saved in an input file called “mileage.txt”.
Design an algorithm and write a C++ program to do the following:
1. Trace and comment each and every line of the C++ program below:
#include <iostream>
using namespace std;
int binarySearch(int arr[], int left, int right, int num)
{
if (right >= left) {
int mid = left + (right - left) / 2;
if (arr[mid] == num)
return mid;
if (arr[mid] > num)
return binarySearch(arr, left, mid - 1, num);
return binarySearch(arr, mid + 1, right, num);
}
return -1;
}
int main(void)
{
int arr[] = { 2, 3, 4, 8, 10, 40 };
int check = 40;
int n = sizeof(arr) / sizeof(arr[0]);
int result = binarySearch(arr, 0, n - 1, check);
(result == -1)
? cout << "Element is not present in array"
: cout << "Element is present at index " << result;
return 0;
}
3. Write a C++ recursive function that takes a string and reverse the string.
4. Write a C++ recursive function that takes an array of words and returns an array
that contains all the words capitalized.
5. Write a linear search C++ program that searches for a number in a two
dimensional array.
6. What is each on the following functions going to achieve:
a)
int fun(int x, int y)
{
if (x == 0)
return y;
else
return fun(x - 1, x + y);
}
b)
int fun(int a, int t)
{
if (a == 0)
return t;
t = (t * 10) + (a % 10);
return fun(a / 10, t);
}
Consider the process of taking the average of a list of N (real) numbers. The list will be contained in an array, X, of real numbers. The numbers will be referenced as X[0], X[1], X[2], ..., X[N-1].
a) Prove that the process of taking the average of a list of N real numbers is recursive.
Hint: Use function polymorphism.
b) As a result of a) above or otherwise, write the corresponding polymorphic and
recursive C++ function that computes the average of a list of N numbers.
Consider a list of (real) numbers, X, of length N. Squaring each number in the list is a recursive process. Prove this by writing a polymorphic and recursive C++ function
template <class Type>
Type * square (Type * X, long int N)
{
// C++ code
}
which recursively squares each element in X and returns that list (i.e. X with
elements squared).
A company has both part time and full time employees. The details of full-time employees include name department contacts basic pay and part time employees Inherit some properties of full time employees calculate their basic pay and basic details
Write a c++ program that
Has a class named Queue for storing integers. In a queue, the elements are retrieved in a FIFO fashion.The class contains:
■ An int[] data fieldnamed elements that stores the int values in the queue.
■ A data field named size that stores the number of elements inthe queue.
■ A constructor that createsa Queue object with defaultcapacity 8 .
■ The method enqueue(int v) that adds v into the queue.
■ The method dequeue() that removes and returns theelement from the queue.
■ The method empty() that returns true if the queue isempty.
■ The method getSize() that returns the size of the queue.
Implement the class with the initial arraysize set to 8. The array size will be doubled once the number of the elementsexceeds the size. After an element is removed from the beginning of thearray,you need to shift all elements in the array one position the
left. Writea test program that adds 20 numbers from 1 to 20 into the queue and removesthese numbers and displays them.
Write a function that takes 4 coordinates of the Rectangle and a point P as a parameter. Your function should be able to tell whether P lies inside the Rectangle, On the Rectangle, or Outside rectangle. Sample Input:
P1 0 0
P2 2 0
P3 2 2
P4 0 2
P 1 1
Output: P lies inside Square
10.Write a function which takes as input 4 points and tell whether these points
are the coordinates of Square, Rhombus, Rectangle, Parallelogram or
Quadrilateral. NOTE: Make separate functions for each case checking whether
its square / rhombus / rectangle / parallelogram. i-e (isSquare, isRhombus,
isRectangle, isParallelogram)
Sample Input:
P1 0 0
P2 1 0
P3 1 1
P4 0 1
Output: It’s a square