Question
click below
click below
Question
Normal Size Small Size show me how
Com prog 2 Mod 3 4
Computer Programming 2 Module 2 & 3
Question | Answer |
---|---|
Check if a character is a digit | isdigit() |
Returns true provided character expression is a lowercase letter otherwise it returns false | islower() |
What is the output of the given program? #include <iostream> #include <ctype.h> using namespace std; int main () { int i=0; char str[]="Test String.\n"; char c; while (str[i]) { c=str[i]; if (islower(c)) c=toupper(c); | TEST STRING |
Check the following program #include <iostream> #include <ctype.h> using namespace std; int main () { int i; char str[]="c3po...??"; i=0; while (isalnum(str[i])) i++; cout << "The first " << i << " characters are al | 4 |
A function which checks if a character is printable | isprint() |
#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 |
#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 |
#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 |
Which of the following converts string to float? | stof |
Which of the following function converts a numerical value to string? | to_string |
#include <iostream> #include <string> using namespace std; int main () { string str1 = "Hello "; string str2 = "World"; cout << ""; return 0; } | Blank output |
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 str3(5, '#'); cout << str3; return 0; } | ##### |
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(Romance); return 0; } | Error |
It returns true if str is an empty string | str.empty(); |
Check if a character is blank | isblank() |
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 |
Which of the following is a ctype function? | isalpha () |
Compares up to num characters of the C string str1 to those of the C string str2 | strcmp() |
It returns the uppercase version of a character expression. | toupper() |
A function used to concatenate strings | strcat() |
Which of the following is a cstring function? | strcmp() |
#include <cctype> #include <iostream> #include <cstring> using namespace std; int main() { char str[] = "hj;pq91js4"; cout << "The digit in the string are:" << endl; for (int i=0; i<strlen(str); i++) { if (isdig | 9 1 4 |
#include <cctype> #include <iostream> #include <cstring> using namespace std; int main() { char str[] = "c++ programming"; for (int i=0; i<strlen(str); i++) putchar(toupper(str[i])); return 0; } | C++ PROGRAMMING |
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 |
What is the output of the given program? #include <iostream> #include <string> using namespace std; int main () { string str1 = ""; cout << str1.empty(); return 0; } | 1 |
#include <cstring> #include <iostream> using namespace std; int main() { char str1[] = "C++"; string str = "Programming"; int len1 = strlen(str1); int len2 = str.length(); cout << len1+len2; return 0; } | 14 |
What is the identifier given to string class to declare string objects? | string |
#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 |
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 |
A function directly writes into the file: | fprintf() |
Creates a new file or open an existing file | fopen() |
Which of the following is used to create an output stream? | iostream |
Which operator is used to insert the data into the file? | >> |
Which header file is used for reading and writing to a file? | #include<fstream> |
Which stream class is to only read from files? | ifstream |
What is the output of the given program? #include < iostream > using namespace std; int main () { char str[] = "Steve jobs"; int val = 65; char ch = 'A'; cout << val << endl; return 0; } | Error |
What is the output of the given program? #include<iostream> using namespace std; main() { class student { int rno = 10; } v; cout<<v.rno; } | Error |
Pick out the other definition of objects. | associate of the class |
Which of the following best defines a class? | Blueprint of an object |
It means displaying only essential information and hiding the details. | Abstraction |
Blueprint of an object | Class |
What is the output of this program? class Test { int x; }; int main() { Test t; cout << t.x; return 0; } | Error |
If a class is named Car and you will create an object named SportsCar, what would be the statement? | Car SportsCar; |
If a class is named Fruits and you will create an object named Apple, what would be the statement? | Fruits Apple; |
Which of the following operator is used for cout? | << |
File mode that opens a text file in append mode | rb |
Closes a file | fclose() |
What is the correct syntax for fclose() | fclose(fp); |
What does the following code do? while( (ch = getchar()) != '\n') { putc(ch, fp); } | Gets a character, put it into a file pointer until an enter is pressed |
Which stream class is used to both read and write on files? | fstream |
The ifstream would be used when: | reading a file |
A C++ library that allows working with files | fstream |
What is meant by ofstream in c++? | Writes to a file |
A behavior an object | class |
What is the additional feature in classes that were not in structures? | Member Functions |
Objects created are based on what? | class |
An object is a _________________ of a class | an instance |
Which of the following term is used for a function defined inside a class? | Member function |
What is the difference between a struct and a class in C++? | A class has a default privacy specification of private |