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
جائت فكرة ربط الحواسيب لغرض نقل البيانات و مشاركتها و بعدها بفتره قصيره جائت إمكانية مشاركة الموارد بين الحواسيب صح ام خطأ​
melamori03 [73]

Answer:

بدلاً من ذلك يُشار إليه باسم مشاركة أو مشاركة شبكة ، الدليل المشترك هو دليل أو مجلد يمكن الوصول إليه من قبل العديد من المستخدمين على الشبكة. هذه هي الطريقة الأكثر شيوعًا للوصول إلى المعلومات ومشاركتها على شبكة محلية

Explanation:

5 0
2 years ago
Read 2 more answers
State the number of terms for each of the following algebraic expression 2x+1
harina [27]

Answer:

Expressions are made up of terms.

A term is a product of factors.

Coefficient is the numerical factor in the term

Before moving to terms like monomials, binomials, and polynomials, like and unlike terms are discussed.

When terms have the same algebraic factors, they are like terms.

When terms have different algebraic factors, they are unlike terms.

Explanation:

Hi please follow me also if you can and thanks.

6 0
3 years ago
What should you, the worker, be aware of with regard to evacuation procedures at your workplace
Alinara [238K]

Answer:

As a worker, it is important to follow the proper set of instructions or emergency plans during an emergent situation. Not carefully following the rules may result to a bigger problem such as further injury and damage to property.

Explanation:

Evacuation Procedure- This is a step-by-step procedure that people follow in order to safely vacate any building or place. This procedure is applicable to any situation, such as the workplace. This is now called the <em>Workplace Evacuation Procedure. </em>This is very important because there are so many unpredictable situations or events that are happening in the world right now, such as fire or earthquake. This procedure is being done through an evacuation plan.

The awareness of the workers regarding the proper way to evacuate during emergency situation is very important. It will be easier for them to know where to locate the nearest exit route. They will also learn to stop any form of device or equipment that could cause a hazzard during the situation. In case of the hospital, which is also a workplace, the employees will also learn how to assist the patients before themselves. They will also know where to assemble if there's a need to do so.

7 0
3 years ago
Read 2 more answers
What colour is best for radiative heat transfer? a. Black b. Brown c. Blue d. White
GarryVolchara [31]

Answer:

The correct answer is option 'a': Black

Explanation:

As we know that for an object which is black in color it absorbs all the electromagnetic radiation's that are incident on it. Thus if we need to transfer energy to an object by radiation the most suitable color for the process  is black.

In contrast to black color white color is an excellent reflector, reflecting all the incident radiation that may be incident on it hence is the least suitable material for radiative heat transfer.

8 0
3 years ago
Use Routh's stability criterion to determine how many roots with positive real parts the following equations have:
Pavlova-9 [17]

Answer:

a) no roots not in LHP

b) 2 roots not in LHP

c) 2 roots not in the LHP

d) 2 roots not in the LHP

e) 2 roots not in LHP

Explanation:

a) s^4 + 8s^3 + 32s^2 + 80s + 100 = 0\\\\s^4:\:\:\:1\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:32\:\:\:\:\:\:100\\s^3:\:\:\:8\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:80\\s^2:\:\:\:22\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:100\\s^1:\:\:\:80-\frac{800}{22} =43.6\\s^0:\:\:\:100

No roots not in the LHP

b) s^5 + 10s^4 + 30s^3 + 80s^2+344s + 480 =0 \\\\s^5:\:\:\:1\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:30\:\:\:\:\:\:344\\s^4:\:\:\:10\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:80\:\:\:\:\:\:480\\s^3:\:\:\:22\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:296\\s^2:\:\:\:-545\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:480\\s^1:\:\:\:490\\s^0:\:\:\:480

2 roots not in the LHP

c) s^4 + 2s^3 + 7s^2 -2s + 8 = 0 \\\\s^4:\:\:\:1\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:7\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:8\\s^3:\:\:\:2\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:-2\\s^2:\:\:\:8\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:8\\s^1:\:\:\:-4\\s^0:\:\:\:8

There are roots in the RHP (not all coefficients are greater than 0).

2 roots not in the LHP

d) s^4 + 2s^3 + 7s^2 -2s + 8 = 0 \\\\s^3:\:\:\:1\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:20\\s^2:\:\:\:1\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:78\\s^1:\:\:\:-58\\s^0:\:\:\:78

There are two sign changes in the first column of the Routh array.

2 roots not in the LHP

e) s^4 + 2s^3 + 7s^2 -2s + 8 = 0 \\\\s^4:\:\:\:1\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:6\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:25\\s^3:\:\:\:4\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:12\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\: new \:\:row \\s^2:\:\:\:3\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:25\\s^1:\:\:\:12-\frac{100}{3}=-21.3 \\s^0:\:\:\:25

2 roots not in LHP

check:

 a (s) = 0  ⇒

 s^2 = -3 \limits^+_- 4j = 5e^{j(\pi \limits^+_- 0.92)}\\\\s = \sqrt5 e^{j( \frac{\pi}{2} \limits^+_-  0.46)+n\pi j},\:\:\:\:\: n= 0, 1\\

3 0
3 years ago
Other questions:
  • You want to determine whether the race of the defendant has an impact on jury verdicts. You assign participants to watch a trial
    9·1 answer
  • Select the correct answer.
    12·2 answers
  • The lift on a spinning circular cylinder in a freestream with a velocity of 30 m/s and at standard sea level conditions is 6 N/m
    7·1 answer
  • Plot the following trig functions using subplots, choosing an appropriate layout for the number of functions displayed. The subp
    8·1 answer
  • A_____ transducer is a device that can convert an electronic controller output signal into a standard pneumatic output. A. pneum
    13·1 answer
  • A frequenter of a pub had observed that the new barman poured in average 0.47 liters of beer into the glass with a standard devi
    14·1 answer
  • All of these are uses of microwaves except...
    15·1 answer
  • Ages have been identified by the materials developed and used in those eras.
    8·2 answers
  • What happens to the electrolyte, during discharging?
    9·1 answer
  • ____ grinders are used to grind diameters, shoulders, and faces much like the lathe is used for turning, facing, and boring oper
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!