1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Leviafan [203]
3 years ago
13

13. Write a function which is passed two strings. The function creates a new string from the two original strings by copying one

character from each in turn until all characters have been copied.

Engineering
1 answer:
attashe74 [19]3 years ago
3 0

Answer:

I am writing the code in C++. Let me know if you want the program in some other programming language.

#include <iostream>  // includes header file for input output functions

using namespace std;     //to identify objects like cin cout

string CopyStrings(string string1, string string2)  

{   string newString = "";    

   for (int loop = 0; loop < string1.length() ||  

                   loop < string2.length(); loop++)      {      

       if (loop < string1.length())  

           newString += string1[loop];          

       if (loop < string2.length())  

           newString += string2[loop];      }  

   return newString;   }  

int main()  

{   string stringA = "ace";  

   string stringB = "bdf";  

   cout << CopyStrings(stringA, stringB);   }

Output:

abcdef

Explanation:

The function CopyStrings() function takes two strings i.e. string1 and string2 as parameters to copy characters from both the string one character from each.

The newString variable stores the new string after copying characters from both strings string1 and string2.

Then the for loop starts which has a variable loop which is an index variable that traverses through both the strings stored in string1 and string2. The loop continues to execute until it moves through entire length of string1 and string2 which means it copies all the characters from both string1 and string2. length() is used here which returns length of the string1 and string2.

If statement in the for loop checks the character that loop (index) variable is pointing to is less than the string1 length which means it checks each character stored in string1. For example if string1 contains "ace" and loop variable is moving through the string and is currently at "a" then this condition is true. If the condition evaluates to true then the body of if statement is executed. The next statement stores that character a into the newString variable.

Next If statement checks character that loop variable is pointing to is less than the string2 length which means it checks each character stored in string2. For example if string2 contains "bdf" and loop variable is moving through the string and is currently at "b" then this condition is true. If the condition evaluates to true then the body of if statement is executed. The next statement stores that character b into the newString variable.

Then the second iteration starts which again first stores the next character i.e. c from string1 into newString and then stores next character i.e d from string2 into newString.

Then the third iteration starts which again first stores the next character i.e. e from string1 into newString and then stores next character i.e f from string2 into newString.

Then the loop breaks as the loop variable reaches end of both the string1 and string2.

return newString will return the copied string into the output screen which is abcdef.

The screenshot of code along with output is attached.

You might be interested in
we want to make a schottky diode on one surface of an n-type semiconductor, and an ohmic contact on the other side. the electron
RoseWind [281]

Answer:

<h2>hope it helps you see the attachment for further information .....✌✌✌✌✌</h2>

7 0
3 years ago
A(n) _____________ is used commonly in open split-phase motors to disconnect the start winding from the electrical circuit when
Alenkasestr [34]

A <u>centrifugal switch</u> is used commonly in open split-phase motors to disconnect the start winding from the electrical circuit when the motor reaches approximately 75% of its rated speed.

Hope that helps!

7 0
2 years ago
When you hover over an edge or point, you are activating ____________ in SketchUp?
7nadin3 [17]

Answer:b

hope thiss helps

Explanation

I took the quiz

7 0
2 years ago
Read 2 more answers
Elements of parallel computing
Leya [2.2K]

\huge{\orange}\fcolorbox{purple}{cyan}{\bf{\underline{\green{\color{pink}Answer}}}}

<h3><u>E</u><u>lements of parallel </u><u>computing:</u></h3>

  • Computer systems organization.
  • Computing methodologies.
  • General and reference.
  • Networks.
  • Software and its engineering.
  • Theory of computation.

6 0
2 years ago
As the asteroid falls closer to the Earth's surface its _______ energy decreases and its _______ energy increases.
Levart [38]

Answer:

As the asteroid falls closer to the Earth's surface its <u>Gravitational</u> <u>Potential</u> energy <em>decreases</em> and its <u>Kinetic</u> energy <em>increases</em>.

4 0
3 years ago
Other questions:
  • Exceeding critical mach may result in the onset of compressibility effects such as:______.
    6·1 answer
  • When in a flow do the streamlines, streak lines and timelines coincide?
    14·1 answer
  • What was the purpose of the vasa ship
    11·1 answer
  • Module 42 Review and Assessment
    7·1 answer
  • ‘Politics and planning are increasingly gaining prominence in contemporary urban and regional planning debates’. Using relevant
    9·2 answers
  • According to the article, what is one reason why commercial carmakers aim to develop driverless technology?
    9·1 answer
  • A single-phase load is located 2800 ft from its source. The load draws a current of 86 A and operates on 480 V. The maximum volt
    10·1 answer
  • A hub a signal that refreshes the signal strength.
    5·1 answer
  • A red circle and diagonal slash on a sign means that:.
    10·1 answer
  • when discussing valve train components, technician a says stamped rocker arms are very strong and may be used in high-horsepower
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!