Thisisa vestigialfeature readingacprogram scaffolding

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: in >> x; y = x * 7; cout << y; return 0; } int main() is a C++ construct that denotes the start of a function. main is a special function. It is the function called by the OS if the program is executed. The empty parentheses denote that main takes no input from the OS. “int” denotes that main will return an integer. This is a vestigial feature. Reading A C++ Program: Scaffolding #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 Braces { } denote a compound statement. The braces around the central program denote that it is all part of the main function. return 0; ends the main function and returns an integer 0 to the OS. #include <iostream> using namespace std; // multiply a number by 7 int main ( ) { double x, y; cin >> x; y = x * 7; cout << y; return 0; } #include <iostream> include <cmath> using namespace std { C double x, z; cout << “Please enter a number:” << endl; cin >> x; cout << “Please enter a second number:” << endl; cin >> y; z = x*x; z = z + y*y cout << “The answer is:” << sqrt(z) <<endl; { A Look at this error riddled program. Which are the declarations, which are the expressions and which are the scaffolding? B #include <iostream> include <cmath> using namespace std { C double x, z; cout << “Please enter a number:” << endl; cin >> x; cout << “Please enter a second number:” << endl; cin >> y; z = x*x; z = z + y*y cout << “The answer is:” << sqrt(z) <<endl; { A B C: scaffolding, A: declarations, B: expressions #include <iostream> include <cmath> using namespace std { There are between 1 and 7 errors in the program. How many do you see? double x, z; cout << “Please enter a number:” << endl; cin >> x; cou...
View Full Document

This note was uploaded on 03/12/2010 for the course ENGIN 101 taught by Professor Jeffringenberg during the Fall '07 term at University of Michigan.

Ask a homework question - tutors are online