So my code is done it outputs exactly what it needs to I'm just wondering if it is possible to make this code a lot more simple using objects. If so could someone tell me what I would need member-wise and I will try and implement it. When I tried it got way too complex and it ended up looking easier to just write functions and a whole ton of for loops with if statements.
The purpose of the code is to analyze 2 inputs (base and template) and then see if the template matches any chunks on the base. Also called Gattaca, but A goes to T, C goes to G, and vice versa.
Here is my code:
#include <iostream>
#include <string>
using namespace std;
bool AT(char a, char b) {
return ((a == 'A' && b == 'T') || (b == 'A' && a == 'T'));
}
bool CG(char a, char b) {
return ((a == 'C' && b == 'G') || (b == 'C' && a == 'G'));
}
bool match(char a, char b) {
return (AT(a, b) || CG(a, b));
}
int main() {
int case_count = 0;
string base;
string temp;
int base_size;
int temp_size;
int count;
cin >> case_count;
for (int i = 0; i < case_count; ++i) {
cout << "Case " << i << ":\n";
bool check = false;
cin >> base;
cin >> temp;
base_size = base.size();
temp_size = temp.size();
if (base_size < temp_size) {
cout << "None";
continue;
}
if (base_size == temp_size) {
count = 0;
for (int index = 0; index < base_size; ++index) {
if (!(match(base[index], temp[index]))) {
cout << "None\n";
break;
}
else
count++;
}
if (count == temp_size) {
cout << "0\n";
}
continue;
}
for (int j = 0; j < base_size - (temp_size+1); ++j) {
count = 0;
for (int k = j; k < j + temp_size - 1; ++k) {
if (!(match(base[k], temp[count]))) {
break;
}
else
count++;
}
if (count == temp_size - 1) {
check = true;
cout << j << " ";
}
}
if (check == false) {
cout << "None \n";
}
else if (check == true) {
cout << "\n";
}
}
return 0;
}
I'm new to C++ programming so the best I can think is using a class to make this look simple. I'm not looking for a full written program just an idea/pseudo code or just the member functions I could use to make this simple.