Implement a program in C++ that does the following:
Reads the each of the words in a given input file (stackInput.txt)
Stores each of those words on to a Stack
After finishing the storage of all the data from the input file on to the stack, retrieve each of the
values from the stack and write it to an output file and save the file with the filename (stackOutput.txt)
NOTE:
Write comments
Maintain proper indentation
Create a STACK ADT using Object-Oriented Paradigm
Use Modularity
code:-
#include <bits/stdc++.h>
using namespace std;
string push(string s);
std::vector<std::string> Stringarray; //decalring string
array for storing words partially
std::vector<std::string> Stack; //stack for storing
words
string push(string s){ //push function to insert into stack
Stack.push_back(s); //pushing into the stack
}
int main()
{
fstream f;
string word, filename;
filename = "stackinput.txt"; //taking stackinput.txt
f.open(filename.c_str()); //opening file into fstream f
while (f >> word)
{
Stringarray.push_back(word); //storing into
Stringrray
}
std::vector<std::string>::iterator i; //iterator for
traversing
for ( i = Stringarray.begin() ; i < Stringarray.end() ; ++i
)
{
push(*i); //push function for storing into stack
}
fstream outfile;
outfile.open("stackoutput.txt",ios::out); //opneing
outputfile
int j;
for (j = Stack.size() ; j> 0 ; j-- ) //reversing
traversing
{
outfile<<Stack[j]; //append to new
file(stackoutput.txt)
outfile<<" ";
}
return 0;
}
input File:- hai hello my name is ksr
output File :- ksr is name my hello hai
Implement a program in C++ that does the following: Reads the each of the words in...
Problem 1. Implement a C++ program that has the following functions: Reads in a paragraph of English text up to 100 words from the keyboard and stores this paragraph in a string object. Feel free to include this task in the main() function. Identifies the least frequent letter (case insensitive) in the above paragraph. Implement a separate function getLeastFreqLetter() for this task. The main() function then calls this function to find out the least frequent letter and its frequency. Calculate...
In C language This program reads in a series of words. All words consist of only lower-case letters ('a' through 'z'). None of the words entered will be longer than 50 letters. The program reads until ctrl-d (end-of-file), and then prints out all the lower-case letters that were missing in the input or a statement indicating the input has all the letters. Two executions of the program are shown below. Enter your input: the quick brown fox jumps over the...
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,...
Write a C program that … reads (from standard input) five words, with each of the words being entered on a separate line prints (to standard output) the words in reverse alphabetical order Hints http://www.cplusplus.com/reference/cstring/strcmp
Write a Java program in Eclipse that reads from a file, does some clean up, and then writes the “cleaned” data to an output file. Create a class called FoodItem. This class should have the following: A field for the item’s description. A field for the item’s price. A field for the item’s expiration date. A constructor to initialize the item’s fields to specified values. Getters (Accessors) for each field. This class should implement the Comparable interface so that food...
write a C++ program that reads in a text file and reads each character or lexemes and states what token it is and writes to another file for example: while (fahr < upper) a = 23.00 whileend Output: token lexeme -------------------------------- keyword while separator ( identifier fahr operator < identifier upper separator ) identifier a operator = real 23.00 keyword whileend the program aslo reads in comments but does not add to the list. characters that are commented out or...
Implement MERGE-SORT() algorithm that reads from a file named “inputHW02.txt” a list of double numbers (max = 3,000,000 numbers), sorts those numbers and indicates time consumption. This programming question will address the advantage of using iteration loops over recursive calls as well as using INSERTION-SORT() as a procedure in MERGESORT(). Your program must perform the following actions: 1. Opens the given file name and reads all double numbers. For simplicity, we assume this file only contains numbers and nothing else....
in c++ please. Write a program that reads the contents of a text file. The program should create a map in which the keys are the individual words found in the file and the values are the number of times each word appears. For example, if the word "the" appears 128 times, the map would contain an element with "the" as the key and 128 as the value. The program should either display the frequency of each word or create...
Write a program that reads a series of words (one word per line) from a file named data.txt. Each word in the file should have each of its characters shifted by 1 character value in the ASCII table (incremented) and then that new word with its characters shifted should be printed to a new file named result.txt. Each word from data.txt should be reprinted with its new encoding in result.txt. Your program should not have any knowledge of how many...
Create a C++ program that reads in from a file numbers.txt and stores each value of each line into a two dimensional array ( int array [4][4] ) The array should be filled row by row from left to right. numbers.txt : 1,8,7,3 3,5,9,2 2,4,6,2 9,3,6,2