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

Your program reads from two files and prints out the text message conversations

ID: 3723921 • Letter: Y

Question

Your program reads from two files and prints out the text message conversations in chronological order (from oldest to newest message sent/received). The required format for your output is:

The first 25 characters on a line are a readable version of the EPOCH time. The function readableTime (shown below) has a newline character as the very last character of the string it generates. Make sure you remove this trailing newline character (simply replace it with a ‘’ character).

The next field in the output lines is the phone number that texted you (or you texted).

The test message itself is printed in a block that does not exceed 40 characters. IF there are more than 40 characters in a text message, wrap the message to the next line.

Use at least three functions, the readableTime function does not count as one of the three functions.

You can assume that no two text messages will ever have the same time stamp.

Char *readableTime(int sec){

                time_t epoch_time = (time_t) sec;

                return asctime( localtime( &epoch_time));

}

Explanation / Answer

Answer:

The Code Can Be Given As :-

#include<iostream>

#include<fstream>

#include<ctime>

using namespace std;

char *readableTime(long unsigned int sec)

{
time_t t = (time_t)sec; //here t represents the epoch_time
return asctime(localtime(&t));
}

void process(ifstream &file,long unsigned int time,int n)

{
char *t = readableTime(time);
string display(t);
if(n == 0)

{
display[display.length()-1] = ' ';
display += " From ";
}
if(n == 1)

{
display[display.length()-1] = ' ';
display += "   To ";
}
int wor = 0;
string phone;
file>>phone;
for(int i = 0;i<phone.length();i++)

{
if(i != 0 && i%3 == 0 && i<7)

{
display += "-";
}
display += phone[i];
}
display += " | ";
file>>wor;
char ch;
for(int i = 0;i<=wor;)

{
file.get(ch);
if(i != wor){
display += ch;
}
if(ch == ' ' || ch == ' ')

{
if(ch == ' ' && i != wor)

{
display += " | ";
}
i++;
}
}
cout<<" "<<display;
}

int main(int argc,char **argv)

{
long unsigned int time1,time2;
if(argc != 3)

{
cout<<" Not Enough Argument !";
return -1;
}
string recieve(argv[0]);
string sent(argv[1]);
ifstream rfs;
ifstream sfs;
rfs.open(recieve.c_str());
sfs.open(sent.c_str());
if(rfs.is_open() && sfs.is_open()){
}else{
cout<<" File Opening Error check files names ";
return -1;
}
rfs>>time1;
sfs>>time2;
while(!rfs.eof() && !sfs.eof())

{
if(time1 < time2)

{
process(rfs,time1,0);
if(rfs.eof())

{
break;
}
   rfs>>time1;
}else{
   process(sfs,time2,1);
   if(sfs.eof()){
    break;
   }
   sfs>>time2;
  }
}
while(!rfs.eof()){
  process(rfs,time1,0);
  if(rfs.eof()){
    break;
   }
  rfs>>time1;
}
while(!sfs.eof()){
  process(sfs,time2,1);
  if(sfs.eof()){
    break;
   }
  sfs>>time2;
}

return 0;
}