T Naughton, CS NUIM
Back to CS211 home
Problem 1.3 Write a program that reads 10 integers from the user and stores them in an array of type int. Using a second array of type double, also of length 10, the program stores each of the first array's integers divided by 2. Finally, the program outputs each integer-double pair, one per line.
Problem T2.4 Write a function to exchange the values of its two arguments.
Problem 1.5 Similar to problem 1.3. However, this time, allow the user to enter any number of integers, specified at run-time (you will have to use new and delete). Furthermore, sort both arrays in ascending order before writing them out. Use any sorting algorithm you like (except the ones built into C++).
Problem 2A.2 Write code for the following function:
int findhighestlessthan100(int * list, int len){
/* This function returns the index of the element with the
** highest value in 'list' that is less than 100. 'list' is
** an integer array of length 'len'
*/
// your code here
}
Problem 2C.2 Write code for the following function:
int findclosestto10(int * list, int len){
/* This function returns the index of the element in 'list'
** that has a value closest to 10. 'list' is an integer
** array of length 'len'
*/
// your code here
}
Problem 2B.3 Write a program that reads 10 integers from the user and stores them in an array of type int. Using a second array of type double of length 2, the program stores the sum and the average of the list of integers. Finally, the program outputs the sum and average.
Problem 2C.3 Write a program that reads 31 integers from the user and stores them in an array of type int. Using a second array of type int, also of length 31, the program stores half the value of each of the first array's integers. Finally, the program outputs each int int pair where a rounding error has occurred.
Problem 3A.1 A computer program is required that reads positive integers, one per line, from the keyboard into a list. The user indicates that they are finished by entering any negative integer (the negative integer itself is not stored). The computer program then checks if any of the numbers in the list is the square root of any other number in the list. The program terminates after finding the first such number. Write this program using fixed-size arrays, the new and delete commands, and a loop to copy the elements from one array to another.
Sample runs of the program:
If the list is (13, 3, 4, 9, 12) then the program should return
The number 9 has a square root of 3 in the list.
If the list is (13, 3, 4, 10, 12) then the program should return
No square roots found in the list.
Problem 3B.1 A computer program is required that reads single letters, one per line, from the keyboard into a list. The user indicates they are finished by entering a '%' character (the '%' itself is not stored). The computer program then checks if any of the letters, anywhere in the list, appear next to each other alphabetically. The program terminates after finding the first such pair of letters. Write this program using fixed-size arrays, the new and delete commands, and a loop to copy the elements from one array to another.
Sample runs of the program:
If the list is (z, d, f, c, r) then the program should return
Letters d and c appear next to each other alphabetically.
If the list is (z, d, f, b, r) then the program should return
No letters appear next to each other alphabetically.