Create a dynamic array of user defined size. Now move the largest number in the array to first position. Print the array after moving the number. All array operations should be done using pointers.
Write a program to create a dynamic array of user defined size. Array should be character type. Write a function RemoveVowels() that should remove all the vowels in the array. All array operations should be done using pointers.
// This function searches through str for the character chr.
// If the chr is found, it returns a pointer into str where
// the character was first found, otherwise nullptr (not found).
const char* findTheChar(const char str[], char chr)
{
for (int k = 0; str[k] != 0; k++)
if (str[k] == chr)
return &str[k];
return nullptr;
} double mean(const double* scores, int numScores)
{
const double* ptr = scores;
double tot = 0;
while (ptr != scores + numScores)
{
tot += *ptr;
ptr++;
}
return tot/numScores;
}The strequal function is supposed to return true if and only if its two C string arguments have exactly same text. Explain what the problems with the implementation of the function are, and show a way to fix them.
// return true if two C strings are equal
bool strequal(const char str1[], const char str2[])
{
while (str1 != 0 && str2 != 0) // zero bytes at ends
{
if (str1 != str2) // compare corresponding characters
return false;
str1++; // advance to the next character
str2++;
}
return str1 == str2; // both ended at same time?
}
int main()
{
char a[15] = "Wang, A.";
char b[15] = "Wang, R.";
if (strequal(a,b))
cout << "They're the same person!\n";
}The computeCube function is correct, but the main function has a problem. Explain why it may not work and show a way to fix it. Your fix must be to the main function only; you must not change computeCube in any way.
void computeCube(int n, int* ncubed)
{
*ncubed = n * n * n;
}
int main()
{
int* ptr;
computeCube(5, ptr);
cout << "Five cubed is " << *ptr << endl;
}This program is supposed to write 30 20 10, one per line. Find all of the bugs and show a fixed version of the program:
int main()
{
int arr[3] = { 5, 10, 15 };
int* ptr = arr;
*ptr = 30; // set arr[0] to 30
*ptr + 1 = 20; // set arr[1] to 20
ptr += 2;
ptr[0] = 10; // set arr[2] to 10
while (ptr >= arr)
{
ptr--;
cout << *ptr << endl; // print values
}
}What does the following program print and why? Be sure to explain why each line of output prints the way it does
#include <iostream>
using namespace std;
int* maxwell(int* a, int* b)
{
if (*a > *b)
return a;
else
return b;
}
void swap1(int* a, int* b)
{
int* temp = a;
a = b;
b = temp;
}
void swap2(int* a, int* b)
{
int temp = *a;
*a = *b;
*b = temp;
}
int main()
{
int array[6] = { 5, 3, 4, 17, 22, 19 };
int* ptr = maxwell(array, &array[2]);
*ptr = -1;
ptr += 2;
ptr[1] = 9;
*(array+1) = 79;
cout << &array[5] - ptr << endl;
swap1(&array[0], &array[1]);
swap2(array, &array[2]);
for (int i = 0; i < 6; i++)
cout << array[i] << endl;
} Write a class which consists of four data members and four member function sum min max and factorial you can inilized class object or can be take by an function
You have been cordially invited to partake in Operation: Operation. Your mission, should you choose to accept it, is to take the two numbers and the operator given then perform the operation successfully.
Instructions:
Input
A line containing a number, operator, and another number separated by a space.
5·+·0.70Output
A line containing a decimal/float containing two decimal places.
5.70