Added instructions in a google doc: FOLLOW THE INSTRUCTIONS https://drive.google
ID: 3816170 • Letter: A
Question
Added instructions in a google doc: FOLLOW THE INSTRUCTIONS
https://drive.google.com/file/d/0B69alnxzYFLpV3pnX0lxMzBWZTA/view?usp=sharing
Need to write a C++ program:
Use only these libraries:
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
Added instructions in a google doc: FOLLOW THE INSTRUCTIONS
https://drive.google.com/file/d/0B69alnxzYFLpV3pnX0lxMzBWZTA/view?usp=sharing
Need to write a C++ program:
Use only these libraries:
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
Added instructions in a google doc: FOLLOW THE INSTRUCTIONS
https://drive.google.com/file/d/0B69alnxzYFLpV3pnX0lxMzBWZTA/view?usp=sharing
Need to write a C++ program:
Use only these libraries:
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
Explanation / Answer
#include <iostream>
using namespace std;
using std::cout;
using std::endl;
int main()
{
int k, length, startColumn, startRow, endColumn, endRow; bool found;
char c[5][5] = {{'M', 'n', 'a', 'b', 'c'},
{'s', 'n', 'o', 'w', 'y'},
{'n', 'o', 'n', ' c', 'd'},
{'x', 'r', 'x', 'c', 's'},
{'u', 'r', 'c', 'x', 'g'}};
int n;
for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { cout << c[i][j] << " "; }
cout << endl; }
cout << "Please select a word to search for; hit 1 for 'snow', 2 for 'lola', 3 for 'away', 4 for 'toys', or 5 for 'knot': " << endl;
cin >> n;
if (n == 1)
{
char word[5] = "snow"; found = false; k = 0; length = 4;
for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (c[i][j] == word[k]) { if (k == 0) {startColumn = j; startRow = i;}
else if (k == length - 1) { endColumn = j; endRow = i; found = true;} k++;} else k = 0; }
if (found) { break;} }
if (found) { cout << "The word " << word << " starts at (" << startColumn << ", " << startRow << ") and ends at (" <<
endColumn << ", " << endRow << ")" << endl; } system ("PAUSE");
}
else if (n == 2)
{
char word[5] = "lola"; found = false; k = 0; length = 4;
for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (c[i][j] == word[k]) { if (k == 0) {startColumn = j; startRow = i;}
else if (k == length - 1) { endColumn = j; endRow = i; found = true;} k++;} else k = 0; }
if (found) { break;} }
if (found) { cout << "The word " << word << " starts at (" << startColumn << ", " << startRow << ") and ends at (" <<
endColumn << ", " << endRow << ")" << endl; } system ("PAUSE");
}
else if (n == 3)
{
char word[5] = "away"; found = false; k = 0; length = 4;
for (int j=0; j<5; j++) { for (int i=0; i<5; i++) { if (c[i][j] == word[k]) { if (k == 0) {startColumn = j; startRow = i;}
else if (k == length - 1) { endColumn = j; endRow = i; found = true;} k++;} else k = 0; }
if (found) { break;} }
if (found) { cout << "The word " << word << " starts at (" << startColumn << ", " << startRow << ") and ends at (" <<
endColumn << ", " << endRow << ")" << endl; } system ("PAUSE");
}
else if (n == 4)
{
char word[5] = "toys"; found = false; k = 0; length = 4;
for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (c[i][j] == word[k]) { if (k == 0) {startColumn = j; startRow = i;}
else if (k == length - 1) { endColumn = j; endRow = i; found = true;} k++;} else k = 0; }
if (found) { break;} }
if (found) { cout << "The word " << word << " starts at (" << startColumn << ", " << startRow << ") and ends at (" <<
endColumn << ", " << endRow << ")" << endl; } system ("PAUSE");
}
else if (n == 5)
{
char word[5] = "knot"; found = false; k = 0; length = 4;
for (int j=0; j<5; j++) { for (int i=0; i<5; i++) { if (c[i][j] == word[k]) { if (k == 0) {startColumn = j; startRow = i;}
else if (k == length - 1) { endColumn = j; endRow = i; found = true;} k++;} else k = 0; }
if (found) { break;} }
if (found) { cout << "The word " << word << " starts at (" << startColumn << ", " << startRow << ") and ends at (" <<
endColumn << ", " << endRow << ")" << endl; }
system ("PAUSE");
}
return 0; system ("PAUSE");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.