Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ //****************************************************************** // Format Names program // This program reads in a social security number, a first name, a // middle name or initial, and

C++
//******************************************************************
// Format Names program
// This program reads in a social security number, a first name, a
// middle name or initial, and a last name from file inData.
// The name is written to file outData in three formats:
// 1. First name, middle name, last name, and social security
// number.
// 2. last name, first name, middle name, and social
// security number
// 3. last name, first name, middle initial, and social security
// number
// 4. First name, middle initial, last name
//******************************************************************
#include // Access ofstream
#include // Access string
using namespace std;
int main()
{
// Declare and open files
ifstream inData;
ofstream outData;
inData.open("name.dat");
outData.open("name.out");
// Declare variables
string socialNum; // Social security number
string firstName; // First name
string lastName; // Last name
string middleName; // Middle name
string initial; // Middle initial
// Read in data from file inData
inData >> socialNum >> firstName >> middleName >> lastName;
// Access middle initial and append a period
initial = middleName.substr(0, 1) + '.';
// Output information in required formats
outData
outData
outData
outData
// Close files
inData.close();
outData.close();
return 0;
}
image text in transcribed
image text in transcribed
Exercise 1: Compile and run program Name (name.cpp). Exercise 2: Change the data file to contain your name and Social Security number. Rerun the program. Explain why it was unnecessary to recompile the program. Exercise 3: Change program Name so that it reads its input from the keyboard rather than from a file. Compile and run the program, using the data that was originally on file name.dat. Run the program again with your name and Social Security number Exercise 4: Change the program that results from Exercise 3 to send its output to cout rather than a file. Compile and run the program using the data from Exercise 3 Exercise 5: Take the original program Nane, and alter it so that it prompts for and reads the input file name from the keyboard. Compile and run the program with the data originally on file name.dat. Exercise 6: Alter the program in Exercise 5 so that it prompts for and reads the output file name from the keyboard. Compile and run the program with the data originally on file name.dat. Exercise 7: Take the code that prompts for and reads the input and output file names from the keyboard and store it on a file to be used in later programs

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions