DNA_C_string

DNA_C_string - cout<<"Seq 1 repaired is"<<...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <iomanip> #include <cstring> using namespace std; bool validate(char gene[]) ; bool validateAndRepair(char gene[]) ; int main() { char seq1[] = "TaCCgcT" ; char seq2[] = "GatCAcCxTG" ; if (! strcmp(seq1, seq2)) { cout << "The sequences are the same." << endl ; } else { cout << "The sequences are NOT the same." << endl ; } char seq3[50] = "" ; strcat(seq3,seq1) ; strcat(seq3,seq2) ; cout << "The concatenated sequence is: " << seq3 << endl ; bool isValid = false ; // Use of validate isValid = validate(seq1) ; cout << "Seq 1 is " << (isValid ? "valid" : "invalid") << "." << endl ; isValid = validate(seq2) ; cout << "Seq 2 is " << (isValid ? "valid" : "invalid") << "." << endl ; isValid = validate(seq3) ; cout << "Seq 3 is " << (isValid ? "valid" : "invalid") << "." << endl ; // Use of validateAndRepair isValid = validateAndRepair(seq1) ; cout << "Seq 1 is " << (isValid ? "valid" : "invalid") << "." << endl ;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout << "Seq 1, repaired, is " << seq1 << endl ; isValid = validateAndRepair(seq2) ; cout << "Seq 2 is " << (isValid ? "valid" : "invalid") << "." << endl ; cout << "Seq 2, repaired, is " << seq2 << endl ; isValid = validateAndRepair(seq3) ; cout << "Seq 3 is " << (isValid ? "valid" : "invalid") << "." << endl ; cout << "Seq 3, repaired, is " << seq3 << endl ; } bool validate(char gene) { int i = 0 ; bool valid = true ; while (gene[i] != '\0') { valid = valid && (gene[i] == 'A' || gene[i] == 'C' || gene[i] == 'G' || gene[i] == 'T' ) ; ++ i ; } return valid ; } bool validateAndRepair(char gene) { int i = 0 ; bool valid = true ; while (gene[i] != '\0') { if (gene[i] >= 97 && gene[i] <= 122) { gene[i] -= ('a' - 'A') ; } valid = valid && (gene[i] == 'A' || gene[i] == 'C' || gene[i] == 'G' || gene[i] == 'T' ) ; ++ i ; } return valid ; }...
View Full Document

This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

Page1 / 2

DNA_C_string - cout<<"Seq 1 repaired is"<<...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online