Exam 3 Topics Flashcards
What are the basic requirements to use the string data type?
Declare header file “#include “.
Declare variable of string type “string strvar;”.
Assign the variable “strvar = strexpression;”
How are string data types compared with each other?
The ASCII value of the character values is used to compare strings with each other. The values are taken character by character until a decision can be made.
All lowercase letters > uppercase letters.
What is the value-returning library function that finds number of characters in a string?
strvar. length()
strvar. size()
return a numeric data type
What is the concatenation operator for the string data type? What is it used for?
”+” operator is used to join strings together
What does “getline” do? What is it’s syntax?
getline is a library function that reads all characters (including blanks) from the current location of the reading marker until the linefeed character is encountered.
getline(inputstream,strvar);
How can individual characters of a string be accessed? What is the index?
each character in a string can be accessed individually by its position in the string.
strvar[0] is the value of the 1st position of the string.
How can characters be converted to upper and lowercase? What is a two line statement that will capitalize all letters in a string?
(given that n=string length and strvar is the string)
include cctype header file.
declare:
tolower(ch)
toupper(ch)
for (int i=0; i
What does “isalpha(ch)” do and which library is the function from?
isalpha(ch) will return true if ch is a letter, false if else. It is from cctype library
What does “isdigit(ch)” do and which library is the function from?
isdigit(ch) will return true if ch is a digit, false if else. It is from cctype library
What does “isupper(ch)” do and which library is the function from?
isupper(ch) will return true if ch is an uppercase letter, false if else. It is from cctype library
What does “islower(ch)” do and which library is the function from?
islower(ch) will return true if ch is a lowercase letter, false if else. It is from cctype library
Define simple data type.
each variable can only store one value at a time and is the building block for structured types
Define structured data type
each data item is a collection of other data items
Define what a one-dimensional array is.
a one-dimensional array is a collection of fixed number of components, all with the same data type. The collection is arranged in list like form.
What is the syntax for declaring an array?
datatype arrayname[intexp];
where intexp is any expression that evaluates to a positive integer