MOD 1_ZYBOOKS 1 & 2_RECAP_1.2_3_6_9ish Flashcards
(23 cards)
What are the 5 integer numeric data types? What are their sizes in bits and supported number range?
What is the most commonly used integer type?
int (short is rarely used, only when needed to save space)
What are the 2 floating-point numeric data types?
Which floating point type is the most commonly used?
Today, double is. Decades ago, float was, but then larger computer memories allowed programmers to use a floating-point type that was “double” the size of float, hence the name.
Declare a character variable.
char myChar;
Assign character variable userKey with the letter g.
userKey = ‘g’;
Get a character from input for character variable userChar.
cin»_space; userChar;
What are the 5 common escape sequences?
Goal output: Say “Hello”
cout «_space;“Say "Hello"”
Print a message telling a user to press the letterToQuit key numPresses times to quit. End with newline.
cout «_space;“Press the “ «_space;letterToQuit «_space;” key “ «_space;numPresses «_space;” times to quit.” «_space;endl;
Declare the standard library (which also declaration of strings).
include <string></string>
Declare a string variable.
string userString;
Assign declared string variable myString with the word Hello.
myString = “Hello”;
Assign declared string variable newString with the string variable oldString.
newString = oldString;
What are the two ways to get input into declared string variable myString?
cin»_space; myString;
getline(cin, myString);
What is the difference between cin»_space; and getline() for inputting strings?
cin»_space;
- Skips inital whitespace/newline.
- Next whitespace/newline is not included and left in input.
getline:
- Gets all remaining text and whitespace.
- Next newline is not included and removed from input.
What happens when you use getline() AFTER cin»_space; ?
An extra getline() is needed to get past the newline left in the input by cin»_space;.
lastName1 = “Reacher”;
lastName2 = “Garber”;
lastNames = lastName1 + lastName2;
cout «_space;lastNames «_space;endl;
What is the output?
ReacherGarber
firstName1 = “Bob”;
firstName2 = “Jane”;
firstNames = firstName1 + “ and “ + firstName2;
cout «_space;firstNames «_space;” are in love.” «_space;endl;
What is the output?
Bob and Jane are in love.
What is a constant variable?
An initialized variable whose value cannot be changed.
Declare a constant variable of type double.
const double MINUTES_PER_HOUR = 60.0;
Declare a constant variable of type int.
const int DAYS_IN_YEAR = 365;
What is a pointer variable?
A variable that holds a memory address (which may hold data), rather than holding data.