The Highlighted Problems Are Assignment To Be Submitted .: Worksheet 6
The Highlighted Problems Are Assignment To Be Submitted .: Worksheet 6
Worksheet 6
The highlighted problems are assignment to be submitted……….
1. Describe the limitation of using array.
2. Give the definition of an array that represents the following matrixes and tell how much
space is reserved for each case.
a. 12 14 16 18 20 b. 1 2 3 4
5 6 7 8
9 10 11 12
3. Give the output of the following code fragment
a. int list [10] = {2,1,2,1,1 2,3,2, 1, 2}; b. int i, list [] = {2, 1, 2, 4, 1, 2, 0, 2, 1, 2};
cout << list[2] << endl; int line[10];
cout list[list[2] + list[3]]; for( i = 0, I < 10, i++)
cout << list[list[list[2]]] << endl; line[ i]=list[9-i];
for(i=0, i<10, i++)
cout << line[i] << “ “<<endl;
4. Refer to problem 2 and declare the array that represents the matrixes but do the initialization
using a loop.
5. Write a program that reads temperatures for a week, stores them in an array and display the
average temperature.
6. Write a program that accepts n integers from the user where n is supplied by the user and
searches for an element in the array.
7. Write a program that randomly stores values in an integer array of n elements when is an
integer obtained from the user, and then print the maximum and minimum value.
8. Rewrite the program you wrote in number 7 so that it displays the original numbers in the
array, the numbers sorted in ascending order, the minimum and the maximum.
9. Modify the program you have written in the previous problem so that it also displays the
frequency of the item in the array.
10. Write a program that reverses the first half elements of an array of characters with the second
half elements symmetrically, without the need to declare another array. E.g. {a,b,c,d,e,f}
reversed to {f,e,d,c,b,a}. Assume any type array.
11. Write a program that tracks scores for 3 tests each evaluated from 100 for utmost 30 students.
The program calculates the total score from 300 and the average score for each student and
display the original tests, the total and the average in a table format.
12. Write a program that merges two sorted array of numbers in a third array. The resulting array
must be sorted too. You can assume any two arrays.
13. Write a program that accepts a square matrix and displays the summation of
a. each rows b. each columns and c. The two diagonals
14. Write and test a program that performs perfect shuffle on an array of integers. A perfect
shuffle is a sequence obtained by interleaving its first half with the second half, always
moving the middle card to the front. For example, the perfect shuffle of
{1,2,3,4,5,6,7,8,9,10} is {6,1,7,2,8,3,9,4,10,5}
15. Write a program that reads two matrix, A and B, and then displays
a. A + B b. A - B c. A*B
16. Write a program that transposes a square matrix. Assume any square matrix.
1|Page
Adama Science and Technology University
School of Electrical Engineering and Computing
Department of Computer Science and Engineering
17. Write a program that keep tracks of the name of 20 students by accepting from the keyboard
and display the sorted names.
18. What is output of the following program?
#include <iostream.h>
void main()
{
int* p, *q, x=10, y=15;
q=&x //assumes this makes q=2000
p=q + 5;
cout <<”p=” <<p<< endl;
p=&y; //assume this makes p=3000;
cout <<”p=” <<p<< endl;
*p=*q+5;
cout <<”x=” <<x<< endl;
cout <<”y=” <<y<< endl;
cout <<”q=” <<q<< endl;
cout <<”p=” <<p<< endl;
}
19. Using the following declaration int ***p;
What is the type of each of the following expressions?
a. p b. *p c. **p d. ***p
20. Which of the followings are valid operation for the following declaration
char a=’A’, *p, **q, b[]=”Hello World”, c[]={‘H’,’e’,’l’,’l’,’o’};
int d[]={10,15,20};string s(”Hello World”);void *n; float *r;
a. p=&a; b. q=&p; c. q=&a; d. p=b;
e. p=a; f. a=*(p + 3); g. p=p+5; h. p=q+5;
i. p=p*5; j. b=p; k. q=&*&p; l. p=5-p;
m. q=NULL; n. cin >>p; o. ++p ; p. p=r;
q. p==0; r. p<q; s. q=&(b+5); t. n=p;
u. n=r; v. r=n; w. cout <<c; x. cout <<d;
y. cout << b; z. a=*(b + 6); z1.b=”Hello Universe”; z2.s=Hello Universe”;
21. Rewrite program 11 but now the program reads also the full name of the students and display
the result sorted by name
22. Write a program that counts the number of words in a text. Use pointer implementation
23. What is wrong with the following code? How do you correct it?
char code[]=”This is a secrete message…”;
void main()
{
int checksum=0;
while(*code)
{
checksum += *code;
++code;
}
}
2|Page