1 / 28

c s150

c s150. Tuesday, April 15 th. 8 - arrays. Exam 2 – next Tuesday , You will need a blue scantron . 8 - arrays 9 - structs 10 - classes 12 - pointers 14 - exceptions 16 - searching/sorting/vectors - linked lists Exam 2, go over the solution – next Thurs .

judith
Download Presentation

c s150

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. cs150 Tuesday, April 15th

  2. 8 - arrays

  3. Exam 2 – next Tuesday, You will need a blue scantron. 8 - arrays 9 - structs 10 - classes 12 - pointers 14 - exceptions 16 - searching/sorting/vectors - linked lists Exam 2, go over the solution – next Thurs

  4. Given the following declaration: int j; int sum; double sale[10][7]; which of the following correctly finds the sum of the elements of the fourth column of sale? a. sum = 0; for (j = 0; j < 7; j++) sum = sum + sale[j][3]; b. sum = 0; for (j = 0; j < 7; j++) sum = sum + sale[j][4]; c. sum = 0; for (j = 0; j < 10; j++) sum = sum + sale[j][4]; d. sum = 0; for (j = 0; j < 10; j++) sum = sum + sale[j][3];

  5. A collection of a fixed number of elements (called components) arranged in n dimensions (n>=1) is called a(n) ____. a. matrix c. n-dimensional array b. vector d. parallel array

  6. In row order form, the ____. a. first row is stored first c. first column is stored first b. first row is stored last d. first column is stored last

  7. Consider the following statement: double alpha[5][10];. The number of components of alpha is ____. a. 15 c. 100 b. 50 d. 150

  8. Consider the following declaration: char str[15]; Which of the following statements stores "Blue Sky" into str? a. str= "Blue Sky"; b. str[15] = "Blue Sky"; c. strcpy(str, "Blue Sky"); strcpy("Blue Sky");

  9. Which of the following correctly declares name to be a character array and stores "William" in it? a. char name[6] = "William"; b. char name[7] = "William"; c. char name[8] = "William"; d. char name[8] = 'William';

  10. All components of an array are of the same data type. The array index can be any integer less than the array size. The statement int list[25]; declares list to be an array of 26 components, since the array index starts at 0. Given the declaration int list[20]; the statement list[12] = list[5] + list[7]; updates the content of the twelfth component of the array list. If an array index goes out of bounds, the program always terminates in an error.

  11. Suppose list is a one dimensional array of size 25, wherein each component is of type int. Further, suppose that sum is an int variable. The following for loop correctly finds the sum of the elements of list. sum = 0; for (int i = 0; i < 25; i++) sum = sum + list;

  12. What statement declares alpha to be an array of 25 components of the type int? a.intalpha[25]; c.intalpha[2][5]; b.int array alpha[25]; d.int array alpha[25][25];

  13. What is the output of the following C++ code? int list[5] = {0, 5, 10, 15, 20}; int j; for (j = 0; j < 5; j++) cout << list[j] << " "; cout << endl;

  14. 9 - classes

  15. A class is an example of a structured data type. In C++ terminology, a class object is the same as a class instance. The public members of a class must be declared before the private members. As parameters to a function, class objects can be passed by reference only.

  16. The components of a class are called the ____ of the class. a. elements c. objects b. members d. properties

  17. Is the following class definition correct in C++? class studentType { public void setData(string, double, int); private string name; };

  18. Is the following class definition correct in C++? class studentType { public: void setData(string, double, int); void print() const; private: string name; double gpa; }

  19. Is the following class definition correct in C++? class studentType { public: void setData(string, double, int); private: string name; };

  20. If a member of a class is ____, you cannot access it outside the class. a. public c. private b. automatic d. static A class and its members can be described graphically using a notation known as the ____ notation. a. OON c. UML b. OOD d. OOP

  21. The word ____ at the end of the member functions in the above class clockTypespecifies that these functions cannot modify the member variables of a clockType object. a. static c. automatic b. const d. private

  22. What is the name of the class? How many private members are in the class? What indicates private members in the class? What indicates public members in the class? What indicates protected members in the class?

  23. In C++, the ____ is an operator called the member access operator. a. . c. :: b. , d. #

  24. A class object can be ____. That is, it is created each time the control reaches its declaration, and destroyed when the control exits the surrounding block. a. static c. local b. automatic d. public

  25. A class object can be ____. That is, it can be created once, when the control reaches its declaration, and destroyed when the program terminates. a. static c. local b. automatic d. public In C++, you can pass a variable by reference and still prevent the function from changing its value by using the keyword ____ in the formal parameter declaration. a. automatic c. static b. private d. const

  26. Which of the followingis the correct prototype for a templatefunction (from lecture). template-class <functionT> T maxThree(T x, T y, T z); template <class T> T maxThree(T x, T y, T z); class <templateT> T maxThree(T x, T y, T z);

  27. More on Thursday Questions?

More Related