Question

. . In this programming assignment, you need to write a CH+ program that serves as a very basic word processor. The program s
Page of 5 6. Paragraphs are written in the output separated by the specified line spacing plus one. Several consecutive empty
3456 george 10.25 1234 smith 4.5 4321 staci 10.25 278 staci 10.25 The maximum allowed number of words is 50. The read file co
3456 george 1234 smith 10.25 4.5 4321 staci 10.25 278888888888888 22222222 8888888 staci 10.25 Case 3: Output of myfile2.txt
0 0
Add a comment Improve this question Transcribed image text
Answer #1

output.txt - Notepad File Edit Format View Help | 3456 george 10.25 1234 smith 4.5 4321 staci 10.25 278 staci 10.25 The maximoutput.txt - Notepad File Edit Format View Help 3456 george 10.25 1234 smith 4.5 4321 staci 10.25 278 The maximum allocated noutput.txt - Notepad File Edit Format View Help george 10.25 1234 smith 4.5 4321 staci 10.252222222222222222222 2788888888888
#include <iostream>
#include<string.h>
#include <regex>
#include<fstream>
#include <sstream>
using namespace std;

int StrToInt (string str)
{
string substr=str.substr(4);
stringstream convert(substr);   
int x = 0;
convert >> x;
return x;
}
string insert(string output,int num,string splchar)
{

string result=output;
for(int i=0;i<num;i++)
result+=splchar;

return result;
}

int main(int argc, char *argv[])
{
int t=20,m=50,n=5,s=1;
int i=1,readcount=0;
int flag=0,filenamepresent=0,truncflag=0;
string filename;
while(i<argc)
{

if((regex_match (argv[i],regex("^(?!_).*")))&&(!regex_match (argv[i],regex("-.+"))))
{
filename=argv[i];

flag=1;
filenamepresent=1;
}
if(regex_match (argv[i],regex("-WC=[0-9]+")))
{
m=StrToInt(argv[i]);
cout<<"m:"<<m<<endl;
flag=1;
}
if(regex_match (argv[i],regex("-LL=[0-9]+")))
{
t=StrToInt(argv[i]);
cout<<"t:"<<t<<endl;
flag=1;
}
if(regex_match (argv[i],regex("-IN=[0-9]+")))
{
n=StrToInt(argv[i]);
cout<<"n:"<<n<<endl;
flag=1;
}
if(regex_match (argv[i],regex("-SP=[0-9]+")))
{
s=StrToInt(argv[i]);
cout<<"s:"<<s<<endl;
flag=1;
}
if(flag)
{
flag=0;
}
else
{
cout<<"Error\n";
}
i++;
}
if(filenamepresent==1)
{
ifstream file;
file.open (filename);
if (!file.is_open())
{
cout<<"File can't be opened\n";
}
else
{
string word;
string *words=new string[m];
for(int i=0;i<m;i++)
{  
   words[i]="";
}
i=0;
while (file >> word)
{
readcount=readcount+1;
if(i<m)
{
words[i]=word;
i=i+1;
}
else
{

truncflag=1;
}
}

file.close();
file.open (filename);
int para_insert=0;
string line;
while (getline(file, line)) {

if(line.empty())
{
while(line.empty())
getline(file, line);
istringstream iss(line);
string first_word;
if(iss>>first_word)
{
  
for(int l=0;l<m;l++)
{
   if(words[l].compare(first_word)==0)
{
   words[l]=insert("",n," ")+words[l];  

   }

  
}
}
  
}
}
file.close();
ofstream outputfile;
outputfile.open ("output.txt");
string output="";

output=insert(output,n," ");//Space indent "\t " could be used for tab indent
  
i=0;

while(i<m)
{
string temp=words[i]+" ";
int j=temp.length();
while(j+words[i+1].length()<t)
{
temp=temp+words[i+1]+" ";
j=temp.length();

i++;
}

output+=temp;
output=insert(output,s,"\n");

i++;
  
}

outputfile<<output;
outputfile<<"\nThe maximum allocated number is "<<m<<"\n";
if(truncflag==1)
outputfile<<"Readfile contained words exceeding maximum hence truncated\n";
else
outputfile<<"Words from readfile is "<<readcount<<"\n";
outputfile.close();
}
}
else{
cout<<"File name not specified\n";
}

}

Add a comment
Know the answer?
Add Answer to:
. . In this programming assignment, you need to write a CH+ program that serves as...
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
  • In c programming, I need to write a program that reverses each of the lines in...

    In c programming, I need to write a program that reverses each of the lines in a file. The program accepts two command line arguments: The first one is the name of the input file The second is the name of the output file If the user didn't give two filenames, display an error message and exit. The program reads in each line of the input file and writes each line in reverse to the output file. Note, the lines...

  • 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...

  • Write a program in java that asks a user for a file name and prints the...

    Write a program in java that asks a user for a file name and prints the number of characters, words (separated by whitespace), and lines in that file. Then, it replaces each line of the file with its reverse. For example, if the file contains the following lines (Test1.txt): This is a test Hi there Output on the console: Number of characters: 22 Number of words: 6 Number of lines: 2 Data written to the file (Test1.txt): tset a si...

  • //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...

  • Please help with this python assignment. Thank you. question 1 Write a Python program to read...

    Please help with this python assignment. Thank you. question 1 Write a Python program to read a file line by line store it into a variable. question 2 Write a Python program to read a file line by line store it into an array. question 3 Write a python program to find the longest words. question 4 Write a Python program to count the number of lines in a text file. question 5 Write a Python program to count the...

  • For this lab, you can assume that no string entered by the user will be longer...

    For this lab, you can assume that no string entered by the user will be longer than 128 characters. You can also assume that the database file does not contain more than 128 lines. However, you can not assume that the database has the correct format. There are three commands your program must handle. If any other command is entered, the program should reply Unrecognized command. and then present the prompt again. The three commands are: quit - The program...

  • Need help with java programming. Here is what I need to do: Write a Java program...

    Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1.     The input and variable value file are both text files that will be specified in...

  • Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a...

    Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a main function and three other functions called. readmarks , changemarks (, and writemarks() The program begins by calling the function readmarks () to read the input file marksin. txt which consists of a series of lines containing a student ID number (an integer) and a numeric mark (a float). Once the ID numbers and marks have been read into arrays (by readmarks () the...

  • Write a program file_max.c that reads a set of integer numbers from a file and prints...

    Write a program file_max.c that reads a set of integer numbers from a file and prints out the maximum number to standard output. The name of the input file should be specified as a command line argument.

  • I need help with a java program Write a program Enigma that takes a single String...

    I need help with a java program Write a program Enigma that takes a single String as a command line argument. Enigma should read the file specified by the String argument, add 5 to each byte, and leave the altered data values in a file whose name is the command line argument. Note that this "updating in place" is the most difficult part of this lab: java Enigma sophie.dat should read file sophie.dat, and upon completion, leave the modified data...

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
ADVERTISEMENT