Question

In: Computer Science

in C++, please show step by step with simple codes. thank you An application from Biology...

in C++, please show step by step with simple codes. thank you
An application from Biology
The only built-in function you can use is length.
1. As a starting point, write a piece of pseudocode for a function that finds a substring of a string. Your
function should take as input the string, the starting point of the desired substring, and the length of the desired substring. For example, substring(“abracadabra”, 3, 5) should return “acada”.

2. Turn your pseudocode from 1 into C++ code. Run your code with several outputs to be sure it’s right.

3. We may wish to look for occurrences of specific protein sequences (that correspond to certain traits) in a strand of DNA. For instance, if you were looking for the protein sequence "AATG" in the DNA strand "ATGCAGAAAGCTACGATCAATGATCGATC AATGGAT", you would find that it starts at index 18. Note that there is more than one match, but we’ve found the starting index of the first one.
Write a piece of pseudocode, using your function from 1 and 2, that finds the index of the start of the the first match of a given string protein within the string dna. In our example above, protein would be “AATG” and dna would be "ATGCAGAAAGCTACGATCAATGATCGATC AATGGAT".

4. Turn your pseudocode from 3 into C++ code. Run your code with several outputs to be sure it’s right.

Solutions

Expert Solution

Answer 1:

Pseudocode substring(string inStr, int start, int size)

1. len <- inStr.length()

2. j <- 0

3. for i <- start to start+size

i. result[j] = inStr[i]

ii. j++, i++

4. result[j] <- '\0'

5. return result

Answer 2:

Code:

Code as text:

#include <iostream>

#include <string>

using namespace std;

// function to find substring of a string

string substring(string inStr, int start, int size) {

int len = inStr.length();

string result(size, ' '); // variable for result

int j = 0;

// loop from start to string size to get substr

for (int i = start; i < start + size; i++) {

result[j] = inStr[i];

j++;

}

result[j] = '\0';

return result; // return the substr

}

int main() {

cout << "Testing substring function.\n";

cout << substring("abracadabra", 3, 5) << endl;

cout << substring("asdfghjkl", 2, 6) << endl;

cout << substring("ATGCAGAAAGCTACGATCAATGATCGATC", 6, 4) << endl;

}

Sample Run:

Answer 3:

Pseudocode for search(string inStr, string s)

1. for i <- 0 till i < inStr.length()

i. subStr <- substring(inStr, i, s.length())

ii. check if subString is equal to search string

a. return index i

iii. end if

2. end for

3. return -1 i.e string not found

Answer 4:

Code:

Code as text:

#include <iostream>

#include <string>

using namespace std;

// function to find substring of a string

string substring(string inStr, int start, int size) {

int len = inStr.length();

string result(size, ' '); // variable for result

int j = 0;

// loop from start to string size to get substr

for (int i = start; i < start + size; i++) {

result[j] = inStr[i];

j++;

}

result[j] = '\0';

return result; // return the substr

}

/* function to find index of the start of the the first match of a given string protein within the string dna */

int search(string inStr, string s) {

for (int i = 0; i < inStr.length(); i++) {

string subStr = substring(inStr, i, s.length()); // get substring

// check if substring is equal to given string

if (subStr == s) {

return i; // return index if found

}

}

return -1; // return -1 if not found

}

int main() {

cout << "Testing search string function.\n";

cout << "Finding AATG in ATGCAGAAAGCTACGATCAATGATCGATC AATGGAT. \n";

int index = search("ATGCAGAAAGCTACGATCAATGATCGATC AATGGAT", "AATG");

if (index) {

cout << "Found at index: " << index;

} else {

cout << "Not found.";

}

}

Sample Run:

P.s. Ask any doubts in comments and don't forget to rate the answer


Related Solutions

Please show work step by step, NO EXCEL. Thank you! The investment is $1,000,000, which is...
Please show work step by step, NO EXCEL. Thank you! The investment is $1,000,000, which is depreciated straight line to a zero salvage value over a 10 year life. The asset will be worthless in 10 years. The project will generate, annually, revenues of $800,000, cash operating expenses of $500,000, and depreciation of $100,000. The tax rate is 30%, and the cost of capital is 10%. a. what are the annual cash flow and the NPV? b. what would be...
Please do step by step clear and show eqations used. Thank you A rocket designed to...
Please do step by step clear and show eqations used. Thank you A rocket designed to place satellites into orbit is carried to a cruising altitude. When the plane is flying in a straight line and at a constant speed of 850 km/h, the rocket is dropped. After the drop the plane continues to fly at the same pseed and in a straight line. The rocket falls for a bried time, and then its propulsion starts. Once the propulsion starts...
Please show work step by step, and no Excel. Thank you! Fei Meng, Incorporated has a...
Please show work step by step, and no Excel. Thank you! Fei Meng, Incorporated has a project with the after-tax cash flows shown below. The required return (cost of capital) on the investment is 10%. Compute the:             Year 0 1 2 3 4 Cash flow -70,000 30,000 30,000 30,000 20,000 Payback Discounted payback NPV Profitability index IRR MIRR
Please show step by step. Thank you. Shallow square footing is resting on a dry cohesionless...
Please show step by step. Thank you. Shallow square footing is resting on a dry cohesionless soil. If the groundwater table moves from great depth to ground surface and axial load of the column moves from centroid to ex = B/3 how will affect bearing capacity (Df = 0). Assume unite weight of soil is 124.8 pcf.
Please show work step by step, no excel. Thank you! The three alternative projects shown below...
Please show work step by step, no excel. Thank you! The three alternative projects shown below have the expected cash flows that are given, and the cost of capital is 10%. Calculate the paybacks for all three projects. Rank the projects from best to worst based on their paybacks. Calculate the NPVs for all three projects. Rank the projects from best to worst based on their NPVs. Why are these two sets of rankings different? year 0 1 2 3...
Please show work step by step, No Excel. Thank you! Suppose miller motors can either expense...
Please show work step by step, No Excel. Thank you! Suppose miller motors can either expense or capitalize an asset it has just purchased for $9,000. if it capitalizes the asset, it will depreciate the asset to a book value of zero on a straight line basis of three years. The firm has a marginal tax rate of 38%, and the cost of capital for this asset is 12%. What is the present-value difference to the firm between expensing and...
please do it step by step with the use of formulas , thank you.. The following...
please do it step by step with the use of formulas , thank you.. The following are monthly percentage price changes for four market indexes. Month DJ SP500 1 0.03 0.02 2 0.07 0.06 3 −0.02 −0.01 4 0.01 0.03 5 0.05 0.04 6 −0.06 −0.04 Russ500 Nicky 0.04 0.04 0.10 −0.02 −0.04 0.07 0.03 0.02 0.11 0.02 −0.08 0.06 (17 points) Compute the following. a. Average monthly rate of return for each index b. Standard deviation for each index...
Please solve A, B, and C. Please use excel. Please show work. Thank you. A. Use...
Please solve A, B, and C. Please use excel. Please show work. Thank you. A. Use the stocks of Apple, SAP, IBM, Oracle, and Amazon Download the historical data of weekly stock prices and S&P 500 index prices from year 2017-2019 on the website of yahoo finance and save it on an excel file. B. Use a different sheet to save the market adjusted prices of Apple, SAP, IBM, Oracle, and Amazon t and the index. For each stock, compute...
Please show the each calculate step, thank you A company has identified the following budgeted overhead...
Please show the each calculate step, thank you A company has identified the following budgeted overhead costs and budgeted cost drivers for next year: Activity Budgeted Activity cost Cost Driver    Quantity Material Handling $120,000 Number of moves 3,000 Ordering costs 70,000 Number of orders 50,000 Maintenance 200,000 Machine hours 80,000 Power 310,000 Kilowatt hours 310,000 Total Activity Cost $700,000 The following job completed during the year: Job 400                                           Direct Materials $22,000 Direct labor $6,000 Units completed 4,000 Direct labor...
In C++, please. Thank you! Perhaps you remember the popular TV show, Deal or No Deal,...
In C++, please. Thank you! Perhaps you remember the popular TV show, Deal or No Deal, with Howie Mandel as the host, that ran several years ago. In honor of the show returning in its original form (and renewed for a fifth season in 2019!) this lab is called Stack or No Stack. As we studied in Chapter 1, imagine again a bag data structure into which we can insert and remove elements. This bag has two operations, defined as:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT