Write a program where the number of characters is counted

Assignment Help Computer Engineering
Reference no: EM131986057

Problem

Write a C++ program where the number of characters in each word of a text file is counted. I'm having trouble defining in my loop exactly when a word begins and ends (using characters). How can I reword this loop so that it recognizes a word and adds the number of characters in it to the variable called "word?" Here's what I have so far:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
ifstream fin("file.txt");
int word=0;
char ch;
while(fin && ch!= '.'){
if(ch==' ' || ch=='\n')
word++;

//It is wrong because the end of text may have large portions of blank spaces which, by this loop, would be counted as chars in a word.

Reference no: EM131986057

Questions Cloud

Write a program for user registration : Write a program for user registration: First the program tells the user "enter 1 to register, enter 2 to sign in, enter 3 to quit.
Principles of respect for autonomy : Major principles of health care ethics include the principles of respect for autonomy, nonmaleficence, beneficence, and justice.
Industries bonds have six years left to maturity : Harrimon Industries bonds have 6 years left to maturity. What is the yield to maturity at a current market price of
Patient protection and affordable care act : Discuss the influence that the Patient Protection and Affordable Care Act has had to date. What changes would you recommend as the tweaking of this law continue
Write a program where the number of characters is counted : Write a C++ program where the number of characters in each word of a text file is counted. I'm having trouble defining in my loop exactly when a word begins.
Compute realized rate of return for investor : Compute the realized rate of return for an investor who purchased the bonds when they were issued and held them until they were called.
Hydrogen exchangers on the luminal membrane : Aldosterone increases sodium reabsorption in the collecting duct by increasing expression of EnaCs, sodium/potassium exchangers
Describe how users of the financial statements may benefit : Describe how users of the financial statements may benefit from communications about these matters in an audit report
Estimated market return and risk-free rate : Spartan Machinery stock trades at $60 per share with a beta of 1.5, an estimated market return of 12%, and a risk-free rate of 5%.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Determines shipping charges based on the number of items

Write a program that a large Internet merchandise provider determines its shipping charges based on the number of items purchased.

  How to find the "smallest" and "largest" in a series of word

Write a program that finds the "Smallest" and "Largest" in a sequence of words. After user enter the words, the program will determine which words would come first and last if the words were listed in dictionary order.

  Use the branch-on-equal mips assembly instruction

Explain how to convert the address(hex) to words(bits) ? Is there any shortcut to do this type of conversion?

  Where can someone obtain programming tools

Where can someone obtain programming tools? Identify at least two of these tools, giving a brief description of each.

  Give description of the network design plan

For the equipment price list, make up price list based on fair market value for each peice of equipment. Do the same for the labor costs.

  How can you define task types in ada

How can you define task types in Ada? What are the main differences between protected types and task types?

  Analyze why getty image embraced agile methodologies

Analyze why Getty Image embraced Agile methodologies. Speculate on the result if Agile methodologies were not embraced in this situation.

  Who is protected by hippa and who must comply with hippa

Who is protected by HIPPA? Who must comply with HIPPA? What is the relevance of health care plans, providers and clearinghouses?

  Monitoring of patient vital signs using mobile computing

Compare and contrast the monitoring of patient vital signs utilizing the mobile computing technology to in-patient visits to the doctor’s office or hospital.

  Write pseudocode using modularization

The Census Bureau has collected data about all of its employees. You will be given a data file which contains the GS number ( rating) for each employee, one per input record. A number of 1000 signifies the end of the data file.

  How do you change the home page 9how do you delete the web

1.what is a peer tp peer network? what is a client server network?2.what is the difference between an internet and an

  Determine a good asymptotic upper bound

Determine a good asymptotic upper bound on the recurrence - write a comment between each pair of lines describing what is true when the program reaches that point in the code.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd