You are on page 1of 1

Ho Chi Minh City University of Technology

Department of Electronics and Electrical Engineering

CS225: Data Structures and Programming Principles Homework 1


(Deadline: 17 Sep 2013) 1. What are the contents of string S after executing the following statements string s = abc; string t = cde; s += s + t[1] + s; 2. Consider the following attempt to allocate a 10-element array of pointers to doubles and initialize the associated double values to 0.0. Rewrite the following incorrect code double* dp[10]; for (int i=0; i<10; i++) dp[i] = 0.0; 3. Write a C++ function printArray(A, m ,n) that prints an mn two dimensional array A of integers, declared to be int** A, to the standard output. Each of the m rows should appear on separate line 4. What is different about the behavior of the following two function f() and g() which increment a variable and print its value? void f(int x) { std::cout << ++x;} void g(int& x) { std::cout << ++x;} 5. Write a C++ class, AllKinds, that has three member variables of type int, long, and float, respectively. Each class must include a constructor function that initializes each variable to a nonzero value, and each class should include functions for setting the value of each type, and computing and returning the sum of each possible combination of types. 6. Write a short C++ function, isMultiple(), that takes two long values, n and m, and returns true if and only if n is multiple of m, that is, n=m*i for some integer i. 7. Write a short C++ function, isTwoPower(), that takes and int i and returns true if and only if i is a power of 2. Do not use multiplication or division, however. 8. Write a short C++ function that takes an integer n and returns the sum of all the integers smaller than n. 9. Write a short C++ program that prints its own source code when executed but does not perform any input or file reading. 10. Write a C++ function that takes an STL vector of int values and print values and prints all the odd values in the vector.

Instructor: Dr. Truong Quang Vinh

You might also like