Presentation is loading. Please wait.

Presentation is loading. Please wait.

Midterm Review CS1220 Spring 2006. Disclaimer The following questions are representative of those that will appear on the midterm exam. They do not represent.

Similar presentations


Presentation on theme: "Midterm Review CS1220 Spring 2006. Disclaimer The following questions are representative of those that will appear on the midterm exam. They do not represent."— Presentation transcript:

1 Midterm Review CS1220 Spring 2006

2 Disclaimer The following questions are representative of those that will appear on the midterm exam. They do not represent a complete list of the topics and types of questions that could be asked. Students should review the list of topics on the course web’s schedule page to determine the content they need to study

3 Topics Pointers – Declaration, assignment, as parameters, arithmetic, to functions, command-line arguments, for dynamic storage, for linked structures Dynamic Structures – Linked lists, building, maintaining, traversing, managing (allocation and freeing) Abstract Data Types – Linked lists, stacks, queues, lists, vectors, complex numbers – Using, building (constructors, operators, member functions, mutators, accessors)

4 Class Components In the class definition for Book below, clearly mark which lines are constructors, which are inspectors, and which are mutators. class Book { public: Book (); Book (string newAuthor, int newNumPages); read(it pageNum); string getAuthor() const {return author;} int getNumPages() const {return numPages;} void setAuthor(string newAuthor) {author = newAuthor;} void setNumPages(int newNumPages) {numPages = newNumPages;} private: string author; int numPages; };

5 Class Components In the following class implementation which keep the a book author’s name as a C-style character array, what is the line which reads “~Book();” called? What is its function? class Book { public: Book (); Book (char *newAuthor, int newNumPages); ~Book (); …. private: char *author; …. };

6 Class Definitions In the class declaration below: What does the “= 0” do? Show examples of the various possible ways the constructor for Book could be called. class Book { public: Book (char *newAuthor, int newNumPages = 0); void read(); …. };

7 Class Definitions Identify the 5 errors in the following class declaration, and annotate why they are errors. class tree { private: int tree (string name) : name(treeName) {} int grow(); string getName(); void setName(string name) : treeName(name) {} public: string treeName; }

8 C++ Language Syntax 1. Write a prototype for an ordinary (i.e., non-member) function called read, which returns an integer and receives two parameters: an int passed by value named pageNum and a reference parameter to an object of type Book named myBook. 2. A well-defined class using information-hiding coupled with the appropriate member functions so that it appears as a fundamental object of the language is called an ? 3. In the getNumPages method following, what does the word const mean? string getNumPages() const;

9 C++ Language Syntax In the following code found at the beginning of a header file, what is the purpose of these statements? #ifndef BOOK_H #define BOOK_H …. header body #endif

10 Pointers 1. What is a “memory leak”? 2. In the following declaration what does the word const mean? const int *p; 3. What does the following code declare? node* (*compare)(node* nodeA, node *nodeB);

11 Pointers Determine the values of m, n, and r after executing the following section of code. You can assume that m, n, and r are located in sequential memory addresses. int m=0, n=1, r=2; int *ptr1, *ptr2, *ptr3; ptr1 = &m; ptr2 = ptr1;m = ptr3 = &r; ptr1 = ptr3;n = ptr3 = &n; ptr3++;r = *ptr1 = 10; *ptr2 = 20; *ptr3 = 30;


Download ppt "Midterm Review CS1220 Spring 2006. Disclaimer The following questions are representative of those that will appear on the midterm exam. They do not represent."

Similar presentations


Ads by Google