Consider the following incomplete C++
#include <iostream>
int main()
{
…
}
Write a statement that includes the header files fstream, string, and iomanip in this program.
Write statements that declare inFile to be an ifstream variable and outFile to be an ofstream variable.
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.
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.000
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
Write statements that close the input and output files.
Write a C++ program that tests the statements in parts a through e.
Trending nowThis is a popular solution!
Chapter 3 Solutions
C++ Programming: From Problem Analysis to Program Design
- Write C++ Program that does the following: •Instead of reading data from the user, create a txt file that will be imported into the code •The format of the file is: –First line: number of records –Subsequent lines: Last name on a line by itself First name and three homework grades •Read function: parameters are –An instream, passed by reference, from which to read the data –Fields for firstname, lastname, grade1, grade2, grade 3 •The read function should read in the data from the instream. It is a void function •What types are the parameters? How will you pass them? •Write function: parameters are –Firstname, lastname, grade1, grade2, grade3, average grade, letter grade –What types are those parameters? Do you need to pass them by reference? •The write function will write the data to the screen formatted neatly –Which formatting instructions will you need to use? Overall program flow: •Open the file in the main program. •Read in the number of records •For each record,…arrow_forwardWrite a function count_character(filename, character) that takes in a filename and a character, both as strings, and returns the total number of times the given character occurs in the file. Examples: Contents of hello.txt:HelloHELLOHelloHELLO count_character('hello.txt', 'L') returns 4count_character('hello.txt', 'H') returns 4count_character('hello.txt', 'e') returns 2 Requirements: Please use Python Programming only Show screenshot of your work.arrow_forwardWrite C++ Program that does the following: •Instead of reading data from the user, I will give you a file, grades.txt (look in ~cthorpe/public/141) •The format of the file is: –First line: number of records –Subsequent lines: Last name on a line by itself First name and three homework grades •Read function: parameters are –An instream, passed by reference, from which to read the data –Fields for firstname, lastname, grade1, grade2, grade 3 •The read function should read in the data from the instream. It is a void function •What types are the parameters? How will you pass them? •Write function: parameters are –Firstname, lastname, grade1, grade2, grade3, average grade, letter grade –What types are those parameters? Do you need to pass them by reference? •The write function will write the data to the screen formatted neatly –Which formatting instructions will you need to use? Overall program flow: •Open the file in the main program. •Read in the number of records •For…arrow_forward
- Program in C only - thanks Write a C Program that writes all the numbers from 1 to 100,000 that are both prime and the sum of the digits > 9. For example 47, 911 are 2 such numbers, since the sum of the digits is > 9. After finding a number, you must immediately write it to the output file. Open the file, write the number you just found, and close the file. Measure how much elapsed time it takes to do this processing. Yes, it is inefficient, but we are trying to force some I/O usage, which will cause interrupts. When this process is completed, next have the program fork and create 10 separate processes. Each process would find search a range of 1 to 100,000 for these prime and sum 11 numbers. One process searches 1 to 10000, another 10001 to 20000 etc. Each process performs the exact same tasks , in the same way, as the first part of the problem, but write the output to 10 separate files, one for each process. When all 10 processes are done, read the ten files to make one file…arrow_forwardWrite a C++ function (along with helper functions if required) that takes a file stream as a parameter and prints out the maximum negative number in the given file. Do not need to write the main function. An example: [Example file contents] 4 -2 8 12 -8 9 3Prints: Maximum Negative number -2arrow_forwardIn C write a program that takes a file name and two strings as command line arguments, and writes the longer of the two strings to the file with the given name. If the given strings are the same length, write the first string given to the file. If the user does not provide the correct number of command line arguments, print an error message and exit the program with a non-zero exit code.arrow_forward
- Can you convert this C++ code into C? #include<bits/stdc++.h> #include<fstream> using namespace std; struct produce{ string name; int item; }; struct costumer{ string name; produce order[n]; }; produce *readdata(string filename){ ifstream producefile; producefile.open(filename); produce * arr[10]; int i = 0; while(i < 10){ arr[i] -> name << producefile; arr[i] -> item = producefile; i++; } return arr; } ofsteam update(produce * arr){ ofstream updater; updater.open("update.txt"); for(int i = 0; i < 10; i++){ updater << arr[i] -> name << arr[i] -> item << endl; } return updater; } ofstream orderfile(string filename, produce *arr[10]){ ifstream costum; costum.open(filename); costumer list[10]; int i = 0; while(i < 10){ string line; getline(costum, line); list[i]->name = line; for(int j = 0; j < 3; j++){ list[i]->order[j]-> name << costum; list[i]->order[j]-> item << costum; } } ofstream orderset;…arrow_forwardThe goal for this question: DISCLAIMER****** CODE MUST BE WRITTEN IN C CODE. NOT C++, C#, etc. To create a program that MUST utilize the functions (argc, argv, char strstr, and possibly even Getline) to, 1. Open a file 2. Read the file 3. Read txt file line by line 4. count up the number of times a specified word is read(HOWEVER! IT CANNOT COUNT MORE THAN ONE WORD PER LINE!) ex. if the code comes across a line in a text file that has the word cookie in it 3 times. It can only count the word ONCE since it is counting line by line. Not all the words added up. 5. then display to the user the total number of lines with the specific word. ex. gcc -o <program name> ./<program name> <file name.txt> <"word to be searched"> then execute a total number of times words came up. Again, only count up by one even if there is that specified word multiple times in one line.arrow_forwardWrite a short program that opens a binary data file, "data.dat" and prints the number of bytes that file contains Use fopen), fseek(), ftell), and fclose() functions in carrow_forward
- The following question is related to C programming system call Task-1: Write a c program that will open a file given from the command line argument and then it will ask the user to input strings that will be written to that file. It will continue to ask the user to enter a string as long as the user enters “-1”. If the given file does not exist in the directory, then your program will automatically create the file.arrow_forwardUsing only standard I/O functions (like fopen(), fseek(), ftell(), fgets(), etc.), write a C program to reverse the order of the lines in a text file. That is the first line becomes last, the second line becomes the one before the last one and so on. Note: your program should have two arguments, the input file name and the output file name. Call model: reverseFile Input file:HelloI am happy to see youOutput file:I am happy to see youHelloarrow_forwardC++:HexDump: Hello i need help with this task: I need a working code. Write a program that gives the user the name of a binary or text file and a desired one Queries the number of bytes and then outputs this number of bytes from the file.->The content of ten bytes in each line should first be output in hexadecimal and then decoded according to the ASCII table. For the ASCII string, make sure that the control characters in the file do not interfere with the formatting of the output. In the examples below, for example, a Tabulator as '¬' (\ xaa) and a line break as '╗' (\ xbb).-> The program should differentiate between binary and text files based on the file extension .txt.-> Functionality and required formatting can be seen in the two following examples. tabeltennis.dta TSV Auerbach @ V TV Buerstadt X : SV Crumstadt II l $ $ TSV Ernsthofen D S TSV Hoechst II [ 0 TTC Langen-Brombach < ^ SV Moerlenbach II 5 Z DJK/Scc Pfungstadt O N …arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr