Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Task 1: Dry run the following code and give the values of the variables using table as discussed:
Task 2: Dry run the following code, and provide array values after each call of printarray function.
cout << "at which index you want to insert data : ";
cin >> ind;
cout << "Enter data you want to put in array : ";
cin >> data;
b[i] = data;
printarray(b, size);
//array values?
Task 3: Dry run following programs and show contents of array 2 after execution.
void function1(int a[], int n1, int b[], int n2, int c[])
{
int i=0, j=0, k=0;
while (i<n1 && j<n2)
{
if(a[i]) < b[j]) { c[k] = a[i]; I = i+1; }
else { c[k] = b[j]; j= j+1; }
k = k + 1;
}
while (i < n1) { c[k] = a[i]; i = i+1; k = k+1;}
while (j<n2) { c[k] = b[j]; j = j+1; k = k+1}
}
int main()
{
cons tint array_size = 4;
return 0;
}
Task 4: Dry run following programs and show contents of array 2 after execution
void function1(int a[], int n1, int b[], int n2, int c[])
{ Int i=0, j=0, k=0;
while (i<n1 && j<n2)
{
if(a[i] < b[j]) { c[k] = a[i]; I = i+1; }
else { c[k] = b[j]; j = j+1; }
k = k+1;
}
while (i < n1) { c[k] = a[i]; i = i+1; k = k+1;}
while(j < n2) { c[k] = b[j]; j = j+1; k = k+1}
}
int main()
{
cons tint array_size = 4;
int x[array_size] = {3, 4, 10, 20};
int y[array_size] = {6, 9, 21, 27};
int z[2*array_size] = {0};
function1(x, array_size, y, array_size, z);
return 0;
}
Task 5: Write a function with an array of 10 values. The function also receives the range of indices. It sums all array
entries between the given range and returns the result.
And the starting index is 3, and ending index is 6. Then, the result returned is the sum of entries between index 3 and
index 6 is, which is 30 in this example.
Task 6: Write a C++ program with an array a of 10 values, filled with random numbers. The program copies this array a
into another array b in the following fashion.
1- First 5 elements of a are placed into the last 5 indexes of b in ascending sort.
2- Last 5 elements of a are placed into the first 5 indexes of b in reverse order.
For example, first 5 elements of a are colored, and the last 5 are not
10 5 8 2 3 17 8 9 14 5
in b they become
5 14 9 8 17 2 3 5 8 10
Task 7: Write a C++ program that deletes the first occurrence of a single character entered by user from a character
array starting from left side (index 0) of array.
Task 8: Improve Task 7 such that it not only deletes the first occurrence, but now deletes ALL occurrences of the
character entered by user from the character array.