CSE 1310 - Practice Problems - Practice Set 2


Practice Problem 1

Write a function foo(int A, int B) that satisfies these specs: For example:


Practice Problem 2

Write a function print_special(String S) that satisfies these specs: For example, print_special("Texas") prints this:
T
ee
xxx
aaaa
sssss 


Practice Problem 3

Write a function print_special_to_file(String S, String output_file) that creates a new file, whose name is specified by argument output_file, such that the contents of the file are the same as the output shown on the screen in the previous problem.

More specifically, the contents of the output file should satisfy these specs:

For example, print_special_to_file("Texas", "target.txt") creates a file called target.txt, whose contents are these:
T
ee
xxx
aaaa
sssss 


Practice Problem 4

Write a function check_letters(String A, String B), that satisfies these specs: For example:


Practice Problem 5

Write a function check_ab(String S), that satisfies these specs: In other words, the function counts how many times letter 'a' appears in S, (counting both upper and lower cases), and how many times letter 'b' appears in S (counting again both upper and lower cases), and checks whether 'a' appears as many times as 'b'. For example:


Practice Problem 6

Write a function check_ab_in_file(String filename), that satisfies these specs: In other words, the function counts how many times letter 'a' appears in the text file, (counting both upper and lower cases), and how many times letter 'b' appears in the text file (counting again both upper and lower cases), and checks whether 'a' appears as many times as 'b'.


Practice Problem 7

Write a function find_N(int number) that satisfies these specs: For example:


Practice Problem 8

Write a function subarray_sums(int[][] items) that satisfies these specs: For example:


Practice Problem 9

Write a function pick_elements(int[] items, int[] positions) that satisfies these specs: For example:


Practice Problem 10

Write a function insert(int[] items, int position, int value) that satisfies these specs: For example: