-
1. C++ is case sensitive. What does this mean?
1. Capital letters are stored differently than lower case. Eg A is not equal to a
-
2. Why do we follow programming standards when writing our programs?
2. Standards allow maintenance programmers to work faster, therefore changes to programs cost less.
- 3. All C++ statements end with what character?
- 3. All C++ statements end with a semicolon.
-
4. What is a keyword? How do we identify keywords in our code?
4. A keyword is a word known by the compiler. Eg int, double, char are keywords.
- 5. What is a syntax error? Will a program run if there is a syntax error?
- 5. Syntax errors are caused mostly by typing or spelling mistakes. Programs will not run if there are syntax errors.
-
6. What is a logic error? Will a program run if there is a logic error?
6. Logic errors may happen when statements are in the wrong order are or missing. Programs can run, but do not produce the required results.
-
7. We need to enclose the program statements inside________________?
7. We need to enclose the program statements inside main.
-
Programming standards:
- 1) Code brace brackets on lines all by themselves, aligned.
- 2) indent statements inside brace brackets by at least 2 spaces.
-
Program execution:
source -> preprocessor->compiler ->linker ->loader
-
1. What is the purpose of the cout statement?
1. cout statements are used to display output onto the console.
- 2. What is a preprocessor directive?
- 2. An example of a preprocessor directive is #include The preprocessor copies code found in the header file iostream into the program.
-
3. What does a compiler do?
3. The compiler translates C++ into machine code.
-
4. At what statement does execution begin?
4. Execution begins at main.
- 5. Are you allowed to have blank lines in your code?
- 5. Yes.
-
1. What is the format for coding a comment that indicates the rest of the line is a comment?
1. //rest of the line is a comment
-
2. What is the format for coding a comment that uses delimiters to mark the beginning and ending of a comment? When would you use this format?
2. /* comments appear inbetween these */
-
3. Why don’t comments increase the program size when the program runs?
3. comments are removed by the compiler
-
4. Write a comment statement that includes your name.
4. //donna
-
2. How do you continue a C++ statement onto the next line?
2. Press enter (don’t code semi colon) and indent the statement onto the next line.
-
3. Write a cout statement that will print the title ‘Name’ onto the screen.
3. cout << “name”;
-
5. Write a cout statement that will move the cursor to the next line.
5. cout << endl;
-
6. What does endl do?
6. endl moves the cursor to the beginning of the next line.
-
7. What is the purpose of system ("pause"); ?
7. Prevents the output console from closing. User must close.
-
8. Correct the error in the following statements:
cout << " Hello " , " There " ;
cout << " Hello " << " There " ;
-
8. Correct the error in the following statements:
cout << " Bye "
cout << " Now " ;
- cout << " Bye ";
- cout << " Now " ;
-
8. Correct the error in the following statements:
cout >> " Hello
There " ;
- cout << " Hello"
- << "There " ;
-
8. Correct the error in the following statements:
int Main()
int main()
-
9. Write the statements that will print your name then program major, separated by a blank line.
cout << "Jeff" << endl << "CNTS";
-
Describe integer datatype
- no deciamls e.g. -3, 876
- size depends on hardware + compiler
- ours 4 bytes
- int
-
Describe character datatype
- any character on keyboard
- size is 1byte
- char
-
Describe real number datatype.
- e.g. 1.5 or 5E4
- 10 dec accuracy
- size depends on hardware + compiler
- ours 8 bytes
- double
-
Describe string datatype
- not a built-in datatype, need string header file
- #include <string>
- default size is 32 bytes, can be 0 or more than 32
- string
-
What datatypes are built in?
- integers int
- real numbers double
- character char
- bool not covered in COMP1100
-
2. If you need to store a number that will be used in arithmetic calculations, which data type(s) would you choose?
int and double
-
3. Which data type would you choose to store your postal code?
string
-
4. How many characters can be stored in a char data type?
1
-
5. Which data type would you choose to store your salary?
double
-
6. Can you store numbers in a string data type?
yes
-
1. What characters can be used when making up variable names?
letters, numbers and underscore
-
2. Give an example of the use of camel caps.
-
3. Indicate if the following are valid variable names
a) char
b) 4thTest
c) test#1
d)overDueAmountThisMonthToDate
e) test one
- a) char -no(key word)
- b) 4thTest-no(can't start with a number)
- c) test#1 -no(can't use #)
- d)overDueAmountThisMonthToDate - valid
- e) test one -no(can't have spaces)
-
4. How long can a variable name be?
Virtually any length
-
5. What variable name would you use to store your postal code?
postalCode
-
All variables must...
be declared prior to use, inside main. The are called local variables.
-
variable Format:
datatype variable name, variable name, .....variable name;
-
1. Write the statement that will declare a variable that will be used to store an employee’s name.
string empName;
-
2. Write the statement(s )that will declare your name and program major.
string name, major;
-
3. Write the statement(s) that will declare variables that will be used to store a product that will be sold in a store and its price.
- string productName;
- double price;
-
4. Write the statement that will be used to store a 1 byte code that is used to represent a customer’s status.
char status;
-
5. What values are initially found in the variables when declare?
garbage
-
1. Write the statement that will declare a variable to store your age. Initialize it to your age.
int age=48;
-
2. Write the statement that will declare a variable that will store your name. Initialize it to your name.
string name="Jeff";
-
3. Write the statement that will declare 3 integer variables, called test1,test2 and test3. Inialize test1 to 80. Do not initialize test2 and test3. What value will be stored in test2 and test3?
- int test1=80, test2, test3;
- test2 and test3 contain garbage
-
4. Write the statement that will declare a variable of type char called status. Initialize it to store a 1.
char status='1';
-
4. Write the statement that will declare a constant to store the letter A.
const char LETTER='A';
-
How do you temporarily change the datatype to avoid coercion?
- use static_cast(variable)
- e.g. static_cast(length)
|
|