Lecture04 - Engineering 101 Engineering 101 Lecture 04...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight 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 04 Lecture 04 The Basics of C++ The Basics of C++ Prof. Michael Falk University of Michigan, College of Engineering Announcements Announcements Project 0 Due Tonight at 9pm Project 1 will be posted tonight, due next Wednesday Read up to Chapter 2.1-2.4 I am Concurrently Enrolled in the I am Concurrently Enrolled in the Following Math Class Following Math Class 1- Math 105 4- Math 215 2- Math 115 5- Math 216 3- Math 116 6- None of the above I Am Concurrently Enrolled in Bio I Am Concurrently Enrolled in Bio 162 162 1 - Yes 2- No Reading A C++ Program Reading A C++ Program #include <iostream> using namespace std; // add 5.5 to a number int main ( ) { double x, y; cin >> x; y = x + 5.5; cout << y; return 0; } #include <iostream> using namespace std; // add 5.5 to a number int main ( ) { double x, y; cin >> x; y = x + 5.5; cout << y; return 0; } Reading A C++ Program Reading A C++ Program Much of this program is scaffolding . Scaffolding is only important insomuch as it holds the program together and provides context for the C++ compiler. We will consider this part of the program later. The remaining part of the code consists of only 4 lines. The code reads in a number and then writes the result of adding 5.5 to the number. #include <iostream> using namespace std; // add 5.5 to a number int main ( ) { double x, y; cin >> x; y = x + 5.5; cout << y; return 0; } Reading A C++ Program Reading A C++ Program #include <iostream> using namespace std; // add 5.5 to a number int main ( ) { double x, y; cin >> x; y = x + 5.5; cout << y; return 0; } Reading A C++ Program: Declaration Reading A C++ Program: Declaration The first line of the body declares two containers to hold numbers. The identifiers of these containers will be x and y . It is important to declare every identifier before it is used. #include <iostream> using namespace std; // add 5.5 to a number int main ( ) { double x, y; cin >> x; y = x + 5.5; cout << y; return 0; } Reading A C++ Program: Declaration Reading A C++ Program: Declaration Simple declarations are of the form: simple_type identifiers; In this case the identifiers x and y are declared to be of the type double . For now we will consider two simple types: double and int . #include <iostream> using namespace std; // add 5.5 to a number int main ( ) { double x, y; cin >> x; y = x + 5.5; cout << y; return 0; } A double is a number with a fractional part that can take on a very large range of magnitudes. An int is an integer number between about -2 billion to 2 billion. Always choose the one closest to your meaning. Reading A C++ Program: Declaration Reading A C++ Program: Declaration #include <iostream> using namespace std; // add 5.5 to a number int main ( ) { double x, y; cin >> x; y = x + 5.5; cout << y; return 0; } The next 3 lines of the program are expressions ....
View Full Document

Page1 / 44

Lecture04 - Engineering 101 Engineering 101 Lecture 04...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online