CH2 -CHECKPOINT QUESTIONs
Write a program that stores your name, address, and phone number in separate string objects. Display the contents of the string objects on the file screen.
#include <iostream> #include <string> int main () { string name = "Stephanie Raymond"; string address = "810 Village Dr.\nClyde, NC 28721"; string phone = "555-5050"; cout << name << endl; cout << address << endl; cout << phone << endl << endl; return 0; }
Write a program that has the following character variables: first, middle, and last. Store your initials in these variables and then display them on the screen.
#include <iostream> using namespace std; int main() { char first, middle, last; first = 'T'; middle = 'E'; last = 'G'; cout << first << " " << middle << " " << last << endl; return 0; }
Write a program that defines an integer variable named age and a float variable named weight. Store your age and weight, as literals, in the variables. The program should display these values on the screen in a manner similar to the following: My age is 21 and my weight is 137 pounds.
#include <iostream> using namespace std; int main() { int age; float weight; age = 26; weight = 180; cout << "My age is " << age << endl; cout << "My weight is " << weight << endl; return 0; }
Which of the following is a character literal? 'B' "B"
'B'
Assuming the char data types uses 1 byte of memory how many bytes do the following literals use? 'Q' "Q" "Sales" '\n'
'Q' uses one byte "Q" uses two bytes "Sales" uses six bytes '\n' uses one byte
How would the following number in scientific notation be represented in E notation? 6.31 x 10^17
6.31E17
Refer to the data types listed in Table 2-6 for questions. A) If a variable needs to hold numbers in the range 32 to 6,000, what data type would be best? B) If a variable needs to hold numbers in a range -40,000 to +40,000, what data type would be best? C) Which of the following literals(constants) uses more memory? 20 or 20L
A)short or unsigned short B) int C) They both use the same amount of memory.
Is the following assignment statement valid or invalid? If invalid, why?
Invalid. The value on the left of the = operator must be an lvalue.
Yes or no: is there an unsigned floating point data type? If so, what is it ?
No.
What is wrong with the following program statement? char letter = "Z";
The string constant "Z" is being stored in the character variable letter.
What header file must you include in order to use string objects?
The string header file.
On a computer, which data types uses more memory, an integer or an unsigned integer?
They both use the same amount of memory.
Write statements using const qualifier to create named constants for the following literal values" Literal Values Description 2.71828 Euler's number (e) 5.256E5 Number of minutes in yr 32.2 Gravitational accerl.const (feet) 9.8 Gravitational accerl.const (meters) 1609 Number of meters in a mile
const float E = 2.71828; const int MINUTES_IN_A_YEAR = 5.256E5; const float G_FEET = 32.2; const float G_METERS = 9.8; const int METERS_IN_A_MILE = 1609
How would you consolidate the following definitions into one statement? int x = 7; int y = 16; int z = 28;
int x = 7, y = 16, z = 28;