Question

estion 3 1. Suppose the file mystery.txt contains the text below: The whole thing starts about twelve, fourteen or seventeen.

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

correct option is Thirteen

ifstream read("mystery.txt"); this reads the mystery.txt file

   while(!read.eof()) // loop continues until the end of the text
   {
       read>>word; //string word stores the each word that is read one after another
       if(i<word.length())
       {
           cout<<word[i];
       }
       i++;
   }

The text is  The whole thing starts about twelve,fourteen or seventeen

i=0

word = The

word.length = 3

so i<word.length .....condition is true so cout<<word[i]

word[0]=T so T will be printed

i is incremented

i=1

word =  whole

word.length = 5

so i<word.length .....condition is true so cout<<word[i]

word[1]=h so h will be printed

i is incremented

i=2

word = thing

word.length = 5

so i<word.length .....condition is true so cout<<word[i]

word[2]=i so i will be printed

i is incremented

i=3

word = starts

word.length = 6

so i<word.length .....condition is true so cout<<word[i]

word[3]=r so r will be printed

i is incremented

i=4

word = about

word.length = 5

so i<word.length .....condition is true so cout<<word[i]

word[4]=t so t will be printed

i is incremented

i=5

word =  twelve

word.length = 6

so i<word.length .....condition is true so cout<<word[i]

word[5]=e  so e will be printed

i is incremented

i=6

word = fourteen

word.length = 8

so i<word.length .....condition is true so cout<<word[i]

word[6]=e so e will be printed

i is incremented

i=7

word = or

word.length = 2

so i>word.length .....condition is not true so nothing will be printed

i is incremented

i=8

word = seventeen

word.length = 9

so i<word.length .....condition is true so cout<<word[i]

word[8]=n so n will be printed

now we have reached end of the text so the loop breaks

When we combine the letters printed in each iteration we get

Thirteen

So option 2 is correct

Add a comment
Know the answer?
Add Answer to:
estion 3 1. Suppose the file mystery.txt contains the text below: The whole thing starts about...
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
  • 1. Suppose the file mystery.txt contains the text below: The whole thing starts about twelve, fourteen...

    1. Suppose the file mystery.txt contains the text below: The whole thing starts about twelve, fourteen or seventeen. #include <iostream> #include <fstream> #include <string> using namespace std; int main() { string word; int i 0; ifstream read("mystery.txt"); while(!read.eof()) { read>>word; if(i < word. length()) cout<<word[i]; i++; } cout<< endl; } seventeen teen

  • How do I complete my code using an external file? External file: data.txt //the number 6...

    How do I complete my code using an external file? External file: data.txt //the number 6 is in the external file Incomplete code: #include <iostream> #include <fstream> using namespace std; class example {    int data[1]; public:    example();    void read(ifstream &); }; example::example() {    ifstream infile;    infile.open("data.txt");    } void example::read(ifstream &infile) {    infile >> data[1];    cout << data[1] << endl;    } int main() {    example example, read; //system("pause");    return 0;...

  • my code deosn't run and it doesn't show any error. what's wrong about it !! it...

    my code deosn't run and it doesn't show any error. what's wrong about it !! it should loads data from a text file into an array of structs and prints the array to the screen here is the code: #include <iostream> #include <string> #include <fstream> using namespace std; struct Company {    string Departmentname;    int Departmentnum; }; const int MAX = 20; int main() { ifstream File;    Company arrayofdepartment[MAX];    int Departmentcount ;      File.open("comapny.txt");       if...

  • can you please split this program into .h and .cpp file #include <iostream> #include<string> #include<fstream> #define...

    can you please split this program into .h and .cpp file #include <iostream> #include<string> #include<fstream> #define SIZE 100 using namespace std; //declare struct struct word_block {    std::string word;    int count; }; int getIndex(word_block arr[], int n, string s); int main(int argc, char **argv) {    string filename="input.txt";    //declare array of struct word_block    word_block arr[SIZE];    int count = 0;    if (argc < 2)    {        cout << "Usage: " << argv[0] << "...

  • I need to make a few changes to this C++ program,first of all it should read...

    I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...

  • I need to add something to this C++ program.Additionally I want it to remove 10 words...

    I need to add something to this C++ program.Additionally I want it to remove 10 words from the printing list (Ancient,Europe,Asia,America,North,South,West ,East,Arctica,Greenland) #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int> words);    int main() { // Declaring variables std::map<std::string,int> words;       //defines an input stream for the data file ifstream dataIn;    string infile; cout<<"Please enter a File Name :"; cin>>infile; readFile(infile,words);...

  • The input file is already there. the file is too long, don't have to send it. using virtualbox ubuntu We want to cre...

    The input file is already there. the file is too long, don't have to send it. using virtualbox ubuntu We want to create a command line terminal where user can run the snap commands with three different options: -thanos, -ironman and -holk. The terminal must keep listening to user command. If the user type:  snap -thanos: all the text line in the text file “input.txt” that does not contain the word “thanos” must be randomly removed. The remaining text...

  • Please add a detailed comment for this program. #include<iostream> #include<string> #include<fstream> #include<sstream> #include<cctype> using namespace std;...

    Please add a detailed comment for this program. #include<iostream> #include<string> #include<fstream> #include<sstream> #include<cctype> using namespace std; int is_palindrome(string word){ int len = word.size(); for(int i=0; i<len/2; i++){ if(toupper(word[i])!=toupper(word[len-i-1])) return 0; } return 1; } int have_vowels3(string word){ int cnt = 0; for(int i=0; i<word.size(); i++){ if(tolower(word[i])=='a' || tolower(word[i])=='e' || tolower(word[i])=='i' || tolower(word[i]) =='o' || tolower(word[i]) == 'u') cnt++; } if(cnt>=3) return 1; else return 0; } int have_consecutives(string word){ for(int i=0; i<word.size()-1; i++){ if(tolower(word[i])=='o' && tolower(word[i+1]=='o')) return 1; } return...

  • Hey, so i am trying to have my program read a text file using a structure...

    Hey, so i am trying to have my program read a text file using a structure but i also want to be able to modify the results(I kinda have this part but it could be better). I cant seem to get it to read the file(all the values come up as 0 and i'm not sure why because in my other program where it wrote to the txt file the values are on the txt file) i copied and pasted...

  • I am having trouble trying to output my file Lab13.txt. It will say that everything is...

    I am having trouble trying to output my file Lab13.txt. It will say that everything is correct but won't output what is in the file. Please Help Write a program that will input data from the file Lab13.txt(downloadable file); a name, telephone number, and email address. Store the data in a simple local array to the main module, then sort the array by the names. You should have several functions that pass data by reference. Hint: make your array large...

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