click below
click below
Normal Size Small Size show me how
CP2-Module 3
Character and String Manipulation: <cstring> and <string>
Question | Answer |
---|---|
Compares up to num characters of the C string str1 to those of the C string str2 strlen() strcmp() isalpha() strncmp() | strncmp() |
This header declares a set of functions to classify and transform individual characters. ctype.h math.h cstdlib.h iostream | ctype.h |
Returns true if character expression is a digit 0 through 9 otherwise false. isdigit() isalpha () isalnum() isspace() | isdigit() |
What is the output of the given program? #include <iostream> #include <ctype.h> int main () { int i=0; char str[]="first line \n second line \n"; while (!iscntrl(str[i])) { putchar (str[i]); i++; } return 0; } | first line |
Returns true if character expression is either a letter or a digit otherwise false isdigit() isalnum () isalpha() isspace() | isalnum () |
Check if a character is an uppercase letter isxdigit() Isupper() isupper() toupper() | isupper() |
What is the output of the given program? #include <iostream> #include <ctype.h> int main () { int i=0; char str[]="first line "; return 0; } Group of answer choices Error FIRST LINE blank screen first line | blank screen |
What is the output of the given program? #include <cctype> #include <iostream> #include <cstring> using namespace std; int main() { char str[] = "THIS IS A TEST"; for (int i=0; i<strlen(str); i++) putchar(tolower(str[i])); return 0; } | this is a test |
Returns true provided character expression is a lowercase letter otherwise it returns false islower() tolower() toupper() isupper() | islower() |
Which of the following is NOT a cstring function? strcpy() strncpy() strcat() sqrt() | sqrt() |
What is the output of the given program? #include <iostream> #include <string> using namespace std; int main () { string str1 = "This is a test"; string str2 = "test"; cout << "Word is found at index " << str1.find(str2,0); return 0; } | Word is found at index 10 |
The sequence of contiguous characters in memory is called _____________. Arrays Character strings Functions Identifiers | Character strings |
Which method do we use to append more than one character at a time? both append and operator += data operator += append | append |
What is the output of the following program? #include <iostream> #include <string> using namespace std; int main () { string str1 = "Trust"; int len = str1.size() cout << len << endl; return 0; } error 7 5 4 | error, no semi-colon after "int len = str1.size()" :-) |
If two strings are identical, then the strcmp() function returns: 1 -1 0 Error | 0 |
Which of the following function converts a numerical value to string? tolower to_string toupper stoi | to_string |
Strings are accessed by variables of what type? boolean double int char | char |
What is the output of the following? #include <iostream> #include <string> using namespace std; int main () { string myString = "Lovely"; cout << myString.substr(0,4); return 0; } Group of answer choices ely Lovely Error Love | Love |
What is the output of the following program? #include <string> #include <iostream> using namespace std; int main() { string str; cin>>str; cout<<str; return 0; } Group of answer choices error str input provided by user 0 | input provided by user |
Which of the following function is used to concatenate strings? strcpy() strcmp() strcat() stod() | strcat() |
Converts lowercase letter to uppercase isspace() isprint() toupper() isupper() | toupper() |
The same as the two-argument strcmp except that at most Limit characters are compared. strncmp() put() strcat() strcmp() | strncmp() |
What is the output of the program? #include <cstring> #include <iostream> int main () { char str[80]; strcpy (str,"these "); strcat (str,"strings "); strcat (str,"are "); strcat (str,"concatenated."); puts (str); return 0; } | these strings are concatenated. |
Checks if a character is blank isblank() isgraph() isalpha() isalnum() | isblank() |
Check if a character is alphanumeric isalnum() isdigit() isprint() isblank() | isalnum() |
It is a sequence of characters String Character Identifier Data Type | String |
Which of the following is NOT a cstring function? strncpy() strcpy() strcat() sqrt() | sqrt() |
Which of the following compares two string values? strcpy() strcmp() strlen() strcat() | strcmp() |
Which of the following operators is not a comparison operator? <= >= #= == | #= |
Which of the following function converts a string to double? stod stoll stoi stof | stod |
Which of the following operator can be used also in strings? - > @ + | + (concatenation operator) |
A string value should always have a _________ enclosed parenthesis Double quotation mark semicolon ampersand | Double quotation mark |
Which operator is suitable for the concatenation function of a string class? > operator – operator < operator + operator | + operator |
What is the output of the following program? #include <iostream> #include <string> #include <cmath> using namespace std; int main () { string s = "54.55"; double php = stod(s); cout << "A dollar is equivalent to " << php return 0; } | Error, syntax error at cout statement. |
If b = “3.1416” then a is a: float integer double string | string, because it is enclosed in double quotation marks. |
What is the output of the following program? #include <iostream> #include <string> using namespace std; int main () { string myString = "Hello"; cout << myString[0]; return 0; } H 0 Error Blank output | H |
What is the output of the following program? #include <string> #include <iostream> using namespace std; int main() { string x = "Bad "; cout << x.append(Romance); return 0; } Error Bad Romance Romance Bad | Error |