An introductory course in di erential geometry and the Atiyah ...
19 pages
English

Découvre YouScribe en t'inscrivant gratuitement

Je m'inscris

An introductory course in di erential geometry and the Atiyah ...

-

Découvre YouScribe en t'inscrivant gratuitement

Je m'inscris
Obtenez un accès à la bibliothèque pour le consulter en ligne
En savoir plus
19 pages
English
Obtenez un accès à la bibliothèque pour le consulter en ligne
En savoir plus

Description

  • exposé
An introductory course in differential geometry and the Atiyah-Singer index theorem Paul Loya Binghamton University, Binghamton NY 13902-6000 E-mail address:
  • topological aspect of the index
  • euler characteristic of the circle
  • linear map
  • dimension theorem
  • diagonal matrix with entries
  • dim
  • dimensional vector spaces
  • index
  • matrix
  • euclidean space

Sujets

Informations

Publié par
Nombre de lectures 31
Langue English

Extrait

CS193D Handout 27
Winter 2005/2006 March 24, 2006
Final Exam Answers
We were very pleased with the results of the final exam. There were quite a few
tricky questions on there and the class still pulled off an average grade of 88.8.
There was only one perfect score, but several came close.

Here is the histogram:




There are comments and solutions for each problem below. If you have questions
about your exam, take a look at the solution first, then we'll be glad to answer
any further questions.
1
Part 1: True or False (15 points) Class Average: 12.7/15)

Indicate whether each statement is true or false. There is no penalty for guessing,
and you do not need to justify your answers.

1) Since it never flushes the output stream buffer, the following program will
never output anything.

int main(int argc, char** argv)
{
cout << "What happened to Andrae?";
}
Answer 1: False. One of the conditions for flushing is that the stream gets
destructed, which will happen here when the program exits. Also, nobody caught
the Project Runway reference. I guess I'm the only one whose wife makes them
watch that awful show.

2) At a particular time, a file stream can be both "not good" and "not bad." In
other words, stream.good() could be false even if stream.bad() is false.
Answer 2: True. For example, when an input stream reaches end of file, it is
!good() because you can't read any further but it's !bad() because there has not
been a fatal error.

3) If a function provides a throw list but doesn't include any exceptions in the
list, then it can safely throw any exception. In other words, the following function
can throw any exception without invoking the unexpected handler:

void tomServo(int i) throw()
{
[etc]
}
Answer 3: False. An empty throw list means that you won't throw anything. If
you omit the throw list entirely, that means you can throw anything.


4) Destructors should never be virtual because you don't really override a
destructor when you create a subclass.


Answer 4: False. Destructors should always be virtual!
2
5) In the following class, foo will be constructed before bar:

#include "Mucus.h"

class Marvin {
public:
Marvin() : bar(2), foo(3) {}

Mucus foo;
Mucus bar;
};

Answer 5: True. Objects are constructed in their list order in the class
definition, not their order on the initializer list.

6) Passing a data member as an argument in the initializer list is dangerous
because the data member will not have been properly initialized. For example,
the following constructor is potentially error-prone:

#include "Game.h"
#include "Player.h"
class Taboo : public Game {
public:
Taboo() : Game(mPlayer) {}

protected:
Player mPlayer;
};


Answer 6: True. Remember the order of construction. The superclass is
constructed before any data members, so it's a bad idea to pass data members to
the superclass.


7) static methods cannot be virtual. Thus, they are not polymorphic.


Answer 7: True. I was surprised how many people missed this. It's important!
static isn't polymorphic – a static method call is bound to the compile time type!
3
8) Consider the following two classes:

class Super {
public:
virtual void foo() {
cout << "Super::foo()" << endl;
}
virtual void foo(int i) {
cout << "Super::foo(" << i << ")" << endl;
}
};

class Sub : public Super {
public:
virtual void foo() {
cout << "Sub::foo()" << endl;
}
};
Since Sub doesn't override the one-argument version of Super::foo(int), the
following code will call Super's version, outputting "Super::foo(3)":

