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
A program that will ring a bell six times is what kind of program?
amm1812

Answer:

D

Explanation:

because it is a sequence it does more than one thing

6 0
3 years ago
Read 2 more answers
If you want to prioritize downloads of your mobile app instead of visits to your mobile site, you should: a) add a sitelink exte
scoray [572]

Answer:

create a Universal App campaign

3 0
3 years ago
What is the difference between second generation and third generation​
Eduardwww [97]

These were later renamed to "Specialized Technology" and "Simscape Components" to help explain this difference.

Specialized Technology (Second Generation) is a Simulink based library and has been around for longer. It can still connect to Simscape, but in the same way you can connect Simulink models to Simscape -- that is, you need converters and sometimes to break algebraic loops, etc. It also has more dedicated electrical power systems capabilities. If your model will be only power systems, and especially if it's a larger model, I'd recommend this one.

Simscape Components (Third Generation) is built using the Simscape language and therefore connects directly with other Simscape blocks. If you plan to use other Simscape domains like mechanical, hydraulic, etc. I'd recommend this one.

4 0
2 years ago
Assume the user types in 7 and 10. What is output by the following?
Marianna [84]

Answer:

Enter a number: 7

Enter a number: 10

Traceback (most recent call last):

 File "main.py", line 3, in <module>

   print (numi + num2)

NameError: name 'numi' is not defined

Explanation:

The typo in the print statement causes a run-time error, where obviously num1+num2 was expected, and an output of 17.

3 0
3 years ago
1 #include 2 3 int max2(int x, int y) { 4 int result = y; 5 if (x &gt; y) { 6 result = x; 7 } 8 return result; 9 } 10 11 int max
Serhud [2]

Answer:

7

Explanation:

#include <stdio.h>

int max2(int x, int y) {

   int result = y;

   if (x > y) {

       result = x;

   }

   return result;

}

int max3(int x, int y, int z) {

   return max2(max2(x,y),z);

}

int main() {

   int a = 5, b = 7, c = 3;

   printf("%d",max3(a, b, c));

   printf("");

   return 0;

}

Hi, first of all, next time you post the question, it would be nice to copy and paste like above. This will help us to read the code easily. Thanks for your cooperation.

We start from the main function:

The variables are initialized → a = 5, b = 7, c = 3

max3 function is called with previous variables and the result is printed → printf("%d",max3(a, b, c));

We go to the max3 function:

It takes 3 integers as parameters and returns the result of → max2(max2(x,y),z)

Note that max2 function is called two times here (One call is in another call actually. That is why we need to first evaluate the inner one and use the result of that as first parameter for the outer call)

We go to the max2 function:

It takes 2 integers as parameters. If the first one is greater than the second one, it returns first one. Otherwise, it returns the second one.

First we deal with the inner call. max2(x,y) is max2(5,7) and the it returns 7.

Now, we need to take care the outer call max2(7, z) is max2(7, 3) and it returns 7 again.

Thus, the program prints 7.

6 0
2 years ago
Other questions:
  • _____________ is a service that provides access to hardware resources available over the Internet.
    11·1 answer
  • The a0 is the part of the central processing unit that performs arithmetic calculations for the computer.
    8·1 answer
  • What is the next series of dragon ball super
    6·2 answers
  • How do you add a PDF assignment to google docs and be able to edit it?
    13·1 answer
  • Which of the following actions is an example of "window dressing?" a. Using some of the firm’s cash to reduce long-term debt. b.
    13·1 answer
  • Given a int variable named callsReceived and another int variable named operatorsOnCall write the necessary code to read values
    13·1 answer
  • Intranets:
    8·1 answer
  • A technician is building a thick client workstation that would be used to run a database and wants to ensure the best protection
    12·1 answer
  • Which two statements are true about algorithms?
    15·2 answers
  • Which digital cellular standard is used widely throughout the world except the united states?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!