{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

midterm_review - CSE 332 Midterm Review Goals for todays...

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

View Full Document Right Arrow Icon
CSE 332 Midterm Review CSE 332 Midterm Review Goals for today’s review Review and summary of material in course so far A chance to clarify and review key concepts/examples Discuss details about the midterm exam In class during next class period (80 minutes) One 8.5”x11” face of notes + pencils/pens allowed All electronics must be off, including cell phones, etc. Recommendations for exam preparation Catch up on any studio exercises you’ve not done Write up your notes page as you study Ask questions here and on the message board
Image of page 1

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

View Full Document Right Arrow Icon
CSE 332 Midterm Review Writing a C++ Program C++ source files (ASCII text) .cpp Programmer (you) emacs editor C++ header files (ASCII text) .h 1 source file = 1 compilation unit Makefile (ASCII text) Also: .C .cxx .cc Also: .H .hxx .hpp readme (ASCII text) Eclipse Visual Studio
Image of page 2
CSE 332 Midterm Review Lifecycle of a C++ Program C++ source code Makefile Programmer (you) object code (binary, one per compilation unit) .o make “make” utility xterm console/terminal/window Runtime/utility libraries (binary) .lib .a .dll .so gcc, etc. compiler link linker E-mail executable program Eclipse debugger precompiler compiler link turnin/checkin An “IDE” WebCAT Visual Studio window compile
Image of page 3

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

View Full Document Right Arrow Icon
CSE 332 Midterm Review What Goes Into a C++ Program? Declarations: data types, function signatures, classes Allows the compiler to check for type safety, correct syntax Usually kept in “header” (.h) files Included as needed by other files (to keep compiler happy) class Simple { public: typedef unsigned int UINT32; Simple (int i); void print_i (); void usage (); private: int i_; }; Definitions: static variable initialization, function implementation The part that turns into an executable program Usually kept in “source” (.cc) files void Simple::print_i () { cout << “i_ is ” << i_ << endl; } Directives: tell compiler (or precompiler) to do something #include <vector> using namespace std;
Image of page 4
CSE 332 Midterm Review Using C++ vs. C-style Strings #include <string> #include <iostream> using namespace std; int main (int, char*[]) { char * w = “world”; string sw = “world”; char * h = “hello, ”; string sh = “hello, ”; cout << (h < w) << endl; // 0: why? cout << (sh < sw) << endl; // 1:why? h += w; // illegal: why? sh += sw; cout << h << endl; cout << sh << endl; return 0; } C-style strings are contiguous arrays of char Often accessed through pointers to char ( char * ) C++ string class (template) provides a rich set of overloaded operators Often C++ strings do “what you would expect” as a programmer Often C-style strings do “what you would expect” as a machine designer Suggestion: use C++ style strings any time you need to change, concatenate, etc.
Image of page 5

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

View Full Document Right Arrow Icon
CSE 332 Midterm Review C++ File I/O Stream Classes #include <fstream> using namespace std; int main () { ifstream ifs; ifs.open (“in.txt”); ofstream ofs (“out.txt”); if (ifs.is_open () && ofs.is_open ()) { int i; ifs >> i; ofs << i; } ifs.close (); ofs.close (); return 0; } <fstream> header file Use ifstream for input Use ofstream for output Other methods open, is_open, close getline seekg, seekp File modes in, out, ate, app, trunc, binary
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern