click below
click below
Normal Size Small Size show me how
CCS7 - Mod 3
Reviewer
| Question | Answer |
|---|---|
| What is the output of the given program? int main() { char ch1 = '!'; if (ispunct(ch1) ) cout << ch1 << " is a punctuation character"; else cout << ch1 << " is not a punctuation character"; return 0; } | ! is a punctuation character |
| 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 |
| It returns the length of a string | strlen() |
| 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 |
| int main () { int i; char str[]="c3po...??"; i=0; while (isalnum(str[i])) i++; cout << "The first " << i << " characters are alphanumeric.\n"; return 0; } What is the value of i? | 4 |
| What is the output of the program? #include <cstring> #include <iostream> using namespace std; int main () { cout.put('a'); return 0; } | a |
| Which of the following is a ctype function? | isalpha () |
| Checks if a character is printable | isprint() |
| #include <iostream> #include <string> using namespace std; int main() { string s = 'a'; cout<<s; return 0; } | error |
| 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; } | input provided by user |
| 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; } | Love |
| int main () { string s = "54.55"; double php = stod(s); cout << "A dollar is equivalent to " << php return 0; } | Error |
| Which of the following function converts a numerical value to string? | to_string |
| #include <iostream> #include <string> using namespace std; int main () { string str3(5, '#'); cout << str3; return 0; } | ##### |
| int main () { int i=0; char str[]="hello world!\n"; char c; while (str[i]) { c=str[i]; if (islower(c)) c=toupper(c); putchar (c); i++; } return 0; } | HELLO WORLD! |
| Returns true provided character expression is an uppercase letter otherwise it returns false | isupper() |
| Which of the following is a cstring function? | strcpy() |
| Returns true if character expression is either a letter or a digit otherwise false | isalnum() |
| A function used to concatenate strings | strcat() |
| Which of the following is NOT a ctype function? | strcmp() |
| Which of the following compares two string values? | strcmp() |
| Returns true if character expression is a letter of the alphabet otherwise false | isalpha () |
| 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 |
| Which of the following function converts a string to double? | stod |
| int main () { string str1 = "Hello"; string str2 = "World"; if (str1==str2) cout << "Equal"; else cout << "NOT Equal"; return 0; } | NOT Equal |
| Which of the following operator can be used also in strings? | + |
| using namespace std; int main () { string s ="79"; int n = stoi(s); cout << n; return 0; } | 79 |
| What is the output of the given program? #include <iostream> #include <string> using namespace std; int main () { string a = "Jessica "; a += "Jones"; cout << a; return 0; } | Jessica Jones |
| #include <iostream> #include <string> using namespace std; int main () { string str1 = "Hello "; string str2 = "World"; string str3; str3 = str1.append(str2); cout << str3 << endl; return 0; } | Hello World |
| int main() { char str1[] = "C++"; string str = "Programming"; int len1 = strlen(str1); int len2 = str.length(); cout << len1+len2; return 0; } | 14 |
| Which method do we use to append more than one character at a time? | both append and operator += |
| If two strings are identical, then the strcmp() function returns: | 0 |
| Check if a character is a control character | iscntrl() |
| Which of the following is NOT a cstring function? | sqrt() |
| Checks if a character is printable | isprint() if isprint() is in position 1 and 3 choose the third position |
| Compares up to num characters of the C string str1 to those of the C string str2 | strncmp() |
| What is the output of the given program? #include <iostream> #include <ctype.h> int main () { int i=0; char str[]="first line "; return 0; } | blank screen |
| int main () { char key[] = "apple"; char buffer[80]; do { cout << "Guess my favorite fruit? "; cin.getline(buffer,80); } while (strcmp (key,buffer) != 0); cout << "Correct answer!" return 0; } | Semicolon is missing |
| Returns true provided character expression is a whitespace character, such as the blank or newline character, otherwise, returns false. | isspace() |
| Which of the following operators is not a comparison operator? | #= |
| Which operator is suitable for the concatenation function of a string class? | + operator |
| A function that converts a string to double? | stod |
| What is the output of the following program? #include <iostream> #include <string> using namespace std; int main () { string myString = "Hello"; myString[0] = 'J'; cout << myString; return 0; } | Jello |
| int main () { string str1 = "Hello "; string str2 = "World"; string str3; str3 = str1 + str2; cout << str3 << endl; return 0; } | Hello World |
| int main() { char str1 []= "Bianca"; char str2 []= "Bianca"; cout << strcmp(str1, str2);; return 0; } | 0 |
| Check if a character is an uppercase letter | isupper() |
| Checks if a character is printable | If isprint() is at 2nd position and 4th position, choose 2nd position |
| It returns the lowercase version of a character expression: | tolower() |
| int main() { char str[] = "hj;pq91js4"; cout << "The digit in the string are:" << endl; for (int i=0; i<strlen(str); i++) { if (isdigit(str[i])) cout << str[i] << " "; } return 0; } | 9 1 4 |
| If b = “3.1416” then a is a: | string |
| The sequence of contiguous characters in memory is called _____________ | Character strings |
| 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 |
| Which of the following is used to read a line of input? | getline() |
| Converts lowercase letter to lowercase | tolower() |
| 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. |
| Which of the following function allows you to read on a character? | get() |
| What is the output of the given program? #include <iostream> #include <string> using namespace std; int main () { string str1 = "This is a test"; cout << str1.empty(); return 0; } | 0 |
| Strings are accessed by variables of what type? | char |
| int main() { string s1 = "Hello"; string s2 = "Programming"; cout<< s1 + " " + s2 + "!"; return 0; } | Hello Programming! |
| What is the header file for the string class? | #include <string> |
| What is the output of the following program? #include <string> #include <iostream> using namespace std; int main() { string x = "Bad "; cout << x.append("Liar"); return 0; } | Bad Liar |
| The same as the two-argument strcmp except that at most Limit characters are compared. | strncmp() |
| Returns true if the provided character expression is a printing character other than whitespace, a digit, or a letter; otherwise returns false. | ispunct() |
| Which of the following is correct? | cin.getline(str,80); |
| Compares the C string str1 to the C string str2 | strcmp() |
| What is the output of the program? #include <cstring> #include <iostream> using namespace std; int main () { cout.put('a'); return 0; } | a |
| The append operator is denoted by: | += |
| It converts a numerical value to string? | to_string |
| A string value should always have a _________ enclosed | Double quotation mark |
| Which of the following function converts the string to an integer? | stoi |
| Check if a character is a digit | isdigit() |
| It returns the uppercase version of a character expression. | toupper() |
| A header file that handles string in C++ | string |
| 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 |
| If two strings are identical, then the strcmp() function returns: | 0 |
| It returns true if str is an empty string | str.empty(); |
| Returns true provided character expression is a lowercase letter otherwise it returns false | islower() |
| Which of the following is a cstring function? | strcmp() |
| Which of the following is correct? | char str[80]; |
| A function which checks if a character is printable | isprint() |
| It is a sequence of characters | String |
| int main() { char str[] = "c++ programming"; for (int i=0; i<strlen(str); i++) putchar(toupper(str[i])); return 0; } | C++ PROGRAMMING |
| Which of the following converts string to float? | stof |
| What is the output of the following program? #include <iostream> #include <string> using namespace std; int main () { string str1 = "Hello"; int len = str1.size(); cout << len << endl; return 0; } | 5 |
| Converts lowercase letter to uppercase | toupper() |
| Returns true provided character expression is an uppercase letter otherwise it returns false | isupper() |
| If a = “$512” then a is a: | string |
| Which of the following is correct? chars s; Char s; CHAR s; char s; | char s; |
| What is the identifier given to string class to declare string objects? | string |
| The sequence of contiguous characters in memory is called _____________ | Character strings |