Я пытаюсь написать код, который будет сравнивать 10 фрагментов последовательности ДНК с ДНК последовательности 10 родственников. Пользователь вводит свое имя, количество родственников, которых они хотят сравнить, и их ДНК. Компьютер выводит процент соответствия. ATTAGACGCA по сравнению с ATAAGACGCA будет соответствовать 90%. Количество родственников является постоянным после того, как пользователь указывает, сколько родственников. Я попытался использовать const, но, похоже, он не хочет использовать этот номер.Использование переменной в качестве параметра массива в C++
/**********************************************************************
* Get DNA Sequence
***********************************************************************/
void getMyDNA(char myDNA[])
{
cout << "Enter your DNA sequence: ";
cin >> myDNA;
}
/**********************************************************************
* Get Potential Relatives
***********************************************************************/
int getRelatives()
{
int relatives = 0;
cout << "Enter the number of potential relatives: ";
cin >> relatives;
return relatives;
}
/**********************************************************************
* Get Potential Relatives Names
***********************************************************************/
void getRelativeName(string relativeNames[], int relatives)
{
string name;
for (int i = 0; i < relatives; i++)
{
cout << "Please enter the name of relative #" << i + 1 << ": ";
cin >> name;
relativeNames[i] = name;
}
}
/**********************************************************************
* Get Potential Relatives DNA Sequence
***********************************************************************/
void getRelativeDNA(char relativeDNA[][10], string relativeNames[], int relatives)
{
for (int i = 0; i < relatives; i++)
{
cout << "Please enter the DNA sequence for " << relativeNames[i] << ": ";
cin >> relativeDNA[i];
}
}
/**********************************************************************
* Display Potential Relatives Match
***********************************************************************/
void displayMatch(string relativeNames, char relativeDNA[][10], int relatives, char myDNA[])
{
const int family = relatives;
int count[family] = 0;
for (int r = 0; r < 3; r++) //relative number r
{
for (int d = 0; d < 10; d++) //dna piece number d
{
if (relativeDNA[r][d] == myDNA[d])
count[r]++;
}
}
}
/**********************************************************************
* Main
***********************************************************************/
int main()
{
char myDNA[10];
string relativeNames[50];
char relativeDNA[50][10];
// My DNA
getMyDNA(myDNA);
//# of relatives
int relatives = getRelatives();
cout << endl;
//thier names
getRelativeName(relativeNames,relatives);
cout << endl;
//their dna
getRelativeDNA(relativeDNA,relativeNames,relatives);
cout << endl;
//display
displayMatch(relativeNames,relativeDNA,relatives,myDNA);
return 0;
}
C++ не имеет [массивы переменной длины] (https://en.wikipedia.org/wiki/Variable-length_array), поэтому технически это недопустимо C++. Если вы хотите, чтобы массив переменной длины использовал ['std :: vector'] (http://en.cppreference.com/w/cpp/container/vector). –
Кроме того, что означает 'count'? Это массив или нет? –
Я обновил свой вопрос, чтобы включить весь мой код. Граф должен считать, сколько букв в последовательности ДНК между мной и моим родственником одинаково. –