Sub mySub;
mySub.foo(3);
Answer 8: False. I think a lot of people correctly detected that something bad
was happening here, but forgot what. When you override only one of the
overloaded versions, the other one gets hidden. You can still call it through a
cast, but not from a subclass instance. The code above doesn't compile!


9) The principle of Refactoring acknowledges that over time, code gets convoluted
and unmaintainable, and needs to be reorganized.
Answer 9: True. I referred to this as cruft during lecture. It's all the gunk that
accumulates over time that you want to go in and rewrite/reorganize.

10) The software development methodology known as The Waterfall Model is an
iterative approach that breaks a problem down into a number of smaller
individual development cycles.


Answer 10: False. The Waterfall Method is not iterative. That's its main weakness.
Most modern approaches are iterative and break a task into smaller subtasks.


4
11) Extreme Programming says that you should start with designs that are as
general as possible, so that they can be reused for different programs.

Answer 11: False. A lot of people answered true, probably because a
programmer's natural instinct is that things should be generalized. However, XP
claims that you should write the simplest possible solution. Remember the
mantra – no speculative generality!

12) With a few minor exceptions, the C++ language is a superset of the C
language. In other words, most C code will compile and run just fine in C++.

Answer 12: True. This goes way back to lecture 1 and the all your favorite stuff
from C is still present in C++ claim. I think some people were tripped up thinking
that there were no exceptions, but that's not true. C++ has new reserved words,
like "class" which C didn't have. So a C program with a variable named "class"
won't compile in C++, but most C code will.

13) A function that takes an object of type Foo can be called on an object of type
Bar as long as Foo has an implicit Bar constructor, as shown below:

class Foo {
public:
Foo() {}
Foo(const Bar& inBar) {}
};

void doFoo(Foo inFoo);

int main()
{
Bar myBar;
doFoo(myBar);
}


Answer 13: True. Remember that a constructor that takes another class
(something that looks like a copy constructor, but for another type) is called
automatically by the compiler when necessary. Part 3 makes use of this feature.
5
14) If you overload operator+, you must return an object of the same type as
your parameters. Otherwise, it won't compile. For example, the following code
will not compile:

// I claim that this won't compile
Bar operator+(const Foo& lhs, const Foo& rhs);

Answer 14: False. Remember that return types are generally ignored as far as
method signatures are concerned. You can return whatever type you want. A
MrPibb plus a RedVine can give you a CrazyDelicious.


15) XML defines a syntax for representing data, but the meaning of the data
varies from application to application.

Answer 15: True. Recall that XML is just a file format, just a structure. It has no
meaning without a specific application to interpret it.


Part 2: Short Answer (20 points) Class Average: 18.76/20

1) One of the problems with C++ exceptions is that they can result in memory
leaks as the stack frames are unwound. There are, however, at least three ways
that you can protect against exceptions causing memory leaks.

Name two ways that you can author your functions to protect against exceptions
causing memory leaks. Note that they don't have to necessary be technical in
nature:

Lots of possible answers here. The ones we talked about in class were:
1. Don't use dynamic memory. Keep everything on the stack.
2. Use smart pointers or auto_ptr
3. Catch, clean up, and rethrow all exceptions

There were some other acceptable answers, but these were the most common
ones. We also accepted "Don't use exceptions." Some people's answers were way
too vague or didn't actually solve the problem. For example, "Use custom
exception types" is not a solution, though it may be a good idea for other reasons.
6
2) Say you've been hired by Microsoft to write a compiler for C*, a new language
that's just like C++, except that Microsoft can add whatever new language
features it wants without the trouble of going through a standards body.
One of your co-workers proposes a solution to the problem of C++
exceptions causing memory leaks (see previous question). She suggests that
when an exception is thrown in C*, the language is smart enough to call delete or
delete[] (as appropriate) on every pointer it encounters as it unwinds the stack. In
other words, stack-based objects are destructed just like in C++, but pointers are
deleted. Describe briefly

  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents