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
drek231 [11]
3 years ago
10

You are given a file consisting of students’ names in the following form: lastName, firstName middleName. (Note that some studen

ts may not have a middle name.) Write a program that converts each name to the following form: firstName middleName lastName. Your program must read each student’s entire name into a variable and must contain a function that takes as input a string, consisting of a student’s name, and returns a string consisting of the altered name. • Use the string function find to find the index of , • the function length to find the length of the string • the function substr to extract the firstName, middleName and lastName. Output the altered name into a file. This program has no user interface.a. Banks,John Williamb. Barret,Ronc. Drew,Lucy Maried. Perry,Mark Ge. Smith,John Carr
Computers and Technology
1 answer:
pishuonlain [190]3 years ago
5 0

Answer:

#include <iostream>  // header file for input output functions

#include <string>  // header file for string manipulation

#include <fstream>  // for handling file functions  

using namespace std;  //namespace is used to identify objects like cout, cin

void NamesFunction()  {

// Function to convert names to format firstName middleName lastName    string Name;  //String type variable to store full name

ifstream DataFile;   //used to read input from a file

ofstream OutputFile;  // used for writing in a file

string lastName;  // string type variable to store last name

string firstName;  // string type variable to store first name

int position;  // used to store position of a specified character in the string

int size;  // stores length of full name

DataFile.open("inputtexthere.txt");

//opens text file using object DataFile

OutputFile.open("outputext.txt" );

//opens the text file using object OutputFile

do  {  //start of Do while loop

getline(DataFile, Name);  //reads full names from input stream

position = Name.find(",");  // stores position of the , in the name

lastName = Name.substr(0, position);  

// stores substring last name from full name

size= Name.length();  //store the length of the entire name

firstName = Name.substr(position + 2, size);  

/* stores first name substring from entire name string with the help of specified position */

OutputFile<< firstName << " "; //output first name  in text file

cout << firstName << " ";  

OutputFile<< lastName << endl;  //outputs last name in text file

cout << lastName << endl;   }

    while (DataFile.eof() == false);  

//loop continues until the end of input file is reached

DataFile.close();  //closes input file

OutputFile.close();  }  //closes output file

int main(int argc, char *argv[])  //start of main function

{   NamesFunction();  // calls NamesFunction()

}

Explanation:

The brief description of included header files is mentioned in the comments added to the program. Lets begin from the NamesFunction()  function.

The string variable Name contains the entire string of full names. Then ifstream class is used which is used to read the input file using an object. The object here is DataFile. ofstream is used to write on a file using an object which is named as OutputFile here. firstName and lastName holds first and last names. position variable stores the specified position. Here the  position stores the index position of comma (,) in the string which comes between the lastName and firstName in the input file. size variable holds the length of the Name string.

The function substr is used here to divide the string into substring which is the part of the string that starts at character position and traverses through the specified length of characters.

Here to get the last name in the Name string, substr is used which has two parameters 0 and position means that the substring is obtained starting from 0 position of string and ends where it encounters (,).

Similarly to get the first name, this function is used and it has two parameters; position+2 and size which states that substring will start from two places after (,) and ends till the length of the string. Here position+2 means that it will skip the space between the first name and last name.

Next the names are displayed and stored in the output file via the OutputFile object in the format : firstName middleName lastName

close function will close both the input and output files

Main function calls this function NamesFunction to execute.

You might be interested in
refers to a problem-solving approach that requires defining the scope of a system, dividing it into its components, and then ide
lilavasa [31]

Answer:

D. System Analysis

Explanation:

System analysis can be defined as the process of analysing a problem in order to the know the cause thereby finding a way to resolve it or finding a solution to it.

System analysis enables us to easily study procedure or process thereby identifying what the objective of the procedures is which will in turn help to achieve what we needed to achieve.

System analysis is important because it enables easier identification of a problem which make us to find the best way to solve the problem since it is a problem solving technique which ensures that all problem are been resolved accurately and efficiently

6 0
3 years ago
What is the process called that determines how bits are represented on the medium?
Bad White [126]
The process that determines how bits are represented on the medium is called encoding. It is the process of converting a certain data into a particular format that is required for a certain processing need like program execution, data transmission or file conversion.
3 0
3 years ago
Photographs, illustrations, and videos are increasingly created an and viewed in digital formats. True or False​
lutik1710 [3]

Answer:

I think it's True but I don't know sorry if I'm wrong

6 0
2 years ago
Read 2 more answers
Write a Python program that takes a file name as input and generates the following output: File size in bytes and KBs Time the f
Airida [17]

Answer:

See explaination

Explanation:

import os

import time

from stat import *

file = input("Enter file name: ")

details = os.stat(file)#stores statistics about a file in a directory

print("File size: ", details[ST_SIZE])#retreiving size

print("File last accessed time: ", time.asctime(time.localtime(details[ST_ATIME])))#access time

print("File last modified time: ", time.asctime(time.localtime(details[ST_MTIME])))#modified time

print("File creation time: ", time.asctime(time.localtime(details[ST_CTIME])))#creation time

print("First character: ", file[0])

print("Middle character: ", file[len(file) // 2])

print("Last character: ", file[len(file) - 1])

num_words = 0

num_lines = 0

f=open(file, "r")

lines = f.readlines()

for line in lines:

num_lines = num_lines + 1

num_words = num_words + len(line.split())#add no. of words in that line

print("Number of lines: ", num_lines)

print("Number of words: ", num_words)

8 0
2 years ago
Your boss calls you from his home to use the VPN connection you configured for him
prisoha [69]

Its not c or b. I think it's a. Im not sure tho..

7 0
3 years ago
Other questions:
  • In three or four sentences, describe how a person buys and sells stock.
    6·2 answers
  • What will allow you to purchase software without receiving full rights to the program?
    14·1 answer
  • The producer thread will alternate between sleeping for a random period of time and inserting a random integer into the buffer.
    7·1 answer
  • An example of an electrical insulator is _____.
    15·1 answer
  • Repl.it Assignment 4.1.2 (Guess the Number)<br> Please help me<br> I will give brainliest and a like
    10·1 answer
  • A proper divisor of a positive integer $n$ is a positive integer $d &lt; n$ such that $d$ divides $n$ evenly, or alternatively i
    8·1 answer
  • Linux is a kind of software whose code is provided for use, modification, and redistribution. what kind of software is this?
    5·1 answer
  • Help giving points mark BRAINLEST
    5·1 answer
  • Does anyone know a good reason WHY to change your username.
    5·1 answer
  • name instances in the past where social media has kept you informed about the latest news around the country​
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!