C++ for Engineers and Scientists
4th Edition
ISBN: 9781133187844
Author: Bronson, Gary J.
Publisher: Course Technology Ptr
expand_more
expand_more
format_list_bulleted
Question
Chapter 8.4, Problem 2E
Program Plan Intro
- Include library files for various operations.
- Declare required variables.
- Declare object of ifstream.
- Declare function header, fcheck()with object of ifstream as a formal parameter.
- Declare afunctionfcheck()to check that the file exits or not.
- Useif statement to check that the file exist.
- Open the file, by using open() method.
- int main() function is used to perform all the tasks.
- Display the calculated results to the user.
Program Description: The main purpose of the program is to declare a function, fcheck()to check that the given file exits or not and if the file exist, then function should return 1 otherwise it will return 0.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(FRP7) Write a function that reads data from a file. The file has already been opened and verified. The data should be saved in the array of type ship. The size of the array is passed in the int parameter and the number of records read is return in the last parameter, by reference. The file should be read until end of file has been reached or the array is full.
struct ship{ string shipCaptain; string shipName;
};
The function prototype isvoid readFile( ifstream&, ship[ ], int, int& );
ifstream - The already open file
ship[ ] - array of structs where the data from the file will be stored.
int - the size of the array.
int& - the number of records read from the file. This value is set by the function before returning
return- the number of records read from the file, returned by the function.
The amount of data in the file is unknown but there is no bad data. The file format is the shipsName followed by the shipsCaptiain .
Example:
MillenniumFalcon HansSolo
(C#)The following statement declares a StreamReader object variable called "inputFile". Which statement opens a file named "data.txt" to the StreamReader object?StreamReader inputFile;
Question 10 options:
inputFile = open("data.txt");
inputFile = OpenFile("data.txt");
inputFile = File.OpenFile("Data.txt");
inputFile = File.OpenText("Data.txt");
(C++ Language)
Create a function that writes to a file named Inventy.txt the information of 8 items. Ask the user for the item's name, the item's quantity in storage, and the item's price and write it to the file. Create a function that reads the file and items' quantity and price to two different arrays. Create a function that computes the subtotal of each item. Implement all functions inside the main program and the computed value should be displayed with the item's name.
Chapter 8 Solutions
C++ for Engineers and Scientists
Ch. 8.1 - Prob. 1ECh. 8.1 - (Practice) a. Write a set of two statements...Ch. 8.1 - Prob. 3ECh. 8.1 - Prob. 4ECh. 8.1 - Prob. 5ECh. 8.1 - Prob. 8ECh. 8.1 - Prob. 9ECh. 8.1 - Prob. 10ECh. 8.2 - Prob. 1ECh. 8.2 - (Practice and modify) a. Enter and run Program...
Ch. 8.2 - (Practice and modify) a. Write a C++ program that...Ch. 8.2 - (Practice) Determine the OS command or procedure...Ch. 8.2 - Prob. 5ECh. 8.2 - (Data processing) a. Write a C++ program that...Ch. 8.2 - Prob. 7ECh. 8.2 - Prob. 8ECh. 8.2 - Prob. 9ECh. 8.3 - Prob. 1ECh. 8.3 - Prob. 2ECh. 8.3 - Prob. 3ECh. 8.3 - Prob. 4ECh. 8.3 - Prob. 5ECh. 8.3 - Prob. 6ECh. 8.4 - Prob. 1ECh. 8.4 - Prob. 2ECh. 8.4 - Prob. 3ECh. 8.4 - Prob. 4ECh. 8.5 - (Practice) Write a C++ program to create the...Ch. 8.5 - Prob. 2ECh. 8.5 - Prob. 3ECh. 8.5 - Prob. 4ECh. 8.5 - Prob. 5ECh. 8 - Prob. 1PPCh. 8 - (Data processing) a. Store the following data in a...Ch. 8 - (Data processing) Write a C++ program that allows...Ch. 8 - (Data processing) Write a C++ program that permits...Ch. 8 - (Data processing) Write a C++ program that reads...Ch. 8 - (Data processing) Write a C++ program that reads...Ch. 8 - Prob. 7PPCh. 8 - (Data processing) A bank’s customer records are to...Ch. 8 - (Inventory) Create an ASCII file with the...
Knowledge Booster
Similar questions
- DO NOT WRITE MAIN! Only write the function. A 50% minimum deduction will be made if main is included. No libraries or comments should be specified. (OP4) Write a function to prompt the user for the filename, open the file, and verify that it opened. If the file does not open, an error message should be printed and the user re-prompted. The function should use the string passed in for the prompt string. The function should not return until the file is open. The function prototype: void openInputFile( ifstream &, string ); ifstream& - the stream to be opened. string - the prompt to be written out to the user. Use this string when prompting the user.arrow_forward(C Language) Write a program that reads movie data from a CSV (comma separated values) file and output the data in a formatted table. The program first reads the name of the CSV file from the user. The program then reads the CSV file and outputs the contents according to the following requirements: Each row contains the title, rating, and all showtimes of a unique movie. A space is placed before and after each vertical separator ('|') in each row. Column 1 displays the movie titles and is left justified with a minimum of 44 characters. If the movie title has more than 44 characters, output the first 44 characters only. Column 2 displays the movie ratings and is right justified with a minimum of 5 characters. Column 3 displays all the showtimes of the same movie, separated by a space.arrow_forwardProgramming Language: C++ 2. Which of the following are true for default arguments? Select one or more: a. They should be placed in both the prototype and function header. b. They should be placed in the function header only if there is no prototype c. Any of the function parameters may or may not have default arguments. d. The parameters with default arguments must come last (to the right) of the ones that don't have default arguments. e. Default arguments can be either variables or constantsarrow_forward
- (python) Write a function sum_file(f) that takes a filename f. Each line in f contains a single number. You should write to the last line in the file the sum of all the numbers written in the file.arrow_forwardIn C++ Language (please use hint) : Write a function which will swap its arguments if the first argument is greater than its second argument, but will not interchange them if the first argument is samller than or equal to the second argument. The function should return 1 if a swap was made, and 0 otherwise. (Hint: Make sure to use call by reference.) Write also a short test driver (i.e. a main() invoking your function).arrow_forward(USING PYTHON) create a function create employee_objects that takes a list of data as input and returns back a list with each element as an object that belongs to class Employee def create employee_objects (data): #start of code # end of code employees_list = create employee_objects (employees_data) Expected output: 29arrow_forward
- -Write a C++ program with the following functions, with the correct number of arguments for each function, as well as any other functions used in class. void fillUpArray ( argument1, argument2) This function should read in a text file called "theVillagers.txt" (You may download it on Canvas). "theVillagers.txt" is a text file of numbers in ascending order, ranging anywhere from 1 to 2500, nonrepeating. Each number is separated by a new line character. The very first number in the text file is a number that refers to how many entries are in the rest of the text file. This function should populate an array with all the remaining entries in the text file, but it should NOT declare any arrays itself and it should not reference any global variables. void getInput(argument1, argument2) This function should read in a text file of the user's choosing into a given array. It should discard excess input. You may assume that there are always 2000 entries in this text file being entered. void…arrow_forward(In C++ Pls) This program should be designed and written by a team of students. Here are some suggestions: You may work on a single class. The parameter and return type s of each function and class member function should be decided in advance. The program will be best implemented as a multi-file program, (header file, the main program,..) You need to print all output to an output file and submit it to the instructor during the final exam. Design a generic class to hold the following information about a bank account: Balance Number of deposits this month Number of withdrawals Annual Interest Rate Monthly service charges The class should have the following member function: Constructors Accepts arguments for the balance and annual interest rate. deposit a virtual function that accepts an argument for the amount of the deposit. The function should add the argument to the account balance. It should also increment the variable holding the…arrow_forwardDiscussion: Files with .h extension are called header files in C. These header files generally contain function declarations which we can be used in main C program, like for e.g. to include stdio.h in C program to use function printf() Exercise 2. Creating myhead.h : Write the below code and then save the file as myhead.h or you can give any name but the extension should be .h indicating it’s a header file. // It is not recommended to put function definitions // in a header file. Ideally there should be only // function declarations. Purpose of this code is // to only demonstrate working of header files. void add(int a, int b) { printf("Added value=%d\n", a + b); } void multiply(int a, int b) { printf("Multiplied value=%d\n", a * b); } Including the .h file in other program : Now as we need to include stdio.h as #include in order to use printf() function. We will also need to include the above header file myhead.h as #include”myhead.h”. The ” ” here are used to instruct…arrow_forward
- (USING PYTHON) create a function create employee_objects that takes a list of data as input and returns back a list with each element as an object that belongs to class Employee def create employee_objects (data): # start of code # end of code employees_list = create_employee_objects (employees_data) Expected output: 29|arrow_forward(IN PYTHON) Problem 1 Write a function word_count() that performs the following actions: Opens a file called “novel.txt”. You can assume that the file exists and is located in the same directory as your code file. Reads in the contents of the file, and stores it in a variable called text. Uses the split() function to obtain a list containing all of the individual words in text. For details on how to use split(), you can consult this site: https://www.w3schools.com/python/ref_string_split.asp For this question, assume that all words will be separated by spaces. Returns the number of words in the lisarrow_forwardUnder what circumstances can you successfully return a pointer from a function?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education