Question

i need help with a c++ program, it will be reading characters in from a file...

i need help with a c++ program, it will be reading characters in from a file using file stream

while the program is reading chartacter by charecter , it will identify what is it reading

so say a file contains this

x = 10; (This is one line)

y = 20;    (This is one line)                                                                                                                                                                                                                            

print x +y; (This is one line)                                                                                                                                                                                                                   

the outcome would be this

x is a word

10 is a number

y is a word

20 is a number

print is a word

x is a word

y is word   

i would like to see the correct outcomes just to see if the program actually runs

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

#include <string>

#include <fstream>

#include <sstream>

using namespace std;

int main()

{

string fileName = "file.txt";

string line;

fstream file;

file.open(fileName.c_str());

if(!file.good())

{

cout << "Problem with file!" << endl;

return 1;

}

while(!file.eof())

{

getline(file, line);

if(line.empty())

continue;

istringstream iss(line);

for(string word; iss >> word;)

if (isdigit(word[0]) != 0)

{

cout << word <<" is a number"<<endl;

}

else if(isalpha(word[0]) != 0)

{

cout << word <<" is a word"<< endl;

}

  

  

}

return 0;

}

Add a comment
Know the answer?
Add Answer to:
i need help with a c++ program, it will be reading characters in from a file...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program In Assembly For this part, your MAL program must be in a file named p5b.mal....

    Program In Assembly For this part, your MAL program must be in a file named p5b.mal. It must have at least one function in addition to the main program. For the purposes of Part (b), you may assume the following 1. Any line of text typed by a user has at most 80 characters including the newline character. 2. A whitespace character refers to a space, a tab or the new line character. 3. A word is any sequence of...

  • Hello! i need a program in C that uses FILE*! The instructions are below! Please dont...

    Hello! i need a program in C that uses FILE*! The instructions are below! Please dont copy paste another chegg post! Thank you! Will leave positive review! I need a program that 1) Count all words in a file. A word is any sequence of characters delimited by white space or the end of a sentence, whether or not it is an actual English word. 2)Count all syllables in each word. To make this simple, use the following rules: •Each...

  • Lab #10 C++ Write a C++ program that reads text from a file and encrypts the...

    Lab #10 C++ Write a C++ program that reads text from a file and encrypts the file by adding an encryption factor (EF) to the ASCII value of each character. The encryption factor is 1 for the first line and increases by 1 for each line up to 4 and then starts over at 1. So, for the 4 th line the EF is 4, for the 5th line it is 1, for the 10th line it is 2. In...

  • Write a C++ program that reads text from a file and encrypts the file by adding...

    Write a C++ program that reads text from a file and encrypts the file by adding 6 to the ASCII value of each character. See section 5.11 in Starting out with C++ for information on reading and writing to text files. Your program should: 1. Read the provided plain.txt file one line at a time. Because this file has spaces, use getline (see section 3.8). 2. Change each character of the string by adding 6 to it. 3. Write the...

  • C PROGRAM, A FOPEN FILE NEED TO BE CREATED Objective To review reading from a file....

    C PROGRAM, A FOPEN FILE NEED TO BE CREATED Objective To review reading from a file. To use records (an instance of a struct) To use Dynamic Memory Allocation To create and use a dynamically allocated array of structs To use enumerated types in a useful manner (more info given on Discussion board!) The Problem Bad economic times has forced the UCF administration to think outside the box for alternative methods of income. Specifically, we now have a UCF lottery,...

  • Programming in C. Name this program schwifty.c - This program reads a text file and makes...

    Programming in C. Name this program schwifty.c - This program reads a text file and makes it schwifty, but the user determines the schwiftiness. The user supplies the filename to schwift and a string containing a sequence of the following characters to determine the schwiftiness via command line arguments: L - Left shift each character in a word: hello --> elloh R - Right shift each character in a word: elloh --> hello I - Shift the letters' and digits'...

  • //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

    //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...

  • Creat a C Program that Reads words from a file called words, which contains one word...

    Creat a C Program that Reads words from a file called words, which contains one word per line.Each word has maximum length to M.The number of words in the file is equal to N. Incert each word to Binary Search Tree with node name dictionary.Each node of the tree must contain one word.The left child must contain a word that it is lexicographically smaller while the right child contains a lexicographically bigger one. 1) When you finish reading the file,...

  • C PROGRAM STRING AND FILE PROCESSING LEAVE COMMENTS! I WILL LEAVE POSITIVE REVIEW! THANK YOU :)...

    C PROGRAM STRING AND FILE PROCESSING LEAVE COMMENTS! I WILL LEAVE POSITIVE REVIEW! THANK YOU :) Use FILE I need a program that 1) Count all words in a file. A word is any sequence of characters delimited by white space or the end of a sentence, whether or not it is an actual English word. 2)Count all syllables in each word. To make this simple, use the following rules: •Each group of adjacent vowels (a, e, i, o, u,...

  • 12.13 (Count characters, words, and lines in a file) Write a program that will count the...

    12.13 (Count characters, words, and lines in a file) Write a program that will count the number of characters, words, and lines in a file. Words are separated by whitespace characters. The file name should be passed as a command-line argument, as shown in Figure 12.13 D Command Prompt exercise java Exercise12.13 Loan.java ile Loan.jaua has 1919 characters 10 words 71 lines lexercise Figure 12.13 The program displays the number of characters, words, and lines in the given file. This...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT