Question

CS211 Lab Assignment - 7 Write a recursive C++ function that prints the contents of the file “lorem ipsum.txt”. Your code sho

Text:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. 
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. 

Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ CODE:

#include<iostream>

#include<fstream>

#include<vector>

using namespace std;

// Define readFile() recursive function

string readFile(ifstream& ifs){

   // ifs is file stream object

   // Keep reading from the file until ifs.eof() return true

   if(ifs.eof())

      return "";

   // Declare string line variable

   // for storing text

   string line;

   // Read text line by line

   getline(ifs, line);

   // return line

   // \n for next line

   // readFile function call recursively

   return  line +"\n" + readFile(ifs);

}

// main() function

int main()

{

    // open a text file lorem_ipsum.txt

    ifstream inputFile("lorem_ipsum.txt");

   //calling readFile() function pass file

    cout<<readFile(inputFile);

    inputFile.close(); //close the file object.

    return 0;

}

lorem_ipsum.txt:

File Edit Format View Help Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut laborOUTPUT:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. UNOTE: If you don't understand any step please tell me.

Add a comment
Know the answer?
Add Answer to:
Text: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore...
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
  • CaesarCipher Introduction Hiding the meaning of messages by putting them in some kind of code is...

    CaesarCipher Introduction Hiding the meaning of messages by putting them in some kind of code is something we have all done, from the “coding rings” and secret symbols of childhood to the top secrecy of military and commercial establishments’ secret data. In fact, some of the earliest uses of computers were for coding messages and for breaking the enemy’s coded messages. Newer coding methods are among the most interesting research areas in computer science today. The Caesar Cipher One of...

  • Having a little trouble with this assignment. "Please add comments within Script, for the guidance of...

    Having a little trouble with this assignment. "Please add comments within Script, for the guidance of the code and what each function is doing, so i can understand more." Project 4 Draft: Pattern Search PYTHON Introduction Your task for this project is to use regular expressions to discover and modify information from the provided test. The project is broken into two sections: Determine the number of non alpha numeric characters in the lorem_ipsum string. Replace all instances of the words...

  • I need to explain the importance of knowing how and when to use: A search using...

    I need to explain the importance of knowing how and when to use: A search using literal characters For sequence and ranges For special characters and wild cards I need to support this answer with examples from my script. Please help. ( I need a written answer and explanation my script is complete and running) 140 lorem ipsumLorem ipsum dolor sit-amet consectetur adipiscing elit- Phasellus iaculis velit ac ounc interdum tempor Ut volutpat elit metus, vel auctor enim commodo at....

  • python program do not use dictionary, list only Complete the program found in assignment4.py. You may...

    python program do not use dictionary, list only Complete the program found in assignment4.py. You may not change any provided code. You may only complete the sections labeled: #YOUR CODE HERE Write a program that does the following. Reads the contents of Text from the include file, input.txt Create a dictionary of key-value pairs called index.txt Key: This represents the individual word Value: This is a list of the line number from Text where Key appeared Example: If the word...

  • Problems: Develop a web page that allows a user to try out different text and background...

    Problems: Develop a web page that allows a user to try out different text and background color combinations by clicking buttons. Use Javascript to implement the functionalities. Below are two screen shots of the working application. Clicking the buttons at the bottom changes either the foreground color or the background color. The following descriptions are about the details. Specifically, you have to implement: An HTML file should include the following features (3 points) Some texts (Anything you like) Put the...

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
Active Questions
ADVERTISEMENT