Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- *
- *
- *
- */
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- using namespace std;
- vector<string> read_in(vector<string> words);
- int total_characters(vector<string> words);
- string longest_word(vector<string> words);
- string shortest_word(vector<string> words);
- int times_used(string input_word, vector<string> words);
- string word_before(string input_word, vector<string> words);
- string word_after(string input_word, vector<string> words);
- int main(){
- vector<string> words;
- string input_word = "";
- double char_total = 0;
- double average = 0;
- string longest = "";
- string shortest = "";
- int word_used = 0;
- string before = "";
- ifstream in_file;
- ofstream out_file;
- words = read_in(words);
- if(words.size() == 0){
- cout << "ERROR: Please use a valid .txt file"<< endl;
- return 0;
- }
- cout << "Please give a word with exact captialization: ";
- cin >> input_word;
- char_total = total_characters(words);
- average = char_total/words.size();
- longest = longest_word(words);
- shortest = shortest_word(words);
- word_used = times_used(input_word, words);
- before = word_before(input_word, words);
- cout << char_total << " " << average <<" " << longest <<" " << shortest <<" "<< word_used <<endl;
- }
- /*The purpose of this function is to read in information from a file
- *
- *Parameters:
- * vector<string>
- *
- *Return value:
- * This will return a value depending on whether or not the txt file exists
- */
- vector<string> read_in(vector<string> words){
- ifstream in_file;
- string file_name ="";
- string temp = "";
- cout << "Please give a file name: ";
- cin >> file_name;
- in_file.open(file_name.c_str());
- for(int i = 0; in_file >>temp; i++){
- words.push_back(temp);
- }
- return words;
- }
- /*This function will find the total amount of characters
- *
- *Parameters:
- * vector<string>
- *
- *return value:
- * This will return the amount of characters in a file
- */
- int total_characters(vector<string> words){
- string temp = "";
- int total=0;
- for(int i = 0; i < words.size(); i++){
- temp = words[i];
- total += temp.length();
- }
- return total;
- }
- /*The purpose of this function is to find the longest word
- *
- *Parameters:
- * vector<string>
- *return value:
- * This returns the word that is the longest in the form of a string
- */
- string longest_word(vector<string> words){
- string longest = "";
- for(int i = 0; i < words.size(); i++){
- if( i == 0){
- longest = words[i];
- }
- if(words[i].length() > longest.length()){
- longest = words[i];
- }
- }
- return longest;
- }
- /*The purpose of this function is to find the shortest word
- *
- *Parameters:
- * vector<string>
- *return value:
- * This returns the word that is the shortest in the form of a string
- */
- string shortest_word(vector<string> words){
- string shortest = "";
- for(int i = 0; i < words.size(); i++){
- if( i == 0){
- shortest = words[i];
- }
- if(words[i].length() < shortest.length()){
- shortest = words[i];
- }
- }
- return shortest;
- }
- /*This function determines how many times a word is used that is given by the user
- *
- *Parameters:
- * input_word: the word the user gives, vector<string> words: The entire file in the form of strings
- *
- *return value:
- * How many times a certain string is used with exact capitalization
- */
- int times_used(string input_word, vector<string> words){
- int counter = 0;
- for(int i = 0; i < words.size(); i++){
- if(words[i] == input_word){
- counter++;
- }
- }
- return counter;
- }
- string word_before(string input_word, vector<string> words){
- }
- string word_after(string input_word, vector<string> words){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement