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.
Develop a functional flowchart and then write a C++ program to solve the following problem. 1....
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 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 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( ); // 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 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. 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 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...
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...
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...
It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #include "File.h" // Constructor of File that takes File name and type as arguments File::File(string type, string name) { this->type = type; this->name = name; } //returns the type. string File::getType() { return type; } //returns the name of file. string File::getName() { return name; } File.h #ifndef __FILE_H__ #define...