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
You have designed a treatment system for contaminant Z. The treatment system consists of a pipe that feeds into a CSTR. The pipe
IRISSAK [1]

Answer:

0.667 per day.

Explanation:

Our values here are

Q=10m^3/dV_p=15m^3\\V_{cstr}=60m^3\\c_p=2500mg/L\\c_{cstr}=500mg/L

Degradation constant=k and is unknown.

We calculate the concentration through the formula,

cc_{cstr} =\frac{c_{in}}{1+K(V/Q)} \\cc_{cstr}=\frac{c_p}{1+K*\frac{V_{csrt}}{Q}}

Replacing values we have

1+k(\frac{60}{10})=\frac{2500}{500}\\1+k=5\\K(6)=5-1\\K(6)=4\\K=2/3\\K=0.667/day

That is the degradation constant of Z-contaminant

3 0
3 years ago
What is an Algorithm? *
barxatty [35]

Answer:

a

Explanation:

4 0
4 years ago
An add tape of 101 ft is incorrectly recorded as 100 ft for a 200-ft distance. What is
baherus [9]

Answer:

the correct distance is 202 ft

Explanation:

The computation of the correct distance is shown below:

But before that correction to be applied should be determined

= (101 ft - 100 ft) ÷ (100 ft) × 200 ft

= 2 ft

Now the correct distance is

= 200 ft +  2 ft

= 202 ft

Hence, the correct distance is 202 ft

The same would be relevant and considered too

4 0
3 years ago
A concrete mix design calls for 6.5 sacks of cement, a water/cement ratio of 0.45, and an air content of 2.5%. 1. Complete the m
RUDIKE [14]

Answer:

28.6 kg

Explanation:

The final weight can be calculated from the mixing data and formulae which is given as follows:

cement content = \frac{water content}{water - cement ratio}

Computing the parameters and checking the tables gives 28.6 kg.

7 0
3 years ago
Read 2 more answers
A number 12 copper wire has a diameter of 2.053 mm. Calculate the resistance of a 37.0 m long piece of such wire.
Alinara [238K]

Answer:

R=1923Ω

Explanation:

Resistivity(R) of copper wire at 20 degrees Celsius is 1.72x10^-8Ωm.

Coil length(L) of the wire=37.0m

Cross-sectional area of the conductor or wire (A) = πr^2

A= π * (2.053/1000)/2=3.31*10^-6

To calculate for the resistance (R):

R=ρ*L/A

R=(1.72*10^8)*(37.0)/(3.31*10^-6)

R=1922.65Ω

Approximately, R=1923Ω

5 0
3 years ago
Other questions:
  • A PV battery system has an end-to-end efficiency of 77%. The system is used to run an all-AC load that is run only at night. The
    11·1 answer
  • What is something that a robot or computer program might do that requires a decision, or conditional statement?
    9·1 answer
  • Draw an ERD for each of the following situations. (If you believe that you need to make additional assumptions, clearly state th
    15·1 answer
  • What is kirchoff's current law?​
    10·2 answers
  • The minimum fresh air requirement of a residential building is specified to be 0.35 air changes per hour (ASHRAE, Standard 62, 1
    10·1 answer
  • Which option identifies the step of the implementation phase represented in the following scenario?
    9·2 answers
  • A fan draws air from the atmosphere through a 0.30-mdiameter round duct that has a smoothly rounded entrance. A differential man
    14·1 answer
  • Marie and James are bubbling dry pure nitrogen (N2) through a tank of liquid water (H2O) containing ethane (C2H6). The vapor str
    5·1 answer
  • What were some of the challenges to safety resulting from such radical airframe designs as highly swept wings, high wing loading
    15·1 answer
  • In a typical American building, most modern lighting systems must use what voltage?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!