As stated in an earlier topic I am trying to follow the exercises in this book. However the answers to the questions seem to be missing and can not be found online either (at least not to the majority of them). I am hoping some one can look my answers over for me.
Chapter 0.
0.0 Compile and run the "hello world" program.
Done.
0.1 What does the following statement do?
It adds the number 4 to the number 3.Code:3+4;
0.2 Write a program that, when run, writes: "This is a quote (") and this is a backslash (\).
0.3 The string literal "\t" represents a tab character; different C++implementations display tabs in different ways. Experiment with your implementation to learn how it treats tabs.Code:#include<iostream> int main() { std::cout << "This (\") is a quote, and this (\\) is a backslash." << std::endl; return 0; }
Done.
0.4 Write a program that, when run, writes the "hello, world!" program as its output.
0.5 Is this a valid program? Why or why not?Code:#include<iostream> int main() { std::cout << "Hello world!" << std::endl; return 0; }
No, the curly braces ({}) are missing in the main function.Code:#include<iostream> int main() std::cout << "Hello, world!" << std:: endl;
0.6 Is this a valid program? Why or why not?
Yes, the program can be build. However the great amount of curly braces ({}) makes it hard to read.Code:#include<iostream> int main() {{{{{ std::cout << "Hello, world!" << std:: endl; }}}}}
0.7 What about this one?
No, the comment stops between the words "and" and "as".Code:#include<iostream> int main() { /* This is a comment that extends over several lines because it uses /* and */ as its starting and ending delimiters */ std::cout << "Does this work?" << std::endl; return 0; }
0.8 And this one?
Yes this will work. The "//" will comment out everything places behind it on that line.Code:#include<iostream> int main() { // This is a comment that extends over several lines // by using // at the beginning of each line instead of using /* // or */ to delimit comments. std::cout << "Does this work?" << std::endl; return 0; }
0.9 What is the shortest valid program?
0.10 Rewrite the "Hello, world!" program so that a new line occurs everywhere that white space is allowed in the program.Code:#include<iostream> int main() { 3+4; }
Code:#include<iostream> int main() { std::cout << "Hello" << std::endl; std::cout << "World!" << std::endl; return 0; }



LinkBack URL
About LinkBacks




CornedBee