C++
What does this filter do?
char ch;
while (can.get(ch))
{
if (ispunct(ch)) continue;
count.put(ch);
}
a. prints only punctuation characters in input
b. endless loop if input contains punctuation: otherwise prints all input
c. prints all non-punctuation characters in input
d. prints all characters before first punctuation character
e. endless loop when first punctuation character encountered
Answer: C (prints all non-punctuation characters in input)
Explanation: So below code first take user input using cin.get in ch variable. ispunct function checks for input character and returns 1 if it is a punctuation character and 0 if it is not so. When you enter any punctuation character, it will simply continue the loop to get next character otherwise it put the character on console using cout.put.
#include <iostream>
using namespace std;
int main()
{
char ch;
//it will be a loop to get character
while (cin.get(ch))
{
//if it is a punctuation character then continu to get next character
if (ispunct(ch)) continue;
//if not a punctuation then print it
cout.put(ch);
}
}
Get Answers For Free
Most questions answered within 1 hours.