Directions: You are to write a C++ program that meets the instruction requirements below. Deliverables: · Your C++ source code file. (The file with the .CPP extension).
No other files will be accepted. A screenshot of your program running. Program Instructions: Consider the following incomplete C++ program: #include int main() { … }
1. Write a statement that includes the header files fstream, string, and iomanip in this program.
2. Write statements that declare inFile to be an ifstream variable and outFile to be an ofstream variable.
3. The program will read data from the file inData.txt and write output to the file outData.txt. Write statements to open both of these files, associate inFile with inData.txt, and associate outFile with outData.txt.
4. Suppose that the file inData.txt contains the following data: Giselle Robinson Accounting 5600 5 30 450 9 75 1.5
The first line contains a person’s first name, last name, and the department the person works in.
In the second line, the first number represents the monthly gross salary, the bonus (as a percent), and the taxes (as a percent).
The third line contains the distance traveled and the traveling time.
The fourth line contains the number of coffee cups sold and the cost of each coffee cup.
Write statements so that after the program executes, the contents of the file outData.txt are as shown below.
If necessary, declare additional variables. Your statements should be general enough so that if the content of the input file changes and the program is run again (without editing and recompiling), it outputs the appropriate results.
Name: Giselle Robinson, Department: Accounting Monthly Gross Salary: $5600.00, Monthly Bonus: 5.00%, Taxes: 30.00% Paycheck: $4116.00 Distance Traveled: 450.00 miles, Traveling Time: 9.00 hours Average Speed: 50.00 miles per hour Number of Coffee Cups Sold: 75, Cost: $1.50 per cup Sales Amount = $112.50 5. Write statements that close the input and output files. 6. Write a C++ program that tests the statements in parts a through e.
/* C++ program that reads an input file, inData.txt file and
then find the paycheck , miles per gallon and cost of selling
coffee cups and then write the result data to the outData.txt file.
*/
//main.cpp
//include header files
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
//declare variables
string firstName;
string lastName;
string dept;
double gross=0;
double bonus=0;
double tax=0;
double paycheck=0;
double distance=0;
int time=0;
double mpg=0;
int coffeecups=0;
double costpercup=0;
double salesamount=0;
//Set file name
string inputFile="inData.txt";
//Open input file stream to read input
file
ifstream fin;
fin.open(inputFile);
//checking if file not opened
if(!fin)
{
cout<<"FILE NOT
FOUND.."<<endl;
system("pause");
return 0;
}
//read values from file into
variables
fin>>firstName;
fin>>lastName;
fin>>dept;
fin>>gross;
fin>>bonus;
fin>>tax;
fin>>distance;
fin>>time;
fin>>coffeecups;
fin>>costpercup;
//close the file
fin.close();
//Open output file stream to write data to
outData.txt
ofstream fout;
fout.open("outData.txt");
//calculate the paycheck
value
paycheck=gross+gross*bonus-(gross+gross*bonus)*tax;
//calculate miles per gallon,
mpg
mpg=distance/time;
//write data to the file
fout<<fixed<<setprecision(2)<<"Name:
"<<firstName<<" "
<<lastName<<",
Department: "<<dept
<<" Monthly Gross Salary:
$"<<gross
<<", Monthly Bonus:
"<<bonus
<<"%, Taxes:
"<<tax
<<"% Paycheck:
$"<<paycheck
<<" Distance Traveled:
"<<distance
<<" miles, Traveling Time:
"<<time
<<" hours Average Speed:
"<<mpg
<<" miles per hour Number of
Coffee Cups Sold: "<<coffeecups
<<", Cost:
$"<<costpercup<<" per cup Sales Amount =
$"<<coffeecups*costpercup<<endl;
//close the fout stream object
fout.close();
//display message
cout<<"Data is written to outData.txt file
"<<endl;
//pause program output on
console
system("pause");
return 0;
}
------------------------------------------------------------------------------------------------------------------
Sample Input file data:
inData.txt
Giselle
Robinson
Accounting
5600
5
30
450
9
75
1.5
Sample Output:
Data is written to outData.txt file
ouData.txt
Name: Giselle Robinson, Department: Accounting Monthly Gross Salary: $5600.00, Monthly Bonus: 5.00%, Taxes: 30.00% Paycheck: $-974400.00 Distance Traveled: 450.00 miles, Traveling Time: 9 hours Average Speed: 50.00 miles per hour Number of Coffee Cups Sold: 75, Cost: $1.50 per cup Sales Amount = $112.50
Directions: You are to write a C++ program that meets the instruction requirements below. Deliverables: ·...
For this assignment, you are to write a program that does the following: (C++) • read exam scores from a file name data.txt into an array, and • after reading all the scores, output the following to the monitor: the average score and the total number of scores. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file 2 of 2 //postcondition: inFile is opened. If inFile...
For this assignment, you are to write a program that does the following: • read exam scores from a file name data.txt into an array, and • after reading all the scores, output the following to the monitor: the average score and the total number of scores. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file 2 of 2 //postcondition: inFile is opened. If inFile cannot...
C++ Format You are to write a program which is going to use inheritance. It should start off with the base classes Account: contains the string name, int accountnumber, double balance. Savings: Derived from Account class, it should contain double interest rate. Checkings: Derived from Account class, it should contain double overdraftlimit. CreditCard: Derived from Checkings class, it should contain int cardnumber. Create a program which will create an array of 3 Savings accounts, 3 Checkings accounts and 3 CreditCards....
Please don't use a void fuction and this is a c++ question.
Thanks
Write a program that reads two input files whose lines are ordered by a key data field. Your program should merge these two files, writing an output file that contains all lines from both files ordered by the same key field. As an example, if two input files contain student names and grades for a particular class ordered by name, merge the information as shown below Using...
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 program in C language.
To get more practice working with files, you will write several functions that involve operations on files. In particular, implement the following functions 1. Write a function that, given a file path/name as a string opens the file and returns its entire contents as a single string. Any endline characters should be preserved char *getFileContents (const char filePath); 2. Write a function that, given a file path/name as a string opens the file and returns...
Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath> header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by...
Write a C++ program that combines the content of the two inputs files, ip1.txt and ip2.txt and writes the combined data into an output file name op.txt. Each line of op.txt contains the student name from ip1.txt and GPA from ip2.txt as follow: LastName, FirstName / GPA Note: assume the contain in ip1.txt: FirstName LastName The program must read ip1.txt and ip2.txt until it reach the end of file.
Write a simple telephone directory program in C++ that looks up phone numbers in a file containing a list of names and phone numbers. The user should be prompted to enter a first name and last name, and the program then outputs the corresponding number, or indicates that the name isn't in the directory. After each lookup, the program should ask the user whether they want to look up another number, and then either repeat the process or exit the...