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
  • This assignment uses functions, files, and strings. Enough flexibility is provided for you to apply your...

    This assignment uses functions, files, and strings. Enough flexibility is provided for you to apply your knowledge of basic C++ programing to develop your solution. Develop a functional flowchart and then write a C++ program to solve the following problem. 1. Create a text file named file1.txt and write your brand of car (like Honda, Toyota, etc) in the file. You will be reading the name of the file from the keyboard as a string, using the string class. Your...

  • Need to check if File is successfully opened? C++ It works when I input the right...

    Need to check if File is successfully opened? C++ It works when I input the right txt file. But, it keeps stating, File successfully open." even I put in a non-existing file. Here are the specifications: Develop a functional flowchart and then write a C++ program to solve the following problem. Create a text file named first.txt and write your first name in the file. You will be reading the name of the file from the keyboard as a string,...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( );...

    Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( ); // constructor ~Salesperson( ); // destructor Salesperson(double q1, double q2, double q3, double q4); // constructor void getsales( ); // Function to get 4 sales figures from user void setsales( int quarter, double sales); // Function to set 1 of 4 quarterly sales // figure. This function will be called // from function getsales ( ) every time a // user enters a sales...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • C++ (1) Write a program to prompt the user for an input and output file name....

    C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...

  • C++ 3. Write a program that reads integers from a file, sums the values and calculates...

    C++ 3. Write a program that reads integers from a file, sums the values and calculates the average. a. Write a value-returning function that opens an input file named in File txt. You may "hard-code" the file name, i.e., you do not need to ask the user for the file name. The function should check the file state of the input file and return a value indicating success or failure. Main should check the returned value and if the file...

  • Write a C program that prompts the user to enter a binary value, multiplies it by...

    Write a C program that prompts the user to enter a binary value, multiplies it by ten, then displays the result in binary. (“Binary” here means that the user communicates with the program in ones and zeros.) Your main function should a) declare a char array, b) call the readLn function to read from the keyboard c) call a function to convert the input text string to an int d) multiply the int by ten e) call a function to...

  • C Programming 12 1 point We can write a large amount text data to a file...

    C Programming 12 1 point We can write a large amount text data to a file without punctuation and will be able to make sense of that data when looking at the file with notepad. True False 13 1 point a When calling the function to open a file in read mode can cause the contents of the file to be erased. True False 14 1 point Writing a struct to a binary file is similar to writing an integer...

  • Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text...

    Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text file by removing all blank lines (including lines that only contain white spaces), all spaces/tabs before the beginning of the line, and all spaces/tabs at the end of the line. The file must be saved under a different name with all the lines numbered and a single blank line added at the end of the file. For example, if the input file is given...

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