1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
exis [7]
3 years ago
9

Create a file with a 20 lines of text and name it "lines.txt". Write a program to read this a file "lines.txt" and write the tex

t to a new file, "numbered_lines.txt", that will also have line numbers at the beginning of each line. Example: Input file: "lines.txt" Line one Line two Expected output file: 1 Line one 2 Line two
Computers and Technology
1 answer:
ehidna [41]3 years ago
6 0

Answer:

The code has been developed in JAVA as it is the best feasible concept to handle the files.

CODE :

import java.io.*;

public class textEditor { // main class that has the code

    public static void main(String[] args) { // main driver method

       try {

            int count = 0; // count to print the line numbers to the output file

           BufferedReader br = new BufferedReader(new FileReader("lines.txt")); // reading the data from the source text file

           File outfile = new File("numbered_lines.txt"); // creating a file in the output directory

           FileWriter fw = new FileWriter(outfile.getAbsoluteFile()); // initialising the filewriter class to write the data

           BufferedWriter bw = new BufferedWriter(fw); // appending the bufferedwriter to get the data to the output file

           String line; // temporary string value

       

           if (!outfile.exists()) { // if file doesnt exists, then create it

               outfile.createNewFile();

           }

         

           while ((line = br.readLine()) != null){ // iterating over the total line in the source file

               count++;

               bw.write(count +" "+ line); // writing the source data with the line numbers to the output file

               bw.write("\n");

           }        

           bw.close(); // closing the file

           System.out.println("Process Done"); // prompt for the user

       } catch (IOException e) { // catching if any exception is raised

           e.printStackTrace();

       }

   }

}

Explanation:

You might be interested in
Learning Management Systems (LMS) allow students to interact with each other, but NOT their teachers.
VMariaS [17]

Answer:

what do you mean friend not for teacher

8 0
3 years ago
Read 2 more answers
Design a class named Employee. The class should keep the following information in member variables:
Paha777 [63]

Answer:

Here is the code.

Explanation:

#include <iostream>

#include <cstdlib>

#include <string>

#include <iomanip>

using namespace std;

class Employee

{

private:

string employeeName;

int employeeNumber;

int hireDate;

public:

void setemployeeName(string employeeName);

void setemployeeNumber(int);

void sethireDate(int);

string getemployeeName() const;

int getemployeeNumber() const;

int gethireDate() const;

Employee();

};

void Employee::setemployeeName(string employeeName)

{

employeeName = employeeName;

}

void Employee::setemployeeNumber(int b)

{

employeeNumber = b;

}

void Employee::sethireDate(int d)

{

hireDate = d;

}

string Employee::getemployeeName() const

{

return employeeName;

}

int Employee::getemployeeNumber() const

{

return employeeNumber;

}

int Employee::gethireDate() const

{

return hireDate;

}

Employee::Employee()

{

cout << "Please answer some questions about your employees, ";

}

class ProductionWorker :public Employee

{

private:

int Shift;

double hourlyPay;

public:

void setShift(int);

void sethourlyPay(double);

int getShift() const;

double gethourlyPay() const;

ProductionWorker();

};

void ProductionWorker::setShift(int s)

{

Shift = s;

}

void ProductionWorker::sethourlyPay(double p)

{

hourlyPay = p;

}

int ProductionWorker::getShift() const

{

return Shift;

}

double ProductionWorker::gethourlyPay() const

{

return hourlyPay;

}

ProductionWorker::ProductionWorker()

{

cout << "Your responses will be displayed after all data has been received. "<<endl;

}

int main()

{

ProductionWorker info;

string name;

int num;

int date;

int shift;

double pay;

cout << "Please enter employee name: ";

cin >> name;

cout << "Please enter employee number: ";

cin >> num;

cout << "Please enter employee hire date using the format \n";

cout << "2 digit month, 2 digit day, 4 digit year as one number: \n";

cout << "(Example August 12 1981 = 08121981)";

cin >> date;

cout << "Which shift does the employee work: \n";

cout << "Enter 1, 2, or 3";

cin >> shift;

cout << "Please enter the employee's rate of pay: ";

cin >> pay;

info.setemployeeName(name);

info.setemployeeNumber(num);

info.sethireDate(date);

info.setShift(shift);

info.sethourlyPay(pay);

cout << "The data you entered for this employee is as follows: \n";

cout << "Name: " << info.getemployeeName() << endl;

cout << "Number: " << info.getemployeeNumber() << endl;

cout << "Hire Date: " << info.gethireDate() << endl;

cout << "Shift: " << info.getShift() << endl;

cout << setprecision(2) << fixed;

cout << "Pay Rate: " << info.gethourlyPay() << endl;

system("pause");

return 0;

}

7 0
3 years ago
Beneficios del reciclaje electrónico
kykrilka [37]

English:

Recycling, in general, is good, it saves space in landfills and prevents pollution. Because some of the materials used to make the electronic piece are made with toxic ingredients its better to recycle them instead of having them end up in our oceans. Also, some pieces of electronics contain valuable metals like gold and copper. These Metals can be reused to make new better electronics with having to use the energy and money to produce new materials  

Español:

El reciclaje, en general, es bueno, ahorra espacio en los vertederos y evita la contaminación. Debido a que algunos de los materiales utilizados para fabricar la pieza electrónica están hechos con ingredientes tóxicos, es mejor reciclarlos en lugar de que terminen en nuestros océanos. Además, algunos componentes electrónicos contienen metales valiosos como el oro y el cobre. Estos metales se pueden reutilizar para fabricar nuevos y mejores productos electrónicos con la necesidad de utilizar la energía y el dinero para producir nuevos materiales.

4 0
3 years ago
For python how do I ask the user how many numbers they want to enter and then at the ending add those numbers up together?
Digiron [165]

I am not too familiar with the Python language, but the algorithm would be something like this:

1. create a variable for the sums of the number

2. read in how many numbers the user wants to enter (let's call it N)

and then create a for loop:

for N times

read in the next number

increase the sum variable by that number

Hopefully this helps!

8 0
3 years ago
How do you use a iPad when it has a password ?
BaLLatris [955]
Take it to the Apple Store and they will help you or you can go on their site and press "Forgot Apple ID." If you choose the second option you have to enter the first and last name, and the email you used for the iCloud on the iPad. 
6 0
4 years ago
Read 2 more answers
Other questions:
  • Design a data structure to support the following two operations for a set S of inte- gers, which allows duplicate values: • INSE
    15·1 answer
  • Sofia is reading a difficult text for class and worries that she won't complete it by the given deadline. How can a text-
    13·2 answers
  • Taking away iPad privileges when a student hits another child would be considered a(an) ________ principle for decreasing or ext
    10·1 answer
  • A wireless engineere has an access point using 5.725-ghz channel in the united states. In which band is the AP operating?
    9·1 answer
  • What important feature of an email gives you a clue about what the sender wants to tell you?
    12·2 answers
  • Distinguish between exponentiation and modulus. Be specific.
    5·1 answer
  • Self-confidence, blank, and communication are key factors to building positive relationships. Fill in the blank with a 13 letter
    5·1 answer
  • Paths describe the location of folders and files on your computer. If you have saved your work to c:\documents, then your work h
    12·1 answer
  • Explain the history of computing device of mechanical era
    7·1 answer
  • Which areas of a business would most benefit from using the Workday platform?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!