Question: How do you do the code for this lab code for cStrTools.cpp and cStrTools.h cStrTools.h #define _CRT_SECURE_NO_WARNINGS #ifndef CSTRTOOLS_H #define CSTRTOOLS_H namespace sdds { char

How do you do the code for this lab

code for cStrTools.cpp and cStrTools.h

cStrTools.h #define _CRT_SECURE_NO_WARNINGS

#ifndef CSTRTOOLS_H #define CSTRTOOLS_H namespace sdds { char toLower(char ch); void toLowerCaseAndCopy(char des[], const char source[]); void trim(char word[]); int isSpace(char ch); int isAlpha(char ch); const char* strStr(const char* str, const char* find); int strCmp(const char* s1, const char* s2); int strnCmp(const char* s1, const char* s2, int len); void strCpy(char* des, const char* src); int strLen(const char* str); void read(char* cString, unsigned int maxSize, char delimiter); } #endif

cStrTools.cpp

#define _CRT_SECURE_NO_WARNINGS #include #include #include #include "cStrTools.h"

using namespace std; namespace sdds { // returns the lower case value of a character char toLower(char ch) { if (ch >= 'A' && ch <= 'Z') ch += ('a' - 'A'); return ch; } // compares s1 and s2 cStrings and returns: // > 0 if s1 > s2 // < 0 if s1 < s3 // == 0 if s1 == s2 int strCmp(const char* s1, const char* s2) { int i; for (i = 0; s1[i] && s2[i] && s1[i] == s2[i]; i++); return s1[i] - s2[i]; } // compares s1 and s2 cStrings upto len characters and returns: // > 0 if s1 > s2 // < 0 if s1 < s3 // == 0 if s1 == s2 int strnCmp(const char* s1, const char* s2, int len) { int i = 0; while (i < len - 1 && s1[i] && s2[i] && s1[i] == s2[i]) { i++; } return s1[i] - s2[i]; } void read(char* cString, unsigned int maxSize, char delimiter) { char ch = 0; unsigned int i = 0; // skipping leading white space chars do { cin.get(ch); // reads one character from input } while (isSpace(ch)); // read char by char util hitting delimiter or maxSize for (i = 0; i < maxSize && ch != delimiter; i++) { cString[i] = ch; // read the cString stopping at the size limit if (i < maxSize - 1) cin.get(ch); } cString[i] = 0; // make sure the cString is null terminated } // copies src to des void strCpy(char* des, const char* src) { int i; for (i = 0; src[i]; i++) des[i] = src[i]; des[i] = 0; } // returns the length of str int strLen(const char* str) { int len; for (len = 0; str[len]; len++); return len; } // if "find" is found in "str" it will return the addres of the match // if not found it will returns nullptr (zero) const char* strStr(const char* str, const char* find) { const char* faddress = nullptr; int i, flen = strLen(find), slen = strLen(str); for (i = 0; i <= slen - flen && strnCmp(&str[i], find, flen); i++); if (i <= slen - flen) faddress = &str[i]; return faddress; } // returns true if ch is alphabetical int isAlpha(char ch) { return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'); } // returns true if ch is a whitespace character int isSpace(char ch) { return ch == ' ' || ch == '\t' || ch == ' ' || ch == '\v' || ch == '\f' || ch == ' '; } // removes the non-alphabetic characters from the begining and end of a word void trim(char word[]) { int i; while (word[0] && !isAlpha(word[0])) { strCpy(word, word + 1); } i = strLen(word); while (i && !isAlpha(word[i - 1])) { word[i-- - 1] = 0; } } // copies the lower case version of the source into des. void toLowerCaseAndCopy(char des[], const char source[]) { int i = 0, j = 0; for (; source[i] != 0; i++) { des[j++] = toLower(source[i]); } des[j] = 0; } }

A research lab requires an application to go through thousands of DNA samples and find all the matches to their sample.

A DNA strand representation is done through combinations of the characters 'a', 'c', 'g' and 't' with no spaces in between. These combinations are kept as a cString of characters in a comma-separated file with a 6 digit integer id attached to each sample as follows:

243245,acccgttcgattcagtcgatcgatcgggatattgcaaa 

Each DNA strand is between 100 to 1000 characters.

The number of DNA strands in the data file could be millions. This amount is different in each data file.

Your responsibility is to write a library of functions in a module called "DNA" that can support the main program provided to have the following execution outcome:

The ids in the file are not sorted. Your search results must be sorted based on the Ids of the DNA strands in ascending order:

Enter DNA data file name: lowBaseDnaSmall.csv DNA search program Enter a DNA squence (max 100 chars) > gtcc 4 matches found: 1) 444136: atattttccactgaacggtccagatcgacgatcggggtgtaacagttcatctttggtataccctctccggcgttagatatggtcgaaacgggaacggctag ====================================================================== 2) 448885: ctgatgcagatggattgcgataacggagcgcaatgtgcaatacgggccttcgggaaacggctcgtccgtttcccgaacgcggaacgcaaagaacatgaca ====================================================================== 3) 469926: cggaccacggcccccgtcccccgcatgttcgacgagtggatagagttgagatccatccctttcctagcgtcattgttgcgatacgattgtagtgagcagct ====================================================================== 4) 489349: ccccttttaccaaatcgaagcttttgtgcgaatgtggtcttattgtacgtccgtctcacaggtgactcacactgtccgctctactgagaagcctcctatgc ====================================================================== Enter a DNA squence (max 100 chars) > gtacct No match found! Enter a DNA squence (max 100 chars) > ! DNA Search Program Closed. 

Tester Program

/* ------------------------------------------------------ Workshop 2 part 2 Module: N/A Filename: main.cpp Version 1 Author Fardad Soleimanloo Revision History ----------------------------------------------------------- Date Reason -----------------------------------------------------------*/ #include  #include "cStrTools.h" #include "DNA.h" using namespace std; using namespace sdds; int main() { bool done = false; char dna[101]; char filename[256]; cout << "Enter DNA data file name: "; cin >> filename; if (beginSearch(filename)) { while (!done) { cout << "Enter a DNA squence (max 100 chars)" << endl << "> "; read(dna, 100); if (strCmp(dna, "!") == 0) { done = true; } else { if (read(dna)) { sort(); displayMatches(); deallocate(); } else { cout << "No match found!" << endl; } } } endSearch(); } return 0; }

Mandatory Functions

bool beginSearch(const char *filename);

It will try to open the file and initialize any requirements needed for the application. Returns true if the file is opened successfully and returns false it fails to open the file.

bool read(const char* subDNA);

Dynamically creates an array of DNA records to the number of matches found in the file and stores the matches in them. Returns true if at least one match is found and false if no match is found in the records.

void sort()

Sorts the dynamic array of DNA matches found in the file based on the ids in ascending order.

void displayMatches()

Displays the dynamic DNA records in the following format.

row) ID: DNA strand ====================================================================== 

void deallocate()

Deallocates all the dynamic memory within the DNA array elements and the DNA array itself.

void endSearch()

Finalizes the program by releasing the resources allocated by the program (like closing the data file and etc...).

And then Prints:

DNA Search Program Closed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!