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

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

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

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

View Full DocumentRight Arrow Icon
2 Ch. 1: The Simple Program s 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 s In C++, you can't use a variable until you declare its type. int x=-10; double y=3.2; char c = 'h'; s You can temporarily change a type by casting. s 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. s You have to be comfortable with arithmetic operations. + - * / % s Remember dividing integers gives an integer. s The mod operator % gives the remainder after division s Other operations in <cmath> : sqrt, pow, sin, cos
Background image of page 2
3 Ch. 2: Input/Output (I/O) s Our console I/O is defined in <iostream> . s Basic output: cout << x; Basic input: cin >> x; s Watch the arrows! s Remember the basic escape characters. b \n new line \t tab b \\ backslash \" double quote s Remember spaces won't show unless you put them there s We can chain the push/pulls. cin >> x >> y >> z; cout << " 2+2 = " << 2+2 << "\n"; s Get an entire line in string s: getline(cin,s); s Get one character in char c: cin.get(c); //Used in HW9. I/O Example s F06 #4c : Write the output of the following code. int good = 15; cout << good << "as\new" << good%4; 15as ew3
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Ch. 2: I/O Formatting s The <iomanip> library has functions for formatting your output. s setw(N) -- puts the next push into a box of width N, right justified. cout << setw(10) << "2+2=" << 4; s setprecision(D) -- displays D decimal places on doubles. ints still show like "2" s fixed -- forces doubles to show trailing zeros. s 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 s The <string> library allows use of string class. string s = "Hello Frodo!\n"; s 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) s Ex How does this change s? s[4] = 'Q'; s 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".
Background image of page 4
5 Example Using Strings s F08 #7b : Write the output of the following code.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online