howthe output of
the following 4 program
segments
(a)
const int SIZE=8;
int values[SIZE] = {10, 10, 14, 16, 6, 25, 5,
8};
int index;
index=0;
res = values[index];
for (int j=1; j<SIZE; j++)
{
if (values[j] > res)
{
res =
values[j];
index = j;
cout << index << res
<< endl;
}
}
cout << index << “ “ <<
values[index] << endl;
(b)
const int SIZE=10;
int values[SIZE] = {0, 10, 14, 6, 6, 5, 5, 8};
int index=0;
int count=8;
bool flag = false;
int num = 6;
int result;
while (index < count && !flag)
{
if (values[index] == num)
{
flag =
true;
result =
index;
}
else
cout << “!”;
index++;
}
cout << result << endl;
(c)
const int SIZE = 10; // maximum number of items to
store in array
void MyFunc(int arr[], int pos, int &size);
int main()
{
int array[SIZE];
int position=2;
int aSize=6;
for (int i=0; i<aSize;
i++)
array[i] = i*10;
MyFunc(array, position,
aSize);
// display values after the
insertion
for (int i=0; i<aSize;
i++)
cout << array[i] << "
";
return 0;
}
void MyFunc(int arr[], int pos, int &size)
{
for (int i=pos; i<size-1;
i++)
{
arr[i] =
arr[i+1];
}
size--
}
(d)
typedef int * intPtr;
int main()
{
intPtr p, q;
int x, y;
p = & x;
*p = 10;
q = & y;
y=*p+10;
cout << *p << " "
<< *q << " " << x << " " << y
<< endl;
q = p;
*q = 20;
cout << *p << " "
<< *q << " " << x << " " << y
<< endl;
q = new int;
*q = x+y;
x = x+*q;
cout << *p << " " << *q << " "
<< x << " " << y << endl;
return 0;
}
A)
output
:
B)
output
C)
output
D)
output
howthe output of the following 4 program segments (a) const int SIZE=8; int values[SIZE]...
#include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){ int number; int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl; displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl; return 0; } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...
Question 1) Suppose a program has the following code: const int X = 2, Y = 3; int sum; int values[X][Y] = {{1, 2, 3}, {4, 5, 6}}; for(int i=0; i<X; i++) { sum=0; for(int j=0; j<Y; j++) sum+=values[i][j]; cout<<sum<<endl; } What is this program getting the sum of? Group of answer choices D-) The columns of the 2D array C-) The rows of the 2D array A-) All of the elements of the 2D...
what is the output of the following code segment? C++ g. int arr[3][4]; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) arr[i][j] =i*4 + j; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) cout << arr[i][j] << " "; h. int next(int & x) { x= x + 1; return (x + 1); int main() { int y = 10;...
12. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; *p = 35; *q = 98; *p = *q; cout << x << " " << y << endl; cout << *p << " " << *q << endl; 13. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; x = 35; y = 46; p...
Write the following function: const int MIN_SIZE = 2; const int MAX_SIZE = 8; const int UNKNOWN = 0; const int RED = 1; const int BLUE = 2; const char UNKNOWN_LETTER = '-'; const char RED_LETTER = 'X'; const char BLUE_LETTER = 'O'; const string UNKNOWN_STRING = "unknown"; const string RED_STRING = "X"; const string BLUE_STRING = "O"; /** * Requires: size <= MAX_SIZE and size is a positive even integer, * 0 <= row && row < size....
1. Your project will include the following three files: A header file: dynamicArray.h that includes a list of function prototypes as enumerated in the next section. An implementation file: dynamicArray.cpp that implements the functions declared in the header file. A test driver file: dynamicArray-main.cpp that includes the main() function so that you can test all the functions you've implemented above. 2. The header file dynamicArray.h will include the following list of functions: constructing a dynamic array of the specified size...
Write a program that works with two arrays of the same size that are related to each other in some way (or parallel arrays). Your two arrays must be of different data types. For example, one array can hold values that are used in a formula that produces the contents of the second array. Some examples might be: from a previous program, populations and the associated flowrates for those populations (an int array of populations and a double array...
can someone help me fix this. The function that finds the minimum and maximum values of the array and outputs the value and index doesnt find the maximum value of the array. #include <iostream> #include <fstream> #include<iomanip> using namespace std; void readArray(ifstream& inF, int arr[], int&ArrSize); void writeArray(ofstream & outF, int arr[], int & ArrSize); void MaxAndMin(ofstream & outF, int arr[], int & ArrSize, int &high, int &low); int main() { int arr[100]; int i = 0; ...
Example (4) Trace the following program and find the output >> SOURCE CODE #include <iostream.h> int main0 // define two integers int x-3; int y = 4; //print out a message telling which is bigger if (x >y) i cout << "x is bigger than y" << endl: else cout << "x is smaller than y" << endl; return 0; Example (5) Write a C++ program that takes from the user a number in SR (Saudi Riyal) then the program...
Part #2 Trace and show your steps and the output of the following code segment const int TEN = 10; int a(TEN), n = 354, num, c = 0; num = n; a[C++] = num % TEN; num = num/TEN; } while (num); cout << "The number" <<n<<" is now: for (int k = -1;k >= 0; k--) cout << a[k]; cout << endl; Trace and show the content of the arrays A and B int A[7] = {66, 55,...