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
What position is the first element of the array?
the first element of the array is always at position 0
What is the syntax to initialize multiple values stored in a array?
int data[5] = {0, 1, 2, 3, 4}
;
How are most one-dimensional arrays processed?
most processing of arrays are done one element at a time using a loop (usually a for loop)
Describe a method that can decide whether to put a unknown number of values from input into a array, given that the max possible number of inputs is known.
This can be accomplished by reading the input into a temporary variable and then evaluating if the variable should go into the array or not. To read an entire data file, a while (cin) statement can be used and continue to input cin to the temp variable.
Describe a method that can print an array to output.
use a for loop.
for (int j=0; j
What is a C++ file stream and what is a file in this context?
C++ file streams are a method to implement file input and output, where a file is a named area of secondary storage used to hold information
What is required to use C++ file streams?
include the fstream header file.
declare variables with data type “ifstream” and “ofstream”
open I/O for reading and writing and close when operations are complete
_.open(filename.c_str());
_.close(filename.c_str());
Handwrite the bubblesort function {ascending/descending note)
void bubblesort(int list[ ],int count) { int temp; for (int i=0; i < count-1; i++) for (int j=0; j < count-(i+1); j++) if (list[j] list[j+1]) { temp = list[j]; list[j] = list[j+1]; list[j+1] = temp; } }
Define “searching”
given a series of values and a target value, find out if the target is present and where it is located.