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
What is the following passage saying about the relationship between sustainability and responsibility?
7nadin3 [17]

What the given passage is saying about the relationship between sustainability and responsibility is that;

C: We should only consider products or services to be green if their broad impact can be considered so.

<h3>Sustainability</h3>

From the passage, we see a write up questioning if the things we term to be green are truly green.

Now, from the passage, we see that a biofuel that is considered to be green is not really green if we consider that if it requires massive overproduction, it could wreck the water table.

Also, he says that if the production is local but also wasteful then it is not green.

Thus, we can see clearly that before we term a product or service as green, we should also consider their broad impact on the environment.

Read more about sustainability at; brainly.com/question/14154063

7 0
2 years ago
What are the inputs, outputs and side effects of a PSP?
Kipish [7]

Answer:

Side effects - sudden loss of balance/ repeated falls

Outputs - sever sickness and could me factual

Inputs/corrections of this- medications and experimental treatments to help slow the process of deterioration

5 0
3 years ago
Ultimate tensile strength is: (a) The stress at 0.2% strain (b) The stress at the onset of plastic deformation (c) The stress at
MissTica

Answer:

By definition the ultimate tensile strength is the maximum stress in the stress-strain deformation. The stress at 0.2% strain, the stress at the onset of plastic deformation, the stress at the end of the elastic deformation and the stress at the fracture correspond, by definition, to other points of the stress-strain curve.

Explanation:

4 0
3 years ago
Dampers dampers springs are used inside some valve spring to
harkovskaia [24]
The correct answer is A. Retain. Valve Stem seals
3 0
3 years ago
Engineering controls are the physical changes that employers make to the work environment or to equipment that make it safer to
____ [38]

Answer:

Engineering Controls. The best engineering controls to prevent heat-related illness is to make the work environment cooler and to reduce manual workload with mechanization. A variety of engineering controls can reduce workers' exposure to heat: Air conditioning, Increased general ventilation , Cooling fans , Local exhaust ventilation at points of high heat production or moisture, Reflective shields to redirect radiant heat , Insulation of hot surfaces Elimination of steam leaks , Cooled seats or benches for rest breaks , Use of mechanical equipment to reduce manual work, Misting fans that produce a spray of fine water droplets.

Hope this helped you!

Explanation:

5 0
3 years ago
Other questions:
  • A commercial refrigerator with refrigerant -134a as the working fluid is used to keep the refrigerated space at -30C by rejectin
    10·3 answers
  • : The interior wall of a furnace is maintained at a temperature of 900 0C. The wall is 60 cm thick, 1 m wide, 1.5 m broad of mat
    12·1 answer
  • How an AK 47 gun was works​
    14·1 answer
  • 100 points Im so bored lol
    11·2 answers
  • 8. Explain how a duo-servo brake assembly works to provide great braking ability.
    11·1 answer
  • Water (cp = 4180 J/kg·°C) enters the 2.5 cm internal diameter tube of a double-pipe counter-flow heat exchanger at 17°C at a rat
    7·1 answer
  • a. To measure the water current in an ocean, a marker is dropped onto it. Determine if the trajectory traced by the drifting mar
    5·1 answer
  • What is the maximal coefficient of performance of a refrigerator which cools down 10 kg of water (and then ice) to -6C. Upper he
    11·1 answer
  • Three possible career opportunities in embedded systems engineering
    11·1 answer
  • What engine does the Mercedes 400e have?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!