Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is a C + + progaming lanuage I passed the first test case now I am stuck on the second testcase my program is
This is a C progaming lanuage I passed the first test case now I am stuck on the second testcase my program is noy funcitoning correctly coud someone help me out to fix my program? thank you second testcase ASCII Neighbors points Write a program that reads from standard input a sequence of whitespaceseparated 'words'. The program should output each word on its own line, but only including the characters that are equal or adjacent in the ASCII table. For example, the character has an ASCII value of and it should be included in the output only if it is next to an an i or a j In your solution, you must use a void function named FilterNeighbors, that takes in a string, and filters it based on the problem specification. Example Input: ahidkkrtsraaav Expected Output: hikktsraaa The first isn't in the output because its only neighbor is not adjacent to it in the ASCII table. The and the are adjacent in the table so they are outputted. The ks are equal to each other, so they are also outputted. And so on Example Input: gbsyfbjlbsadfoebw $$&aAJ :::: Expected Output: $$ Remember that there are lots of characters in ASCII beyond just letters. The "gbsyfbjlbsad foebw" word contains to letters that are adjacent in the word and in the table, so its line is empty. When writing your program, you may only use concepts you have learned in the course thus far. Your program should compile and run. The formatting must match exactly as shown in the example above, including whitespaces. gbsyfbjlbsadfoebw $$&aAJ ::k Expected Output: new line $$& My program output: $$& new line Mycode: #include #include #include #include #include using std::cout; using std::endl; using std::cin; using std::string; using std::vector; void FilterNeighborsstring &s string result; int n ssize; for int i ; i n; i if i && std::abssi si result si; else if i n && std::abssi si result si; s result; int main string line; vector inputlines; Read multiple lines of input while std::getlinecin line inputlines.pushbackline; for sizet i ; i inputlines.size; i string &line inputlinesi; vector words; string word; Split the line into words for char c : line if std::isspacec if word.empty words.pushbackword; word.clear; else word c; if word.empty words.pushbackword; Process each word with FilterNeighbors vector filteredwords; for string &word : words FilterNeighborsword; if word.empty filteredwords.pushbackword; Output the results for const string &filteredword : filteredwords cout filteredword endl; Add an extra new line at the end of the output for each input line, except the last one if i inputlines.size cout endl; return ;
This is a C progaming lanuage I passed the first test case now I am stuck on the second testcase my program is noy funcitoning correctly coud someone help me out to fix my program? thank you
second testcase ASCII Neighbors points
Write a program that reads from standard input a sequence of whitespaceseparated 'words'.
The program should output each word on its own line, but only including the characters that
are equal or adjacent in the ASCII table. For example, the character has an ASCII value of
and it should be included in the output only if it is next to an an i or a j
In your solution, you must use a void function named FilterNeighbors, that takes in
a string, and filters it based on the problem specification.
Example Input:
ahidkkrtsraaav
Expected Output:
hikktsraaa
The first isn't in the output because its only neighbor is not adjacent to it in the ASCII
table. The and the are adjacent in the table so they are outputted. The ks are equal to
each other, so they are also outputted. And so on
Example Input:
gbsyfbjlbsadfoebw $$&aAJ
::::
Expected Output:
$$
Remember that there are lots of characters in ASCII beyond just letters. The "gbsyfbjlbsad
foebw" word contains to letters that are adjacent in the word and in the table, so its line is
empty.
When writing your program, you may only use concepts you have learned in the course
thus far.
Your program should compile and run.
The formatting must match exactly as shown in the example above, including whitespaces.
gbsyfbjlbsadfoebw $$&aAJ
::k
Expected Output:
new line
$$&
My program output:
$$&
new line
Mycode:
#include
#include
#include
#include
#include
using std::cout;
using std::endl;
using std::cin;
using std::string;
using std::vector;
void FilterNeighborsstring &s
string result;
int n ssize;
for int i ; i n; i
if i && std::abssi si
result si;
else if i n && std::abssi si
result si;
s result;
int main
string line;
vector inputlines;
Read multiple lines of input
while std::getlinecin line
inputlines.pushbackline;
for sizet i ; i inputlines.size; i
string &line inputlinesi;
vector words;
string word;
Split the line into words
for char c : line
if std::isspacec
if word.empty
words.pushbackword;
word.clear;
else
word c;
if word.empty
words.pushbackword;
Process each word with FilterNeighbors
vector filteredwords;
for string &word : words
FilterNeighborsword;
if word.empty
filteredwords.pushbackword;
Output the results
for const string &filteredword : filteredwords
cout filteredword endl;
Add an extra new line at the end of the output for each input line, except the last one
if i inputlines.size
cout endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started