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

In this assignment it is supposed to be a conversation between us and the comput

ID: 3695261 • Letter: I

Question

In this assignment it is supposed to be a conversation between us and the computer. Please submit: 1. Printout of your C++ program with a heading comment (Do not forget to add comments within within your program). You must use both input and output files in order to receive any eredit (6 points) 2. 4 points) objective of this assignment Read a set of words trom the input file. Generate a sentence usinga random number output tile. r generator. Store your conversation with the program to the Step 1 Open an input and an output file. Step 2 Read contents (aubject, verb, possessive, abject) trom the input file (PA13.txt). You are free to modify and create your own word sot Step 3 Your progran accepts a string from a keyboard. Step 4 Randomly generate a sentence using may include ctime library, and use srand (time (NULL)) for your random nunber seed. the words read from the input file. You step 5 Repest step 3 and 4 a few times while recording the conversation to the output file. Step 6 close both input and output files

Explanation / Answer

#include<iostream>
#include<ctime>
#include<string>
#include<fstream>
#include<sstream>
#include<cstdlib>
using namespace std;
int main()
{
string a[100][4];
string infile,outfile;
srand (time(NULL));
int num_con = rand()%7+3;
printf("Enter the name of the file you wish to open:");
cin>>infile;
ifstream in(infile);
string str1,str;
int len=0;
while(getline(in,str1))
{
stringstream ss;
ss.str(str1);
ss>>a[len][0];
ss>>a[len][1];
ss>>a[len][2];
ss>>a[len][3];
len++;
}
printf("Enter the name of the file you wish to write:");
cin>>outfile;
ofstream out(outfile);
cout<<"Hi, what's up?"<<endl;
out<<"Hi, what's up?"<<endl;
int l;
stringstream s2;
for(int i=0;i<num_con;i++)
{
s2.str("");
cin>>str;
out<<str<<endl;
l=rand()%len;
s2<<a[l][0]<<' ';

l=rand()%len;
s2<<a[l][1]<<' ';

l=rand()%len;
s2<<a[l][2]<<' ';

l=rand()%len;
s2<<a[l][3]<<endl;

cout<<s2.str();
out<<s2.str();
}
cout<<"I gotta go. Bye ;)"<<endl;
out<<"I gotta go. Bye ;)"<<endl;
in.close();
out.close();
return 0;
}