C s150
This presentation is the property of its rightful owner.
Sponsored Links
1 / 28

c s150 PowerPoint PPT Presentation


  • 337 Views
  • Uploaded on
  • Presentation posted in: General

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 .

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


C s150

cs150

Tuesday, April 15th


8 arrays

8- arrays


C s150

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


C s150

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];


C s150

A collection of a fixed number of elements (called components) arranged in n dimensions (n>=1) is called a(n) ____.

a.matrixc.n-dimensional array

b.vectord.parallel array


C s150

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


C s150

Consider the following statement:

double alpha[5][10];.

The number of components of alpha is ____.

a.15 c.100

b.50d.150


C s150

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");


C s150

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';


C s150

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.


C s150

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;


C s150

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];


C s150

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;


9 classes

9- classes


C s150

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.


C s150

The components of a class are called the ____ of the class.

a.elementsc.objects

b.membersd.properties


C s150

Is the following class definition correct in C++?

class studentType

{

public void setData(string, double, int);

private string name;

};


C s150

Is the following class definition correct in C++?

class studentType

{

public:

void setData(string, double, int);

void print() const;

private:

string name;

double gpa;

}


C s150

Is the following class definition correct in C++?

class studentType

{

public:

void setData(string, double, int);

private:

string name;

};


C s150

If a member of a class is ____, you cannot access it outside the class.

a.publicc.private

b.automaticd.static

A class and its members can be described graphically using a notation known as the ____ notation.

a.OONc.UML

b.OODd.OOP


C s150

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.staticc.automatic

b.constd.private


C s150

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?


C s150

In C++, the ____ is an operator called the member access operator.

a..c.::

b.,d.#


C s150

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.staticc.local

b.automaticd.public


C s150

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.staticc.local

b.automaticd.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.automaticc.static

b.privated.const


C s150

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);


C s150

More on Thursday

Questions?


  • Login