Need this written in C++ in the simplist way possible You are given a file of cu
ID: 3572775 • Letter: N
Question
Need this written in C++ in the simplist way possible
You are given a file of customer data with records in the following format : account number, last name, first name, middle name. Write a program to convert the input data and display it to the monitor in the following format :
Account Name Logon ID Initial Pswd
21-88282712-C Keith S. Adams ADAM21 Adam88282
08-36847734-A John R. Sturm STUR08 Stur36847
etc.
Notes :
1) The account number on the input is 10 digits
2) The names on the input file are 2 strings. The first incoming name string variable has last name, comma and first name in it. The second one contains the middle name.
3) The outputted account must contain hyphens as shown above. The first 2 digits of the account determine the letter at the end of the outputted account : For instance, if the first 2 digits are between 01 and 10 inclusive, the ending letter is A, if the first 2 digits are between 11 and 20 inclusive, the ending letter is B, and so on..
4) The ouputted name is : first name, middle initial, last name. Use the string function find to find the index of , ; the function length to find the length of the string; and the function substr to extract the first name, last name and middle initial. See table 7-1 in the textbook.
5) Logon ID is formed by taking first 4 characters of last name and making them uppercase, then appending the first 2 digits of the account number. The toupper(x) function can be used to obtain the uppercases of the letter.
6) Initial Pswd consists of up to the first 4 characters of last name and the third to seventh digits of account number
7) Include the column headings in the output and be sure the columns are centered under the headings.
This is the file. It's supposed to a text file, but I couldn't upload the txt file.
Explanation / Answer
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
void main()
{
String a[5],f,e,b,c,d2;
ifstream read_file;
read_file.open("file_name.txt");
if(read_file.is_open())
{
while(!read_file.eof)
{
getline(read_file,e);
istringstream iss(e);
for(i=0;i<4;i++)
{
String f;
iss>f;
a[i]=f;
}
}
}
//printing of data in respective form
String d2=a[2]+a[3]+a[1];
b=a[1].substr(0,4)+a[0].substr(0,2);
c=a[1].substr(0,4)+a[0].substr(3,7);
cout<<a[0]<<d2<<toupper(b)<<c<<endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.