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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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