11. Classes - ENGR 101 Classes and Generic Routines ENGR...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
ENGR 101 1 Classes and Generic Routines ENGR 101, Lecture 11: 20 Oct 10 Announcements Project 5 due Wed 27 Oct (9pm) Exam 2 on Wed 3 Nov (6pm) contact Nader Jawad (njawad@umich.edu) about conflicts Mid-term course evaluations thanks for constructive feedback
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ENGR 101 2 Debugging Pointers (Outline) First hurdle: the compiler Incremental implementation using stubs Tracing program execution Monitoring expectations using assert The key to debugging is to understand what your program is actually doing. Multiple Choice The C++ compiler g++ A. catches all program errors B. tells you exactly what to do to fix an error C. clearly explains the source of the problem D. all of the above E. none of the above
Background image of page 2
ENGR 101 3 Compiler Errors Error messages are often not helpful reflect C++ syntax violations, often far removed from underlying cause Successfully compiles Correct an error is when your program does not mean what you intended often it is still a legal C++ program Find the Errors #include <iostream> include <cmath> using namespace std { double x, z; cout << "Please enter a number:" << endl; cin >> x; cout << "Enter a second number:" << endl; cin >> y; z = x*x; z = z + y*y cout << "The answer is:" << sqrt(z) << endl; { 2:error: expected constructor, destructor, or type conversion before ‘<’ token
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ENGR 101 4 Find the Errors (2&3 of ?) #include <iostream> #include <cmath> using namespace std { double x, z; cout << "Please enter a number:" << endl; cin >> x; cout << "Enter a second number:" << endl; cin >> y; z = x*x; z = z + y*y cout << "The answer is:" << sqrt(z) << endl; { 5:error: expected ‘;’ before ‘{’ token 5:error: expected unqualified-id before ‘{’ token Find the Errors (4–7 of ?) #include <iostream> #include <cmath> using namespace std; int main () { double x, z; cout << "Please enter a number:" << endl; cin >> x; cout << "Enter a second number:" << endl; cin >> y; z = x*x; z = z + y*y cout << "The answer is:" << sqrt(z) << endl; { In function ‘int main()’: 11: error: ‘y’ was not declared in this scope 14: error: expected ‘;’ before ‘cout’ 15: error: expected ‘}’ at end of input 15: error: expected ‘}’ at end of input
Background image of page 4
ENGR 101 5 A Less Direct Error Message 1. 2. void p(int & x, int y); 3. 4. int main () 5. { 6. int m, n=0, p=0; 7. cout << "Please enter a number:" << endl; 8. cin >> m; 9. p(m,n); 10. cout << "The answer is:" << m+n << endl; 11. } 9: error: ‘p’ cannot be used as a function Multiple Choice Which of the following will not compile? A. int x = 38.6; B. int x = + + + 38; C. int x = -+-38; D. int x=38; if (x = 42) cout << x; E. none of the above
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ENGR 101 6 Incremental Implementation: Stubs void winner(int pSequence, int qSequence, bool print, winner = true; return; } int winsForQ(int pSequence, int qSequence, int noOfGames) { return noOfGames/2; } void gatherStatistics(int pSequence, int noOfGames)
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/25/2011 for the course ENGR 101 taught by Professor Ringenberg during the Fall '07 term at University of Michigan.

Page1 / 18

11. Classes - ENGR 101 Classes and Generic Routines ENGR...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online