Question: Please write in C++, NOT C. Here is the starter code : #include // For cout, cin, etc. #include // For the columnar output #include

Please write in C++, NOT C.

Please write in C++, NOT C. Here is the starter code: #include

Here is the starter code:

#include // For cout, cin, etc.

#include // For the columnar output

#include // A new one: this is needed for file operations

using namespace std;

//

// Starter file for Lab #5.

//

// This program should open file and will read it in a loop. If you are

// having trouble determining the file's location, try giving a "full path"

// to it including the directory. For example, if the file is in your Downloads

// directory, you would use a path like this:

// "C:\\Users\\myname\\Downloads\\instagram.txt"

// on Windows machines (don't forget the double backslashes, this is require to

// escape the 'literal' backslash character). Mac/OSX uses forward slashes '/'

// that do not need to be doubled.

//

int main() {

ifstream inputFile("instagram.txt"); // The opened file

string tmp; // To hold the line from the file

int nLines = 0; // A count of lines

// Other variables needed here (more counters?)

// Check to see if the file was opened

if (!inputFile.good()) {

cerr

return -1;

}

// Enter a while() loop here. Check the getline() function for

// how to read from inputFile.

//

// while ( ... ) {

//

//

// }

// Output the report

cout

// ...

// Don't forget to close the file!

return 0;

}

instagram.txt:

1. Selena Gomez celebrities 2. Taylor Swift celebrities 3. Ariana Grande celebrities 4. Beyonce celebrities 5. Kim Kardashian West celebrities 6. Cristiano Ronaldo celebrities 7. Kylie celebrities 8. Justin Bieber celebrities 9. therock celebrities 10. Kendall celebrities 11. Nicki Minaj celebrities12. nike fashion 13. National Geographic media 14. Nj celebrities 15. Leo Messi celebrities 16. Khloe celebrities 17. KATY PERRY celebrities 18. Miley Cyrus celebrities 19. Jennifer Lopez celebrities 20. Demi Lovato celebrities 21. Kourtney Kardashian celebrities 22. Victoria's Secret fashion 23. badgalriri celebrities 24. Kevin Hart celebrities 25. FC Barcelona sports 26. Real Madrid C.F. sports 27. Justin Timberlake celebrities 28. Ellen celebrities 29. Cara Delevingne celebrities 30. Zendaya celebrities 31. 9gag entertainment 32. David Beckham celebrities 33. champagnepapi celebrities 34. Vin Diesel celebrities 35. Shakira celebrities 36. James Rodrguez celebrities 37. Gigi Hadid celebrities 38. LeBron James celebrities 39. Gareth Bale celebrities 40. Nike Football (Soccer) fashion 41. Zac Efron celebrities 42. Vanessa Hudgens celebrities 43. IAmZlatan celebrities 44. Emma Watson celebrities 45. xoxo Joanne celebrities 46. NBA sports 47. harrystyles celebrities 48. Scott Disick celebrities 49. Luis Suarez celebrities 50. Niall Horan celebrities

For this lab you will get some practice opening files and using a loop to read their contents. We're going to start with a text file, which contains human-readable data. Your program will read a line at a time from the provided file into a 'string' variable,. String processing from files is a very common thing to do in C++ programs (and computer software in general!). Input File The file posted in this module, instagram.txt D, is a text file containing a recent tally of the 50 most followed Instagram accounts. Download and copy this file into your Desktop directory. The file has 3 columns: the rank, the name associated with the account, and the category. There are 5 possible categories: celebrities, fashion, media, sports and entertainment. Assignment To complete this lab write a program that: Opens the file. The program should exit with an error message if the file cannot be opened. Reads the file one line at a time in a loop. Checks each line for its category (more on this below). Keeps a count of each category seen. Outputs a report to the screen with the number of lines and number of entries in each category. The output should be formatted in a table with column headers -- your output doesn't have to exactly match this example, but it should look similar. Example Output Total number of lines: 50 Category breakdown: Category Amount Celebrities Fashion Media Sports Entertainment 42 3 1 3 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!