Lecture03

Info iconThis 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

Ask a homework question - tutors are online