Quiz on Strings in C++
String is one of the most important and confusing topics in C++. Strings are used to store sequences of characters(text). However, a string variable is a collection of characters. You may still need to revise the concepts if you feel that you need to, so please visit the tutorial first and then come to this page to check them. You will need to move forward to the arena of our quiz once you have the confidence.
Let’s get started with the C++ String quiz. Good luck!
0 of 15 Questions completed Questions: You have already completed the quiz before. Hence you can not start it again. Quiz is loading… You must sign in or sign up to start the quiz. You must first complete the following: 0 of 15 Questions answered correctly Your time: Time has elapsed You have reached 0 of 0 point(s), (0) Earned Point(s): 0 of 0, (0) #include <iostream> #include <string> using namespace std; int main() { string str={“Hello World”}; cout<<str; return 0; } #include <iostream> #include <string> using namespace std; int main() { string str={“Hello World”}; cout<<str[6]; return 0; } #include <iostream> #include <string> using namespace std; int main() { string str; int i; cin>>str; for(i=2;i<str.length();i++) cout<<str[i]; } #include <iostream> #include <cstring> using namespace std; int main() { char s1[50]=”Hello”, s2[50]=”World”; strcat(s1, s2); cout << s1 << endl; return 0; } #include <iostream> #include <string> using namespace std; int main() { string s1 {“QuizOrbit”}; unsigned long int found = s1.find_last_of(“aeiou”); while (found != string :: npos) { s1[found] = ‘*’; found = s1.find_last_of(“aeiou”, found + 1); } cout << s1 << “\n”; return 0; } #include <iostream> #include <string> using namespace std; int main() { string s1 {“QuizOrbit”}; for (int i = 0; i < s1.length(); i++) { s1[i]=toupper(s1[i]); } cout<<s1; return 0; } #include <iostream> #include <string> using namespace std; int main() { string s1 {“QuizOrbit”}; for (int i = 0; i < s1.length(); i++) { s1[i]=tolower(s1[i]); } cout<<s1; return 0; } #include <iostream> #include <string> using namespace std; void fun(string str, string str1) { unsigned int found = str.find(str1); if (found != string :: npos) cout << found << endl; } int main() { string str {“C++ string Quiz”}; string str1 {“string”}; fun(str,str1); return 0; } #include <iostream> #include <string> using namespace std; void fun(string str, string str1) { cout<<str.capacity()<<” “<<str1.capacity(); } int main() { string str {“C++ String Quiz”}; string str1 {“string”}; fun(str,str1); return 0; } #include <iostream> #include <string> using namespace std; int main() { cout << is_same <int, char> :: value; cout << rank <char [10][10]> :: value; cout << is_same <char [10], string[10]> :: value; cout << rank <string[10][20][30]> :: value; return 0; } #include <iostream> #include <string> using namespace std; int main() { cout << is_array <char[5]> :: value; cout<<is_array<string>::value; cout << extent < string [10][20][30], 0> :: value; return 0; } #include <iostream> #include<vector> using namespace std; int main() { vector <string> studentrollno, studentname; studentrollno.push_back(“1”); studentrollno.push_back(“2”); studentrollno.push_back(“3”); studentname.push_back(“annu”); studentname.push_back(“radhe”); studentname.push_back(“lalit”); for(int i = 0; i<studentrollno.size(); i++) { cout << studentrollno[i] << ” “<<studentname[i]<<”,”; } return 0; } #include <iostream> #include <cstring> #include<string> using namespace std; int main () { string str1{ “C++ String”}; string str2{ “Quiz”}; string str3; int len ; str3=str1; str1=str1+str2; len = str1.length(); cout << len << endl; return 0; } #include <iostream> #include <string> using namespace std; int main () { string str {“C++ String Quiz”}; string::reverse_iterator rev; for (rev = str.rbegin() ; rev < str.rend(); rev++ ) cout << *rev; return 0; } Quiz Summary
Information
Results
Results
0 Essay(s) Pending (Possible Point(s): 0) Categories
1. Question
2. Question
3. Question
4. Question
5. Question
6. Question
7. Question
8. Question
9. Question
10. Question
11. Question
12. Question
13. Question
14. Question
15. Question
Summary
This might have become more apparent with the concepts we reviewed above in terms of C++ strings being mutable. Additionally, please share the quiz with others so that none of your friends miss out on the learning and fun doubles. Happy Learning!!