HW 2 Lab 2 - Lab 2 Solve problems 1, 2 and 3 during the lab...

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

View Full Document Right Arrow Icon
Lab 2 Solve problems 1, 2 and 3 during the lab session. Work the additional exercises later. Electronically in DOCX format, submit your solutions to all problems and exercises by 11:59 p.m. Sun., Jan 31, 2009. Problem 1 Enter, compile and run the following code, adding proper C++ comments to explain what each line does. Submit your commented source (that is, submit the code with your comments added; do not submit output). #include <iostream> using std::cout; int main() { int x; int y = 9; double a = 4.7; cout << a << "\n"; cout << (x = y) << "\n\n" ; return 2; } Answer: #include <iostream> //includes iostream.h using std::cout; //allows me to use standard cout int main() //where the program starts executing { int x; //naming an integer x int y = 9; //integer y gets 9 double a = 4.7; //doubel a gets 4.7 cout << a << "\n" ; //outputs a and then jumps to the next line cout << (x = y) << "\n\n" ; //x gets y and then outputted and then jumps to the next line return 2; //return 2 to tell the program it is done
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

HW 2 Lab 2 - Lab 2 Solve problems 1, 2 and 3 during the lab...

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

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