Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this assignment, practice using iostream, getline, and string ops. Your prog

ID: 3883673 • Letter: F

Question

For this assignment, practice using iostream, getline, and string ops. Your program should ask for a output filename.
It will read test1.csv.
test1.csv contains their firstname, lastname, birthday, and yearly income of 4 people formatted in the following way: firstname;lastname;mm/dd/yyyy;$yearlyIncome .
It will calculate the monthly income and age (in years) of each person and output that information to the provided output filename in the following format: lastname, firstname;age;$monthlyIncome.

Explanation / Answer

#include<iostream>
#include<fstream>
#include<sstream>
#include<time.h>

using namespace std;

int main(){

time_t theTime = time(NULL);
struct tm *aTime = localtime(&theTime);
int year = aTime->tm_year + 1900;
string fn, ln, dob, inc, file;

ifstream ip;

ip.open("test1.csv");

cout<<"Enter output file name:-";
getline(cin, file);

ofstream f;
f.open(file.c_str());

while(ip){
string yr;
int yri, yi, age, mi;
getline(ip,fn,',');
getline(ip,ln,',');
getline(ip,dob,',');
getline(ip,inc,' ');

yr = yr.append(dob,6,4);
stringstream ss(yr);
ss >> yri;
stringstream si(inc);
si >> yi;

age = year - yri;
mi = yi/12;
f << ln <<","<< fn <<","<< age <<","<< mi <<" ";

}
f.close();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote