Question

In: Computer Science

Given the following program readline.cpp and the data file e2_input.txt: // Program readline.cpp demonstrates how to...

  • Given the following program readline.cpp and the data file e2_input.txt:
    // Program readline.cpp demonstrates how to read a line of text from a file
    
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    
    int main()
    {
    
        string str1, str2, str3, str4;      // declares 4 variables
        ifstream inData;                    // declares input stream
        ofstream outData;                   // declares output stream
    
        inData.open("e2_input.txt");
        // binds program variable inData to the input file "input.txt"
    
        outData.open("e2_output.txt");
         // binds program variable outData to the output file "output.txt"
    
        // input 4 lines
        getline(inData,str1);
        getline(inData,str2);
        getline(inData,str3);
        getline(inData,str4);
    
        // output 4 lines
        outData  << str4  << endl;
        outData  << str3  << endl;
        outData  << str2  << endl;
        outData  << str1  << endl;  // outputs 4 lines
    
        inData.close();
        outData.close();
    
        return 0;
    }
    
    
  • The input data file e2_input.txt.
    Allan Smith
    John Cooper
    Zhang Hua
    Yao Ming
    

    You are required to deliver the following:

    • Edit/create the input data file e2_input.txt and the program file readline.cpp in your project folder.
    • Compile and run the program readline.cpp.
    • Check the content of the output data file.
      • On Hercules use this command: cat e2_output.txt
      • In Visual Studio, add the existing file e2_output.txt to the project and click on it or use Notepad to open it from the project folder.
    • Add your full name and your CS110 class instructor's name in the input data file e2_input.txt a line for each.
    • Modify the program readline.cpp to work with your new input data file.
    • Compile and run this C++ program.
    • Run the program for your lab instructor and show the result in e2_output.txt.

How to add two more names with it?

How to add two more names with it?

How to add two more names with it?

How to add two more names with it?

Solutions

Expert Solution

#include<iostream>

#include<fstream>

#include <string>

using namespace std;

int main()

{

string str1, str2, str3, str4; // declares 4 variables

ifstream inData; // declares input stream

ofstream outData; // declares output stream

inData.open("e2_input.txt");

// binds program variable inData to the input file "input.txt"

outData.open("e2_output.txt");

// binds program variable outData to the output file "output.txt"

// input 4 lines

getline(inData, str1);

getline(inData, str2);

getline(inData, str3);

getline(inData, str4);

// output 4 lines

outData << str4 << endl;

outData << str3 << endl;

outData << str2 << endl;

outData << str1 << endl; // outputs 4 lines

// add 2 more names to the output file

string str5 = "John Smith";

string str6 = "Alicia Vaughn";

outData << str5 << endl << str6 << endl;

inData.close();

outData.close();

  return 0;

}

********************************************************* SCREENSHOT *******************************************************

CODE SCREENSHOT :

INPUT FILE (e2_input.txt) - This file needs to be created before running the code and this file should be created within the same directory.

OUTPU T FILE (e2_output.txt)


Related Solutions

Program Requirements: Write a C++ program according to the following requirements: 1.   Open the data file...
Program Requirements: Write a C++ program according to the following requirements: 1.   Open the data file Electricity.txt and read each column into an array (8 arrays total). 2.   Also create 2 arrays for the following: Total Fossil Fuel Energy (sum of all fossil fuels) Total Renewable Energy (sum of all renewable sources) Electricity.txt: Net generation United States all sectors monthly https://www.eia.gov/electricity/data/browser/ Source: U.S. Energy Information Administration All values in thousands of megawatthours Year   all fuels   coal       natural gas   nuclear  ...
Write a Fortran program that is able to read in the data file. The file has...
Write a Fortran program that is able to read in the data file. The file has lines with the structure: 19990122 88888 30.5 Where: i) the first is an 8 digit code with the date: yyyymmdd (yyyy is the year, mm is the month, and dd is the day) ii) the second is the five digit odometer reading of a car iii) the third is the amount of fuel put into the car on that date to fill the tank...
write a program in c++ that opens a file, that will be given to you and...
write a program in c++ that opens a file, that will be given to you and you will read each record. Each record is for an employee and contains First name, Last Name hours worked and hourly wage. Example; John Smith 40.3 13.78 the 40.3 is the hours worked. the 13.78 is the hourly rate. Details: the name of the file is EmployeeNameTime.txt Calculate the gross pay. If over 40 hours in the week then give them time and a...
The following program can be done all in the main method. It demonstrates that a TreeSet...
The following program can be done all in the main method. It demonstrates that a TreeSet eliminates duplicates and is ordered. Create a Random object with a seed of 5. Create an ArrayList numAL of type Integer Populate numAL with 10 numbers randomly selected from 0 to 6 Print out numAL Create a TreeSet numTS of type Integer Create an Iterator alIter from numAl and use it to add all the elements of numAL in numTS. Print out numTS
Write a C program that will read different data types from the following file and store...
Write a C program that will read different data types from the following file and store it in the array of structures. Given file: (This file have more than 1000 lines of similar data): time latitude longitude depth mag magType nst gap dmin 2020-10-19T23:28:33.400Z 61.342 -147.3997 12.3 1.6 ml 12 84 0.00021 2020-10-19T23:26:49.460Z 38.838501 -122.82684 1.54 0.57 md 11 81 0.006757 2020-10-19T23:17:28.720Z 35.0501667 -117.6545 0.29 1.51 ml 17 77 0.1205 2020-10-19T22:47:44.770Z 38.187 -117.7385 10.8 1.5 ml 15 100.22 0.049 2020-10-19T22:42:26.224Z...
Create a program that creates a sorted list from a data file. The program will prompt...
Create a program that creates a sorted list from a data file. The program will prompt the user for the name of the data file. Create a class object called group that contains a First Name, Last Name, and Age. Your main() function should declare an array of up to 20 group objects, and load each line from the input file into an object in the array. The group class should have the following private data elements: first name ,last...
Hello, How can I make the program print out "Invalid data!!" if the file has a...
Hello, How can I make the program print out "Invalid data!!" if the file has a grade that is not an A, B, C, D, E, or F or a percentage below zero. The program should sort a file containing data about students like this for five columns: one for last name, one for first name, one for student ID, one for student grade percentage, one for student grade. Smith Kelly 438975 98.6 A Johnson Gus 210498 72.4 C Reges...
1)Write a C++ program which clearly demonstrates how the dangling else ambiguity is resolved. Your program...
1)Write a C++ program which clearly demonstrates how the dangling else ambiguity is resolved. Your program should print distinct results depending on if C++ uses inner-if or outer-if resolution. Turn in a listing of your program, the output, and a description of how your program demonstrates the semantic resolution of the ambiguity. 2) Give a context-free grammar describing the syntax of the following; Non-empty strings of 0’s and 1’s that represent binary numbers that have odd parity
Write a program to complete the following tasks. Record all results to a data file called "GradeSheet.dat".
 c++Write a program to complete the following tasks. Record all results to a data file called "GradeSheet.dat".(1) Read the grade sheet from attached data file, "Assignment4.dat". Print the original grade sheet.(3) Write a module to sort array GRADE[] and print the sorted grade sheet.(4) Write a module to sort array NAME[] and print the sorted grade sheet.(5) Write a module to sort array ID[] and print the sorted grade sheet.(6) Write a module to print the student's id, name, and...
Write a C++ program that implements a simple scanner for a source file given as a...
Write a C++ program that implements a simple scanner for a source file given as a command-line argument. The format of the tokens is described below. You may assume that the input is syntactically correct. Optionally, your program can build a symbol table (a hash table is a good choice), which contains an entry for each token that was found in the input. When all the input has been read, your program should produce a summary report that includes a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT