Question

You have a file called Names that has names as FirstName LastName FirstName LastName. For example,...

You have a file called Names that has names as FirstName LastName FirstName LastName. For example, Names could have Bruce Willis Andrew Andrew Samwise Gamgee Duran Duran Write a program that goes through this file and writes all the names that have the same first and last names to a file called SameNames For example, for the file above, the program would write to the file SameNames Andrew Andrew Duran Duran

0 0
Add a comment Improve this question Transcribed image text
Answer #1

As you not mentioned any program software name I solved it in Python, Any doubt please comment me.

Answer)

#open the file

f=open("names", "r")

#read the lines from the file

data = f.readlines()

#split the words into array from the line

for line in data:

words = line.split(" ")

l=len(words)

i=0

w1=""

while i<l-1:

#check the words with fn which is i and lastname is i+1

if (words[i] == words[i+1]):

w1=w1+" "+words[i]+" "+words[i+1]

#move to the next

i=i+2

//write the output to the file

f = open("SameName", "w")

f.write(w1)

Add a comment
Know the answer?
Add Answer to:
You have a file called Names that has names as FirstName LastName FirstName LastName. For example,...
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
  • Consider the method: private void ShowName(string firstName, string lastName) {           MessageBox.Show(firstName + “ ” + lastName);...

    Consider the method: private void ShowName(string firstName, string lastName) {           MessageBox.Show(firstName + “ ” + lastName); } Which of the following could be used to call the method? ShowName(lastName : “Smith”, firstName : “Suzanne”); ShowName(“Suzanne”, “Smith”); Write a method named showTax which has 2 parameters of type decimal. The first parameter is the price of the items sold. The second parameter is the tax rate which has a default value of 0.07. The method does not return a value. It...

  • A table in MySQL names users has 3 String fields including firstname, lastname and username. Write...

    A table in MySQL names users has 3 String fields including firstname, lastname and username. Write a complete PHP class that would allow for constructing a users object and getting and setting values for each of the fields

  • I have this module of javascript var data = [     {id: 1, firstName: 'John', lastName: 'Smith'},...

    I have this module of javascript var data = [     {id: 1, firstName: 'John', lastName: 'Smith'},     {id: 2, firstName: 'Jane', lastName: 'Smith'},     {id: 3, firstName: 'John', lastName: 'Doe'} ]; module.exports.setid =     function (value) {         data.id = value; }; module.exports.getid = function () {         return data.id;     }; module.exports.setFirstName = function (value) {         data.firstName = value;     }; module.exports.getFirstName = function () {         return data.firstName;     }; module.exports.setLastName = function (value) {         data.lastName = value;     }; I wrote the following to get all first...

  • Write a program that reads a person's first and last names, separated by a space. Then...

    Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline. Example output if the input is: Maya Jones Jones, Maya import java.util.Scanner; public class SpaceReplace {    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       String firstName;       String lastName; //answer goes here//    } }

  • Write a program that reads a person's first and last names, separated by a space. Then...

    Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline. Example output if the input is Maya Jones Tones, Maya import java . util·Scanner; public class SpaceReplace 4 public static void main (String [1 ares) f( Scanner scnr-new Scanner(System.in); String firstName; String lastName; Your solution goes here */ 10 12

  • Write this in Java. say i have a file called "file.txt" that looked like this: Dunn...

    Write this in Java. say i have a file called "file.txt" that looked like this: Dunn Sean 31111 Duong Geoffrey 29922 Fazekas Nicholas 31100 Prezioso Stefano 22223 Puvvada Mohana 11224 and i have an object class called Student, with three String fields lastName, firstName, and ID. i want to read in file.txt from another class (preferably using BufferedReader) and store each line in the file as a Student in a Student array (example: first line gets stored as ("Dunn" ,...

  • C++ Code Please, Three employees in a company are up for a special pay increase. You...

    C++ Code Please, Three employees in a company are up for a special pay increase. You are given a file, say Ch3_Ex5Data.txt, with the following data: Miller Andrew 65789.87 5 Green Sheila 75892.56 6 Sethi Amit 74900.50 6.1 Each input line consists of an employee’s last name, first name, current salary, and percent pay increase. For example, in the first input line, the last name of the employee is Miller, the first name is Andrew, the current salary is 65789.87,...

  • In JAVA #3 Write a program named nameChanger.java. This program will only have a driver class...

    In JAVA #3 Write a program named nameChanger.java. This program will only have a driver class with a main. This program will have the user enter a series of names(first and last), which will then be stored in a String array. You will then change the values of each of the names in the array, so that they are stored lastname, firstname, and then output the revised array. Sample: Enter a name (first and last): Tonya Pierce Enter a name...

  • has to be done in c programming not c++ 5:28 . O Done Lab_Seven Lun, wuUULIVIL...

    has to be done in c programming not c++ 5:28 . O Done Lab_Seven Lun, wuUULIVIL - - - - - - - - Write a program that prompts the user to input their first name, from the keyboard and stores them in the variable "firstName". It does the same for last name and stores it in the variable "lastName". It then uses strcat to merge the two names, separates them by a space and stores the full name into...

  • Write following queries given these schemas: (FK stands for Foreign Key) Customer = {customerID, firstName, lastName,...

    Write following queries given these schemas: (FK stands for Foreign Key) Customer = {customerID, firstName, lastName, income, birthDate} Account = {accNumber, type, balance, branchNumberFK-Branch} Owns = {customerIDFK-Customer, accNumberFK-Account} Transactions = {transNumber, accNumberFK-Account, amount} Employee = {sin, firstName, lastName, salary, branchNumberFK-Branch} Branch = {branchNumber, branchName, managerSINFK-Employee, budget} Focus should be on using: Order By to sort data Set Operators to union/intersect multiple tables Join Operator to join multiple tables Aggregations and Group By to aggregate data Subqueries 3.15 Customer ID, first...

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
ADVERTISEMENT