Question

include<iostream> #include<cstring> using namespace std; char reg[30]; int main() {    //char reg[30];    char DNA[30];...

include<iostream>
#include<cstring>

using namespace std;
char reg[30];
int main()
{
   //char reg[30];
   char DNA[30];
   int flag = 0;
   int n, ni, i, j, k;

   cout << "Enter a regular expression" << ;
   cin >> reg;
   cout << endl;

   n = reg.size();
   for (int i = 0; i < n; i++)
   {
       strcpy(DNA, reg.substr(i, j));
       ni = DNA.lenghth();
       for (k = 0; k < ni; k++)
       {
           if (DNA[i] == 'A')
               flag = flag + 1;
       }
       if (flag >= 2)
           cout << DNA << endl;
   }
   return 0;
}

Please help my code won't work

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: If you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

Please note there were many syntax errors I have changed char array to string since substr works for string

#include<iostream>
#include<cstring>

using namespace std;
string reg;
int main()
{
//char reg[30];
int flag = 0;
int n, ni, i, j, k;

cout << "Enter a regular expression: ";
cin >> reg;
cout << endl;

n = reg.length();
for (int i = 0; i < n; i++)
{ string DNA;
string temp=reg.substr(i, j);
DNA=temp;
ni =DNA.length();
for (k = 0; k < ni; k++)
{
if (DNA[i] == 'A')
flag = flag + 1;
}
if (flag >= 2)
cout << DNA<<endl;
}
return 0;
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
include<iostream> #include<cstring> using namespace std; char reg[30]; int main() {    //char reg[30];    char DNA[30];...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • what is the output for the following code? explain the steps. /*#include <iostream> using namespace std;...

    what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int...

    #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...

  • #include <iostream> #include <stack> #include <queue> using namespace std; void printFromStack(string expr){ stack<char> myStack; for(int i=0;...

    #include <iostream> #include <stack> #include <queue> using namespace std; void printFromStack(string expr){ stack<char> myStack; for(int i=0; i<expr.length(); i++){ //Insert code here to push each character onto the stack } cout << "My stack is popped in this order" << endl; while(!myStack.empty()){ //Insert code here to cout the top of the stack one by one //Pop each one after it’s printed out } cout << endl; } void printFromQueue(string expr){ queue<char> myQueue; //Insert code here to push each character onto the...

  • Use C++ #include <iostream> #include <stdlib.h> #include <stdio.h> #include <cstring> using namespace std; /I Copy n...

    Use C++ #include <iostream> #include <stdlib.h> #include <stdio.h> #include <cstring> using namespace std; /I Copy n characters from the source to the destination. 3 void mystrncpy( ???) 25 26 27 28 29 11- 30 Find the first occurrance of char acter c within a string. 32 ??? mystrchr???) 34 35 36 37 38 39 / Find the last occurrance of character c within a string. 40 II 41 ??? mystrrchr ???) 42 43 45 int main() char userInput[ 81]; char...

  • #include <iostream> uisng  namespace std; int main() {             cout<<"Enter your three test scores and I...

    #include <iostream> uisng  namespace std; int main() {             cout<<"Enter your three test scores and I will ";                  <<" average them: ";             int score1, score2, score3,             cin>>score1>>score2>>score3;             double average;             average = (score1 + score2 + score3) / 3.0;             if (average = 100);                         perfectScore = true; // set the flag variable             cout<<"Your average is "<<average <<endl;             bool perfectScore;             if (perfectScore);             {                         cout<<"Congratulations!\n";                         cout<<"That's a perfect score.\n";                        ...

  • #include <iostream> using namespace std; int main() {    int i,n;    int counter=0;    cin...

    #include <iostream> using namespace std; int main() {    int i,n;    int counter=0;    cin >> n;    for (i = 1; i <= n; i++)    {        if (n % i == 0 )        {            counter++;        }        /*else        {            counter++;            i++;        }*/           }    if (counter == 2)        cout << n <<...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout...

    Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;

  • #include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be...

    #include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be implemented by you } int main() { cout << "To calculate x^y ..." << endl; double x; int y; cout << "Please enter x: "; cin >> x; cout << "Please enter y: "; cin >> y; if(x == 0) { if (y > 0) cout << 0 << endl; else cout << "x^y is not defined" <<endl; } else { cout << improvedPow(x,y)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT