Question
Develop a functional flowchart and then write a C++ program to solve the following problem.
1. Create a text file named c1.txt and write your brand of computer (like Dell, HP, etc) in the file. You will be reading the name of the file from the keyboard as a string, using the string class. Your program will also read the brand of your computer from the keyboard. The process of the file creation (name of the file, mode for opening the file, and testing the open success is done in a user-defined function. The function communicates the status of file open to the calling function).
2. Create a text file named c2.txt and write your computer model in the file. You will be reading the name of the file from the keyboard as a string, using the string class. Your program will also read the model of your computer from the keyboard. The process of the file creation (name of the file, mode for opening the file and testing the open success is done in a user-defined function. The function communicates the status of file open to the calling function)
3. Create a text file named myComputer.txt and writes the brand of your computer from the file c1.txt, and the model from file c2.txt. You will be reading the name of the file from the keyboard as a string, using the string class. The process of the file creation (name of the file, mode for opening the file and testing the open success is done in a user-defined function. The function communicates the status of file open to the calling function)
4. At this time, each file will have one line of text in it.
5. Prepare the files for reading.
6. Display the results of the three files in the order shown below:
c1.txt​​​your brand of computer as written in the c1
c2.txt​​​your model of the computer as written in the c2
myComputer.txt​​your computer brand and the model as written in myComputer
Note that there is a single space between the Computer brand and the computer model when you display the contents of the file myComputer.txt.
You will use a user-defined function to display all the files at once or one at a time.
7. Close all files. You will use a user-defined function that closes each file separately or all at once.
8. Run the program again and use your choice of the filenames, and different names, different than what you used above and repeat the process.
The programs in the book and sample programs provided show you how to read file names as strings and how to convert the strings to the C string, if needed.

solution. Develop a functional flowchart and then write a C++ program to solve the following problem. Create a text file name
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:-

code:

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

string fFile, lFile, flFile;

//function to write first name to file

void Firstfilewrirt()

{

cout << "Input the firstname filename: ";

cin >> fFile;

ofstream f(fFile);

string fname;

cout << "FirstName: ";

cin >> fname;

f << fname;

f.close();

}

//function to write last name to file

void Lastfilewrirt()

{

cout << "Input the lastname filename: ";

cin >> lFile;

ofstream l(lFile);

string lname;

cout << "LastName: ";

cin >> lname;

l << lname;

l.close();

}

//function to read first name and last name from file and write to a file

void FistLastfilewrirt()

{

cout << "Enter the combined filename: ";

cin >> flFile;

ofstream fl(flFile);

ifstream i1(fFile);

string fn, ln;

i1 >> fn;

ifstream i2(lFile);

i2 >> ln;

fl << fn << " " << ln;

fl.close();

}

//function to diaplay three file contents

void disply()

{

string fnam;

ifstream fi1(fFile);

fi1 >> fnam;

cout<<"First name: "<<fnam<<endl;

string lnam;

ifstream li1(lFile);

li1 >> lnam;

cout<<"Last name: "<<lnam<<endl;

string flnam1, flnam2;

ifstream fli1(flFile);

fli1 >> flnam1>>flnam2;

cout<<"Last name: "<<flnam1<<" "<<flnam2<<endl;

}

//main function calling each user defined function

int main()

{

Firstfilewrirt();

Lastfilewrirt();

FistLastfilewrirt();

disply();

system("pause");

}

As per HomeworkLib rule , i have given you the answer. Thanking you. Keep HomeworkLibing.

Add a comment
Know the answer?
Add Answer to:
Develop a functional flowchart and then write a C++ program to solve the following problem. 1....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT