Modify Counter into a program that tells you only the number of lines that are a) shorter than ten characters and b) longer than twenty. Complete the following file: counter.cpp #include <iostream> #include <cctype> using namespace std; int main() { int charCount = 0; int lineCount = 0; char ch; while (cin.get(ch)) { if (ch == '\n') { lineCount++; } else { charCount++; } } cout << "Characters read: " << charCount << endl; cout << "Lines read: " << lineCount << endl; return 0; }
Added by Krista A.
Step 1
Initialize both variables to 0. ** Show more…
Show all steps
Your feedback will help us improve your experience
Derrick Danso and 51 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Integer numVals is read from input representing the number of integers to be read next. Use a loop to read the remaining integers from input. For each integer read in the loop, output "quantity >>" followed by the integer. End each output with a newline. Ex. If the input is: 3 70 95 80 Then the output is: quantity >> 70 quantity >> 95 quantity >> 80 #include <iostream> using namespace std; int main() { int numVals; int value; cin >> numVals; for (int i = 0; i < numVals; i++) { cin >> value; cout << "quantity >> " << value << endl; } return 0; }
Akash M.
Give a program that will create a file named text.txt and write ten sentences into the file, which are stored as one sentence per line. Provide a function that reads the file's contents and calculates the average number of words per sentence.
Liam H.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD