Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you explain what this C++ code doing and give the detailed explanation of why the code does what it does. What is the output

Can you explain what this C++ code doing and give the detailed explanation of why the code does what it does.

What is the output of the following code? (You may assume that the file has all of the necessary #includes, etc).

1 string x = "one \"two\" three four"; 2 string y = "\"fivesix seveneight\""; 3 cout << x.length() <<" "; 4 cout << y.length() << " "; 5 string z; 6 7 if (x.length() <= y.length()) { 8 z = y+x; 9 } 10 else { 11 z = x+y; 12 } 13 string the_new_one = ""; 14 for (int i = 0; i < z.length(); ++i) { 15 if (i % 3 == 0) { 16 the_new_one += z.substr(i, 1); 17 } 18 } 19 cout << "" << the_new_one << " ";

Answer: 21 20 o w r oviseit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions