Exam 3 Topics Flashcards

1
Q

What are the basic requirements to use the string data type?

A

Declare header file “#include “.

Declare variable of string type “string strvar;”.

Assign the variable “strvar = strexpression;”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How are string data types compared with each other?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the value-returning library function that finds number of characters in a string?

A

strvar. length()
strvar. size()

return a numeric data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the concatenation operator for the string data type? What is it used for?

A

”+” operator is used to join strings together

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does “getline” do? What is it’s syntax?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can individual characters of a string be accessed? What is the index?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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)

A

include cctype header file.
declare:

tolower(ch)
toupper(ch)

for (int i=0; i

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does “isalpha(ch)” do and which library is the function from?

A

isalpha(ch) will return true if ch is a letter, false if else. It is from cctype library

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does “isdigit(ch)” do and which library is the function from?

A

isdigit(ch) will return true if ch is a digit, false if else. It is from cctype library

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does “isupper(ch)” do and which library is the function from?

A

isupper(ch) will return true if ch is an uppercase letter, false if else. It is from cctype library

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does “islower(ch)” do and which library is the function from?

A

islower(ch) will return true if ch is a lowercase letter, false if else. It is from cctype library

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Define simple data type.

A

each variable can only store one value at a time and is the building block for structured types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Define structured data type

A

each data item is a collection of other data items

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Define what a one-dimensional array is.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the syntax for declaring an array?

A

datatype arrayname[intexp];

where intexp is any expression that evaluates to a positive integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What position is the first element of the array?

A

the first element of the array is always at position 0

17
Q

What is the syntax to initialize multiple values stored in a array?

A

int data[5] = {0, 1, 2, 3, 4}

;

18
Q

How are most one-dimensional arrays processed?

A

most processing of arrays are done one element at a time using a loop (usually a for loop)

19
Q

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.

A

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.

20
Q

Describe a method that can print an array to output.

A

use a for loop.

for (int j=0; j

21
Q

What is a C++ file stream and what is a file in this context?

A

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

22
Q

What is required to use C++ file streams?

A

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());

23
Q

Handwrite the bubblesort function {ascending/descending note)

A
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;
 }
}
24
Q

Define “searching”

A

given a series of values and a target value, find out if the target is present and where it is located.

25
Q

What is a unordered sequential search?

A

if values stored in an array and not sorted, then start at beginning of the array and compare the target to each value until a match is found (success) or there are no more values in the array (Failure)

26
Q

Handwrite a search function

A

int search(int list[],int n,int target)

{
for (int i=0; i

27
Q

Define a “record” (struct in C++)

A

A structured data type with a fixed number of components that are accessed by name. The components may be of different (heterogeneous) types. The components of a record are called fields. Declaring a record is creating a new data type.

28
Q

what is the 2 step process for declaring a record (Struct)

A
  1. declare (define) the new data type

2. declare variable(s)

29
Q

handwrite the syntax for declaring a new data type

A
struct TypeName
{
datatype fieldname; 
datatype fieldname; 
. . .;
};
30
Q

Where are custom data types declared generally?

A

declaration is generally made at the global level (after named constants, before prototypes)
so that the data type is recognized throughout the program.

31
Q

Explain how the fields in a record is accessed.

A

First declare the record. The record will then contain declared data variables all packaged together. Then in main function declare a variable that has the custom data type. Now the data variables in the record can be assigned object values (use “structName.varName = literal”)

32
Q

List three operations that must be done on a field by field basis.

A

Input/Output, Arithmetic, Comparison.

33
Q

List the aggregate operations that are allowed for Structs.

A

Assignment, parameter passage, return as a function’s return value.

34
Q

List the aggregate operations that are allowed for arrays.

A

Parameter passage.

35
Q

List the aggregate operations that are allowed for strings.

A

I/O, Assignment, Comparision, Parameter passage, return as a function’s return value