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
Are ocean currents always cold
swat32

Answer:

The surface ocean currents have a strong effect on Earth's climate. ... However, these areas do not constantly get warmer and warmer, because the ocean currents and winds transport the heat from the lower latitudes near the equator to higher latitudes near the poles.

8 0
3 years ago
How can any student outside apply for studying engineering at Cambridge University​
telo118 [61]
Admission to the Engineering course at Cambridge is highly competitive, both in terms of the numbers and quality of applicants. In considering applicants, Colleges look for evidence both of academic ability and of motivation towards Engineering. There are no absolute standards required of A Level achievement, but it should be noted that the average entrant to the Department has three A* grades. You need to get top marks in Maths and Physics.All Colleges strongly prefer applicants for Engineering to be taking a third subject that is relevant to Engineering.
Hope that helps and good luck if you are applying. Can you please mark this as brainliest and press the thank you button and if you have any further questions please let me know!!
3 0
2 years ago
A gas turbine receives a mixture having the following molar analysis: 10% CO2, 19% H2O, 71% N2 at 720 K, 0.35 MPa and a volumetr
Sliva [168]

Answer:

2074.2 KW

Explanation:

<u>Determine power developed at steady state </u>

First step : Determine mass flow rate  ( m )

m / Mmax = ( AV )₁ P₁ / RT₁   -------------------- ( 1 )

<em> where : ( AV )₁ = 8.2 kg/s,  P₁ = 0.35 * 10^6 N/m^2,   R = 8.314 N.M / kmol , </em>

<em>  T₁  = 720 K . </em>

insert values into equation 1

m  = 0.1871  kmol/s  ( mix )

Next : calculate power developed at steady state ( using ideal gas tables to get the h values of the gases )

W( power developed at steady state )

W = m [ Yco2 ( h1 - h2 )co2

Attached below is the remaining  part of the detailed solution

4 0
3 years ago
Which of these is the coarsest grit abrasive that may be used on aluminum?
natali 33 [55]

Answer:

80grit

Explanation:

80 grit is coarsest grit that may be used on aluminum

The lowest grit sizes range from 40 to 60. From the given options 80 grit is practically available grit.

What is a sandpaper used for?

They are essentially used for surface preparation. Sandpaper is produced in a range of grit sizes and is used to remove material from surfaces, either to make them smoother (for example, in painting and wood finishing), to remove a layer of material (such as old paint), or sometimes to make the surface rougher (for example, as a preparation for gluing).

5 0
3 years ago
Read 2 more answers
I'm so confused to this question <br>What is the difference between Science and Engineering? ​
muminat

Explanation:

Science is the body of knowledge that explores the physical and natural world. Engineering is the application of knowledge in order to design, build and maintain a product or a process that solves a problem and fulfills a need (i.e. a technology).

4 0
3 years ago
Read 2 more answers
Other questions:
  • Name two types of Transformers.
    6·1 answer
  • The in situ moisture content of a soil is 18% and the moist (total) unit weight is 105 pcf. The soil is to be excavated and tran
    9·1 answer
  • 37. In ______ combination of drugs, the effects of one drug cancel or diminish
    12·1 answer
  • Which type of load is not resisted by a pinned joint? A) Moment B) Shear C) Axial D) Compression
    7·1 answer
  • 16. Driverless cars have already , and they look so cool.
    10·2 answers
  • What was the most important thing you learned this school year in your engineering class and why did you choose this thing
    15·1 answer
  • 8. What is the purpose of the 300 Log?
    12·1 answer
  • A helicopter is hovering in a steady cross wind at a gross weight of 3,000 lb (1,360.8 kg). This helicopter has 275 hp (205 kW)
    10·1 answer
  • Many vehicles have indicator lights telling you when your
    13·1 answer
  • 2.<br> The most common way to identify size of pipe is by:
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!