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
the left rear brake drum is scored, but the right rear drum looks as good as new. technician a says the left-side drum should be
Romashka-Z-Leto [24]

Technician b is correct because the left rear brake drum is scored, but the right rear drum looks as good as new then both sides should be remachined to a similar diameter.

A brake drum is a revolving cylinder-shaped component that is friction-activated by a set of shoes or pads pressing outward against it. Drum brakes are brakes where shoes are pressed against the inner surface of the drum. Drum brakes are frequently used at the rear. Compared to disc brakes, these brakes have more parts and are more difficult to maintain, but they cost less to make and are simple to add an emergency braking mechanism. The front and rear brakes are standard equipment on all automobiles. Your car may have a "disc brake" system on all four wheels, a "drum brake" system on all four wheels, or a combination of the two. Typically, the front brakes of your car have a disc system, and the rear brakes have a drum system.

Learn more about brake drum here:

brainly.com/question/14937026

#SPJ4

7 0
1 year ago
A binary liquid system exhibits LLE at 25°C. Determine from each of the following sets of miscibility data estimates for paramet
Phoenix [80]

Answer:

(a) - A12 = A21 = 2.747

(b) - A12 = 2.148; A21 = 2.781

(c)-  A12 = 2.781; A21 = 2.148

Explanation:

(a) - x1(a) = 0.1 |  x2(a) = 0.9 | x1(b) = 0.9 | x2(b) = 0.1

LLE equations:

  • x1(a)*γ1(a) = x1(b)γ1(b)

        x2(a)*γ2(a) = x2(b)γ2(b)

  • A12 = A21 = 2.747

(b) -  x1(a) = 0.2 |  x2(a) = 0.8 | x1(b) = 0.9 | x2(b) = 0.1

LLE equations:

  • x1(a)*γ1(a) = x1(b)γ1(b)

        x2(a)*γ2(a) = x2(b)γ2(b)

  • A12 = 2.148; A21 = 2.781

(c) -  x1(a) = 0.1 |  x2(a) = 0.9 | x1(b) = 0.8 | x2(b) = 0.2

LLE equations:

  • x1(a)*γ1(a) = x1(b)γ1(b)

        x2(a)*γ2(a) = x2(b)γ2(b)

  • A12 = 2.781; A21 = 2.148
7 0
3 years ago
It describes the physical and social elements common to this work. Note that common contexts are listed toward the top, and less
QveST [7]

Answer:

BCDE

Explanation:

just look at the link, it tells you.

7 0
3 years ago
Read 2 more answers
How could the location of tests affect the performance of a catapult ?
Luba_88 [7]

Answer:

It could affect how far the projectile travels

Explanation:

Facing Uphill: Moves less far

Downhill: Moves further

3 0
3 years ago
Read 2 more answers
Saturated water vapor undergoes a throttling process from 1bar to a 0.35bar. What is the change in temperature for this process?
mamaluj [8]

Answer:

-25.63°C.

Explanation:

We know that throttling is a constant enthalpy process

      h_1=h_2

From steal table

We know that if we know only one property in side the dome then we will find the other property by using steam property table.

  Temperature at saturation pressure 1 bar is 99.63°C and  Temperature at saturation pressure 0.35 bar is about 74°C .

So from above we can say that change in temperature is -25.63°C.

But there is no any option for that .

4 0
3 years ago
Other questions:
  • Show from the first principles that, for a perfect gas with constant specific heat capacities
    14·1 answer
  • Given the following data, plot the stress-strain curves for the two unknown materials on the same set of stress-strain axes. Den
    9·1 answer
  • What is the capacity of the machine in batches?
    10·1 answer
  • What are the weight restrictions for a small UAS, including everything onboard at the time
    12·1 answer
  • When wasDisney Cruise Line founded
    5·1 answer
  • A 4-pole, 3-phase induction motor operates from a supply whose frequency is 60 Hz. calculate: 1- the speed at which the magnetic
    10·1 answer
  • Can someone help plz?!?
    5·2 answers
  • Determine the wattmeter reading when it is connected to resistor load.​
    11·1 answer
  • A tiger cub has a pattern of stripes on it for that is similar to that of his parents where are the instructions stored that pro
    8·1 answer
  • Which of following is not malicious ?<br> Worm<br> Trogan Horse<br> Driver<br> Virus
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!