Lecture03

Info icon This preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: Engineering 101 Engineering 101 Lecture 3 9/11/07 C++ Basics Quote of the Day Quote of the Day If you take no thought about what is distant, you will find sorrow near at hand. ­ Confucius From last lecture From last lecture Sequence Selection Iteration Greatest Common Factor 1: Request a value for a 2: Request a value for b 3: if a ≥ b then assign b to c 4: if a < b then assign a to c 5: while (remainder(a, c)≠0 OR remainder(b, c)≠0) 6: subtract one from c 7: return c 8: end From last lecture Scaffolding Identifiers Simple type #include <iostream> using namespace std; int main ( ) { double x, y; cin >> x; y = x * 7; cout << y; return 0; } Declaration Expressions Reading A C++ Program: Scaffolding #include <iostream> is a preprocessor directive. It tells the compiler to look for a header file important for accessing a library of algorithms. In this case we want to use the iostream library that describes how to get input from the keyboard and print output to the screen. #include <iostream> using namespace std; // multiply a number by 7 int main ( ) { double x, y; cin >> x; y = x * 7; cout << y; return 0; } Reading A C++ Program: Scaffolding Some of the identifiers in iostream have complicated names like std::cin to denote the “standard input stream” and std::cout for the “standard output stream”. using namespace std is a directive that tells the compiler to assume the prefix std:: so we can just type cin or cout. #include <iostream> using namespace std; // multiply a number by 7 int main ( ) { double x, y; cin >> x; y = x * 7; cout << y; return 0; } Reading A C++ Program: Scaffolding The next line in the program is a comment. Comments are denoted by //. Anything after the // is ignored and not considered by the compiler. Comments are important so that other human beings can understand your code. #include <iostream> using namespace std; // multiply a number by 7 int main ( ) { double x, y; c...
View Full 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