igure I below shows the screen output of Program I. Complete the program to generate the output as shown in Figure I. lote: You cannot create new variables and cannot use the overloaded operator for concatenation. ou are only allowed to use the functions to complete the program below. Output: SC student attends programming technique 2 Reversed: 2 euqinhcet gnimmargorp sdnetta tneduts CS Output vs. Reversed (compare): 1 Output vs. Reversed (length): 42 vs. 42 *Note: All the stated string variables are empty Figure 1: Screen output of Program 1 / Program 1 include sinclude sinclude using namespace std; int main(){ string name("SC STUDENT"); string word1="pro"; string word2="gram"; string word3="technique"; word1.append(word2); word1.append ("ming"); word1.insert(0, word1.append(word3); word1.insert(20, " "); attends "); word1. (30, 2"); // attends programming technique 2 word2.clear(); word3.clear(); word2.assign(name.substr(3,7)); string::iterator it; for(it=word2.begin(); it!=word2.end(); it++){ word3+=:: • (*it); // conversion of letter } (3,7, word3); name. name.append (word1); cout<<"Output: "<

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%
Figure 1 below shows the screen output of Program 1. Complete the program to generate the output as shown in Figure 1.
Note: You cannot create new variables and cannot use the overloaded operator for concatenation.
You are only allowed to use the functions to complete the program below.
Output: SC student attends programming technique 2
Reversed: 2 euqinhcet gnimmargorp sdnetta tneduts Cs
Output vs. Reversed (compare): 1
Output vs. Reversed (length): 42 vs. 42
*Note: All the stated string variables are empty
Figure 1: Screen output of Program 1
// Program 1
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(){
string name ("SC STUDENT");
string word1="pro";
string word2="gram";
string word3="technique";
word1.append (wогd2)%;
word1.append ( "ming");
word1.insert(0,
word1.append(word3);
word1.insert(20,
attends ");
");
word1.
(30, " 2"); // attends programming technique 2
word2.clear();
word3.clear();
word2.assign(name.substr(3,7));
string::iterator it;
for(it=word2.begin(); it!=word2.end(); it++){
word3+=::
• (*it); // conversion of letter
}
name.
(3,7, word3);
name.append (word1);
cout<<"Output: "<<name<<endl;
word2.clear();
for (int i=0; i<name.length(); i++){ word2=name.substr(i, 1)+word2; }
cout<<"Reversed: "<<word2<<endl;
cout<<"\nOutput vs. Reversed (compare): "<<name.compare(word2)<<end1;
cout<<"Output vs. Reversed (length): "<<name.length()<<" vs. "<<word2.length()<<endl;
name.clear();
if(name.
// final output: SC student attends programming technique 2
word1.clear(); word2.clear(); word3.clear);
// clear all string variables
&& word1.
&& word2.
&& word3
cout<<"\n*Note: All the stated string
variables are empty";
return 0;
// prove empty
Transcribed Image Text:Figure 1 below shows the screen output of Program 1. Complete the program to generate the output as shown in Figure 1. Note: You cannot create new variables and cannot use the overloaded operator for concatenation. You are only allowed to use the functions to complete the program below. Output: SC student attends programming technique 2 Reversed: 2 euqinhcet gnimmargorp sdnetta tneduts Cs Output vs. Reversed (compare): 1 Output vs. Reversed (length): 42 vs. 42 *Note: All the stated string variables are empty Figure 1: Screen output of Program 1 // Program 1 #include <iostream> #include <string> #include <cstring> using namespace std; int main(){ string name ("SC STUDENT"); string word1="pro"; string word2="gram"; string word3="technique"; word1.append (wогd2)%; word1.append ( "ming"); word1.insert(0, word1.append(word3); word1.insert(20, attends "); "); word1. (30, " 2"); // attends programming technique 2 word2.clear(); word3.clear(); word2.assign(name.substr(3,7)); string::iterator it; for(it=word2.begin(); it!=word2.end(); it++){ word3+=:: • (*it); // conversion of letter } name. (3,7, word3); name.append (word1); cout<<"Output: "<<name<<endl; word2.clear(); for (int i=0; i<name.length(); i++){ word2=name.substr(i, 1)+word2; } cout<<"Reversed: "<<word2<<endl; cout<<"\nOutput vs. Reversed (compare): "<<name.compare(word2)<<end1; cout<<"Output vs. Reversed (length): "<<name.length()<<" vs. "<<word2.length()<<endl; name.clear(); if(name. // final output: SC student attends programming technique 2 word1.clear(); word2.clear(); word3.clear); // clear all string variables && word1. && word2. && word3 cout<<"\n*Note: All the stated string variables are empty"; return 0; // prove empty
2 no X
Cisco X
n STRU X
Whic x
set1. X
My C x
New Tab x S StuD x S Wee x
G stati X
conv X -+
oloarningutm mu/20212/m uzattomnt phn2attomnt-ɔ7902icmid-110290
1. Which function is used to return a character array containing a null-terminated string?
empty() +
IMPORTANT: To answer Questions 2 to 4, please refer to the variable declarations (the first four statements in the main() function) in Program 1.
2. What is the output of word3.resize(4,'|0')?
3. What is the output of wordl.append(name)?
4. What will be happened after this command wordl.swap(word2); executes?
wordl =
* word2 =
5. What is the use and output of word2.assign(name.substr(3,7))?
Use:
• Output:
6. Give a reason why the Output string compared with the Reversed string in Figure 1 returns 1?
..
Transcribed Image Text:2 no X Cisco X n STRU X Whic x set1. X My C x New Tab x S StuD x S Wee x G stati X conv X -+ oloarningutm mu/20212/m uzattomnt phn2attomnt-ɔ7902icmid-110290 1. Which function is used to return a character array containing a null-terminated string? empty() + IMPORTANT: To answer Questions 2 to 4, please refer to the variable declarations (the first four statements in the main() function) in Program 1. 2. What is the output of word3.resize(4,'|0')? 3. What is the output of wordl.append(name)? 4. What will be happened after this command wordl.swap(word2); executes? wordl = * word2 = 5. What is the use and output of word2.assign(name.substr(3,7))? Use: • Output: 6. Give a reason why the Output string compared with the Reversed string in Figure 1 returns 1? ..
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY