1 answer

Write a recursive function that takes a string as input. This recursive function should open a...

Question:

Write a recursive function that takes a string as input. This recursive function should open a file by the name of the string, and read the first word. Then attempt to open a file by the word you just read and repeat this process. This ends, when there is no file with the name you are looking for. At this point, cout the last word in the current file (the one where the first word was not a different file).

So for example if you have three files: "hi.txt" contains: moo is happy cow "moo" contains: im actually a sad cow "cow" contains: the cow is a lie

If you ran this recursive function on "hi.txt", you would find the first word in this file is "moo". "moo" is an actual file, so we open it. The first word in "moo" is "im". There is no file "im", so we would just cout "cow". (Ensure you do not write the function for this specific example... but any combinations of files and words.)


Answers

void readFiles(string file){
     
   ifstream fin,f;
   fin.open(file.c_str());//open the file to read
   string word;
   fin>>word;//read first word
   f.open(word.c_str());//open the file with that name
   if(f.is_open()){//if file is getting opened
       readFiles(word);//call the function again on that file
   }else{//if file is not getting opened
       while(fin>>word){//read all the words
          
       }
       cout<<word;//cout the last word
   }
  
}

[*] readFlles_recurs.cpp 1 #include<iostream> 2 #include<fstream> im 1 hi.txt im actually a sad cow using namespace std; 69 v

.

Similar Solved Questions

1 answer
D ancial statement information and additional data for Stanislaus Co. is holow Prepare a statement of...
d ancial statement information and additional data for Stanislaus Co. is holow Prepare a statement of cash flows for the year ending December 31, 2018 December 31 2018 w $65,000 144 200 206,600 21,000 2017 $42.000 84,000 168,000 58,800 504.000 $856.800 $84,000 50,400 Cash Accounts receivable (net) I...
1 answer
Find the equation of the line that passes through each pair of points
Find the equation of the line that passes through each pair of points. Write your answers in standard form. (1/3, -1/5), (-1/3, -1)...
1 answer
The tolowing data relating to units shipped and total shipping expense have been assembled by Archer...
The tolowing data relating to units shipped and total shipping expense have been assembled by Archer Company, a wholesaler of large, custom-built air-conditloning units for commercial buildings Total Units Month Shipped January Februay March Apri May June July 1,900 $2.400 1,800 $2,100 $2.400 $3,400...
1 answer
4. [6 marks] Consider a play of the casino game 'Quick Draw'. In this game, the...
4. [6 marks] Consider a play of the casino game 'Quick Draw'. In this game, the player pays $10 to play. He/she picks onē card from the standard deck of 52 cards (i.e. four A's, four K's, etc.). If the player selects an "A", he/she wins $50 (i.e. the profit is $40); if t...
1 answer
The beam is made of timber that has an allowable bending stress of O allow =...
The beam is made of timber that has an allowable bending stress of O allow = 6.5 MPa and an allowable shear stress of Tallow = 500 kPa. Part A Determine its height if it is to be rectangular and have a height-to-width ratio of 1.22. (Figure 1) Figure < Express your answer with the appropriate uni...
1 answer
12. Let cE C and let bER a. Show that cz + Cz b is the...
12. Let cE C and let bER a. Show that cz + Cz b is the equation of a line in C. b. For which values of b and c is l212+cZ+cz b the equation of a circle in C?...
1 answer
Req. 3: The production engineers have given you the materials requirements for each Black & White handbag.
Req. 3: The production engineers have given you the materials requirements for each Black & White handbag. Assume that no efficiencies in materials can be achieved by producing more than one unit per batch. Complete the Bill of Materials for Job #114 found below. Be sure to include number of uni...
1 answer
1. Calculate the change in price the bond will experience. ? X S. . HOME Calibri...
1. Calculate the change in price the bond will experience. ? X S. . HOME Calibri Bond Prices and Interest Rate Changes - Excel PAGE LAYOUT FORMULAS DATA REVIEW - Sign In FILE INSERT VIEW 1 - A À - A Paste B I U . Cells Editing Alignment Number Conditional Format as Cell Formatting" Table ...
1 answer
The following pie chart shows the relative frequency distribution resulting from a survey of 2,000 U.S....
The following pie chart shows the relative frequency distribution resulting from a survey of 2,000 U.S. rural households with Internet connections in a certain year. Other DSL .019 Cable .092 Dial-up Modem .747 .142 Determine the frequency distribution, that is, the total number of households with e...
1 answer
Marchete Company produces a single product. They have recently received the results of a market survey...
Marchete Company produces a single product. They have recently received the results of a market survey that indicates that they can increase the retail price of their product by 10% without losing customers or market share. All other costs will remain unchanged. Their most recent CVP analysis is pre...
1 answer
Smithen Company, a wholesale distributor, has been operating for only a few months. The company sells...
Smithen Company, a wholesale distributor, has been operating for only a few months. The company sells three products-sinks. mirrors, and vanities Budgeted sales by product and in total for the coming month are shown below based on planned unit sales as follows: Units 1,089 Sinks Mirrors Vanities Per...
1 answer
Assign ICD-10-PCS codes to the following. listed within that body system. Case Studies Assign ICD-10-PCS codes...
Assign ICD-10-PCS codes to the following. listed within that body system. Case Studies Assign ICD-10-PCS codes to the following case studies. 4. Procedure Report PREOPERATIVE DIAGNOSIS: Unstable progressive angina pectoris, markedly abnorma cani POSTOPERATIVE DIAGNOSIS: Unstable progressive angina p...
1 answer
Date: Class: Name: Midterm Examination 46. G 40. General Motors Company recently announced plans to build...
Date: Class: Name: Midterm Examination 46. G 40. General Motors Company recently announced plans to build a new production facility in Mexico and will be able to take advantage of reduced production costs related to wage rates in the local area. GM will sell the vehicles in Mexico and will also expo...
1 answer
Westerville Company Reported The.. what ROl will it earn Upgrade to macOS Mojave l 2018 6...
Westerville Company Reported The.. what ROl will it earn Upgrade to macOS Mojave l 2018 6 Get Dark Mode, Stacks, new app new Mac App Store Saved Check my wol 0 Required information [The following information applies to the questions displayed below. Westerville Company reported the following results...
1 answer
Use a table of Standard Reduction Potentials to predict if a reaction will occur between Al...
Use a table of Standard Reduction Potentials to predict if a reaction will occur between Al metal and F_2(g).when the two are brought in contact via standard half-cells in a voltaic cell. If a reaction will occur, write balanced net ionic equation for the reaction that the product ions are in aqueou...
1 answer
The average time for two replicate runs is used in the calculations because Select one: o...
The average time for two replicate runs is used in the calculations because Select one: o a. An average is more reliable than a single data point b. Calculation errors will cancel out O C. None of these are true O d. It makes the experiment longer...
1 answer
Question 18 0.25 points Save Answer Whistle Works manufacturers safety whistle keychains. They have the following...
Question 18 0.25 points Save Answer Whistle Works manufacturers safety whistle keychains. They have the following information available to prepare their master budget: October November December Units to be produced 4900 5050 5720 Whistle Works sells each whistle for $8. It takes 4 ounces of metal to...