1 |
h01 |
CS16 F17 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | |||
Optional: name you wish to be called if different from name above. | ||||
Optional: name of "homework buddy" (leaving this blank signifies "I worked alone") |
h01: Introduction to C++
ready? | assigned | due | points |
---|---|---|---|
true | Thu 09/28 02:00PM | Thu 10/05 02:00PM |
You may collaborate on this homework with AT MOST one person, an optional "homework buddy".
MAY ONLY BE TURNED IN IN THE LECTURE LISTED ABOVE AS THE DUE DATE. There is NO MAKEUP for missed assignments.
Reading: Read Chapter 1 (with a special focus on pages 18-32), Chapter 2 (sections 2.1 thru 2.3). If you do not have a copy of the textbook yet, there is one on reserve at the library under “COMP000-STAFF - Permanent Reserve”.
-
1. (5 pts) Before you come to your first discussion section (lab), PLEASE visit this website and create your College of Engineering account (unless you already have one). Then write your College of Engineering username below. (DO NOT WRITE YOUR PASSWORD!!!!! NEVER WRITE DOWN YOUR PASSWORD!!! Just your username!)
Website: <https://accounts.engr.ucsb.edu/create>
Write your username here:
2. (5 pts) Not including any comments that may appear, what are the first two lines that typically begin a C++ program that is going to may either output on the screen, and/or read input from the keyboard?
3. The author describes the difference between "syntax errors" and "logic errors", and also the difference between syntax errors that produce an "error message" vs. those that produce a "warning message". Briefly explain each of the items below in a way that makes the DIFFERENCES among them clear:
a. (5 pts) Syntax errors that result in an error message:
b. (5 pts) Syntax errors that result in an warning message:
c. (5 pts) Logic errors:
4. (5 pts) As you discovered when you read the textbook, for the most basic kind of input and output, C++ uses two words, and two symbols, along with variables and quoted strings. Unlike in some other languages (e.g. Python), quoted strings must always use double quote marks `"like this"`, never single quotes `'like this'`. (Single quotes are used for another purpose in C++.)
Inside a quoted string, `\n` means "newline". Quoted strings can only be output, while the value of a variable can be either output to the screen, or read in from the keyboard. Variable names are not put inside quotation marks. Also remember that every line of C++ that does input or output must end in a semicolon.
Write a line of C++ that will print out `Hello World` followed by a newline?.
(For full credit, be sure to end your line with a semicolon. That's true of all the problems in this section, but this is the only time I'll remind you.)
7. (5 pts) Assuming the variable `int age;` has already been declared, what line of code will read in a value for `age` from the user?
8. (5 pts) Assuming the variable `int balance;` has already been declared, write two lines of code that will ask (prompt) the user for a value for balance, and then read in the value of balance.
9. (5 pts) The textbook describes C++11 on p.27. Briefly, what is C++11? (A one sentence answer is good enough. Note that if your textbook does not describe C++11 on p. 27, then you may have the wrong edition. You need the 10th edition.)
10. (5 pts) What are the five main components of a computer?
11. (5 pts) What is the role of a compiler?
12. (5 pts) What is object code?
13. (10 pts) If the following statement were in a C++ program, what would it do?
cout >> "An apple a day";
cout << "Keeps the doctor away";
#include <iostream>
using namespace std;
int main ()
{
int area, base1, base2, height;
} //end program