{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Lec25 - Lecture 25 Review PIC 10A Todd Wittman Final Exam...

This preview shows pages 1–6. Sign up to view the full content.

1 Lecture 25: Review PIC 10A Todd Wittman Final Exam square6 Sunday December 6th square6 Young Hall 76 square6 3:00-6:00 ( Daylight Savings on Sunday!!! ) square6 The final exam is worth 30% of your grade, same weight as 2 midterms. square6 Length is also roughly 2 midterms (2 hrs). square6 Very similar in style to practice exams and midterms. square6 Half short-answer, half long-answer. square6 Exam cover Ch. 1-7 + Sec 9.1, 14.4 square6 Remember to bring your student ID.

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

View Full Document
2 Ch. 1: The Simple Program square6 Recall the first C++ program you wrote: #include <iostream> using namespace std; int main ( ) { cout << "Hello Middle Earth!\n"; return 0; } Ch.2: Data Types square6 In C++, you can't use a variable until you declare its type. int x=-10; double y=3.2; char c = 'h'; square6 You can temporarily change a type by casting. square6 Remember casting a double to int chops the decimal. int a = 2; int b = 3; double c = (double) a / b; //Stores z = 0.666667 int d = (int) c; //Stores d=0. square6 You have to be comfortable with arithmetic operations. + - * / % square6 Remember dividing integers gives an integer. square6 The mod operator % gives the remainder after division square6 Other operations in <cmath> : sqrt, pow, sin, cos
3 Ch. 2: Input/Output (I/O) square6 Our console I/O is defined in <iostream> . square6 Basic output: cout << x; Basic input: cin >> x; square6 Watch the arrows! square6 Remember the basic escape characters. box2 \n new line \t tab box2 \\ backslash \" double quote square6 Remember spaces won't show unless you put them there square6 We can chain the push/pulls. cin >> x >> y >> z; cout << " 2+2 = " << 2+2 << "\n"; square6 Get an entire line in string s: getline(cin,s); square6 Get one character in char c: cin.get(c); //Used in HW9. I/O Example square6 F06 #4c : Write the output of the following code. int good = 15; cout << good << "as\new" << good%4; 15as ew3

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

View Full Document
4 Ch. 2: I/O Formatting square6 The <iomanip> library has functions for formatting your output. square6 setw(N) -- puts the next push into a box of width N, right justified. cout << setw(10) << "2+2=" << 4; square6 setprecision(D) -- displays D decimal places on doubles. ints still show like "2" square6 fixed -- forces doubles to show trailing zeros. square6 How do the following print statements differ? cout << 2.0/3 << " " << 3.0/3; cout << setprecision(2) << 2.0/3 << " " << 3.0/3; cout << fixed << setprecision(2) << 2.0/3 << " " << 3.0/3; Ch. 2: Strings square6 The <string> library allows use of string class. string s = "Hello Frodo!\n"; square6 Basic member functions: s.length() s.substr(pos,length) s.insert(pos,str) s.erase(pos,length) s1 + s2 (concatenation) s[i] (access char at position i) square6 Ex How does this change s? s[4] = 'Q'; square6 A good example problem for strings is the find and replace problem, e.g. replace all occurences in a phrase of "Star Wars" with "Lord of the Rings".
5 Example Using Strings square6 F08 #7b : Write the output of the following code.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 14

Lec25 - Lecture 25 Review PIC 10A Todd Wittman Final Exam...

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

View Full Document
Ask a homework question - tutors are online