Files and Their Contents: test2.txt this is test1.txt test3.txt 1| this is 2| a 3 test a asdfqwerty [end of file] a test 4| 5| mondays 6| 7| [end of file] mondays [end of file] Note: For the expected output, '\n' is used to designate where newlines have been placed. Expected Output: lastline.cpp Test case Eaгpеcted Output \n mondays\n asdfqwerty test1 test2 test3 Expected Output: longestline.cpp Елреcted Output 7\n 7\n 10\n Test case test1 test2 test3

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please see attached images that contain the instructions, three different files and their contents, and the expected output.

Files and Their Contents:
test1.txt
test2.txt
this is
test3.txt
1| this is
2| a
3| test
4|
5| mondays
6||
7| [end of file]
a
asdfqwerty
[end of file]
a
test
mondays
[end of file]
Note: For the expected output, '\n' is used to designate where newlines have been placed.
Expected Output: lastline.cpp
Test case
Егреcted Output
\n
mondays\n
asdfqwerty
test1
test2
test3
Expected Output: longestline.cpp
Еaреcted Output
7\n
7\n
10\n
Test case
test1
test2
test3
Transcribed Image Text:Files and Their Contents: test1.txt test2.txt this is test3.txt 1| this is 2| a 3| test 4| 5| mondays 6|| 7| [end of file] a asdfqwerty [end of file] a test mondays [end of file] Note: For the expected output, '\n' is used to designate where newlines have been placed. Expected Output: lastline.cpp Test case Егреcted Output \n mondays\n asdfqwerty test1 test2 test3 Expected Output: longestline.cpp Еaреcted Output 7\n 7\n 10\n Test case test1 test2 test3
Create the C++ programs lastline.cpp and longestline.cpp, where...
1. lastline.cpp – Prints the last line of the file to the screen
2. longestline.cpp – Prints the length of the longest line of the file
Note: Use the following skeleton to complete the programs.
lastline.cpp:
int main( {
ifstream file;
string name;
cout << "Enter the File Name: ";
cin >> name; // enter example: test3.txt
// Opens the File
file.open(name);
/** TODO: Read the contents of a file AND print the last line of the file. */
// Closes the File
file.close();
return EXIT_SUCCESS;
}
longestline.cpp:
int main() {
ifstream file;
string name;
cout << "Enter the File Name: ";
cin >> name; // enter example: test1.txt
// Opens the File
file.open(name);
/** TODO: Read the contents of a file AND print the length of the longest line. */
// Closes the File
file.close();
return EXIT_SUCCESS;
}
Transcribed Image Text:Create the C++ programs lastline.cpp and longestline.cpp, where... 1. lastline.cpp – Prints the last line of the file to the screen 2. longestline.cpp – Prints the length of the longest line of the file Note: Use the following skeleton to complete the programs. lastline.cpp: int main( { ifstream file; string name; cout << "Enter the File Name: "; cin >> name; // enter example: test3.txt // Opens the File file.open(name); /** TODO: Read the contents of a file AND print the last line of the file. */ // Closes the File file.close(); return EXIT_SUCCESS; } longestline.cpp: int main() { ifstream file; string name; cout << "Enter the File Name: "; cin >> name; // enter example: test1.txt // Opens the File file.open(name); /** TODO: Read the contents of a file AND print the length of the longest line. */ // Closes the File file.close(); return EXIT_SUCCESS; }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY