Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
9th Edition
ISBN: 9780134379319
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 13.7, Problem 13.32CP
Briefly describe what each of the following statements does.
file.seekp(100L, ios::beg);
file.seekp(-10L, ios::end);
file.seekg(-25L, ios::cur);
file.seekg(30L, ios::cur);
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a function, WriteFile(), that saves information to a text file. The function receives a string value (obtained from Question 3.2) that is written to the text file. The function does not return any value to the calling statement.Store the output text file as Output.txt.The output must be added on a new line to the text file each time without erasing any existing
The above functions (ReadFile(), Decode(), and WriteFile()) must now be implemented in the main program in the following order:1. Create a list of type character, i.e. the data type that is stored in the list is text.2. Read the contents of the file to the lists with ReadFile(). Display the number of lines that are read from the text file.3. Decode each card number with the Decode() function by passing the list to the function.4. As each card number is decoded, write the information to an output file with WriteFile(). The WriteFile() function should be called from within the Decode() function.
python only***
define the following functions;
Function 1. writeStringToFile(fileName, text): This function overwrites the contents of the file named fileName with the string text.
Must
Define writeStringToFile
Use def to define writeStringToFile
Use a open file expression
Within the definition of writeStringToFile, use open(___) or open(___, ___=_) in at least one place.
Use a file .write() call
Within the definition of writeStringToFile, use _.write(_) in exactly one place.
Function 2. readFirstLines(fileName, numLines): This function reads the first numLines lines of the file named fileName, returning them as a list of strings (each of which includes a terminating newline character, if there is one). If there are fewer than numLines lines in the file, returns a list of all the lines in the file.
Define readFirstLines
Use def to define readFirstLines
Use a open file expression
Within the definition of readFirstLines, use open(___) or open(___, ___=_) in…
Compiler returning errors. Screenshot of File.txt as well as compiler errors included.
//importing necessary header files
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
//writing a function to open the file and checking the file failure
bool openTheFile(ifstream& x,string fileName){
//open the file
x.open(fileName);
//if file doesnt open
if(x.fail())
{
//then return false
return false;
}
//otherwise returns true
return true;
}
//writing a function to read file and counting the number of integers,
//calculating sum and average of the given function*/
void calculateFile(ifstream& myFile,int& sum,int& total_num,double& average ){
//declaring variables
int count=0;
string output;
//checking end of file by using eof
while (!myFile.eof()) {
//displaying data
myFile >> output;
sum+=stoi(output);
//incrementing count variable
count++;
}
//assigning value of count variable to total_num
total_num = count;
//calculating…
Chapter 13 Solutions
Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
Ch. 13.1 - Name three different C++ classes that can be used...Ch. 13.1 - Name three different C++ classes that can be used...Ch. 13.1 - What is the purpose of the second parameter to the...Ch. 13.1 - Why is it important for a program to close an open...Ch. 13.1 - Which file open flag causes all output to take...Ch. 13.1 - Which file open flag causes the contents of an...Ch. 13.1 - What happens if ios: :out is used by itself to...Ch. 13.1 - What happens if ios::out is used by itself to open...Ch. 13.1 - Write a sequence of C++ statements that reads in...Ch. 13.1 - Write a sequence of C++ statements that reads in...
Ch. 13.1 - Show how to use the constructor of the fstream...Ch. 13.1 - Consider two parallel arrays of the same size, one...Ch. 13.3 - Make the required changes to the following program...Ch. 13.3 - Describe the purpose of the eof member function.Ch. 13.3 - Assume the file input.txt contains the following...Ch. 13.3 - Describe the difference between reading a file...Ch. 13.3 - Describe the difference between the getline...Ch. 13.3 - Describe the purpose of the put member function.Ch. 13.3 - What will be stored in the file out.dat after the...Ch. 13.3 - The following program skeleton, when complete,...Ch. 13.5 - Write a short program that opens two files...Ch. 13.5 - How would the number 479 be stored in a text file?...Ch. 13.5 - Describe the differences between the write member...Ch. 13.5 - What arc the purposes of the two arguments needed...Ch. 13.5 - What are the purposes of the two arguments needed...Ch. 13.5 - Describe the relationship between fields and...Ch. 13.5 - Prob. 13.27CPCh. 13.7 - Describe the difference between the seekg and the...Ch. 13.7 - Describe the difference between the tellg and the...Ch. 13.7 - Describe the meaning of the following file access...Ch. 13.7 - What is the number of the first byte in a file?Ch. 13.7 - Briefly describe what each of the following...Ch. 13.7 - Describe the mode that each of the following...Ch. 13 - Prob. 1RQECh. 13 - Before a file can be used, it must first beCh. 13 - When a program is finished using a file, it shouldCh. 13 - The__________ header file is required for file I/O...Ch. 13 - Prob. 5RQECh. 13 - The_____________ file stream data type is for...Ch. 13 - The____________ file stream data type is for input...Ch. 13 - The ______ file stream data type is for output...Ch. 13 - Write a statement that defines a file stream...Ch. 13 - Write a statement that defines a file stream...Ch. 13 - Write a statement that defines a file stream...Ch. 13 - Write two statements that use the people file...Ch. 13 - Write two statements that use the pets file stream...Ch. 13 - Write two statements that use the places file...Ch. 13 - If a file fails to open, the file stream object...Ch. 13 - Write a program segment that defines a file stream...Ch. 13 - The same formatting techniques used with ______...Ch. 13 - The ______ member function reports when the end of...Ch. 13 - The ______ function reads a line of text from a...Ch. 13 - The _______ member function reads a single...Ch. 13 - The _____ member function writes a single...Ch. 13 - Prob. 22RQECh. 13 - Prob. 23RQECh. 13 - Prob. 24RQECh. 13 - In C++, _______ provide a convenient way to...Ch. 13 - The _______ member function writes raw binary data...Ch. 13 - The _______ member function reads raw binary data...Ch. 13 - The ______ operator is necessary if you pass...Ch. 13 - In _______ file access, the contents of the file...Ch. 13 - In _____ file access, the contents of a file may...Ch. 13 - The _______ member function moves a files read...Ch. 13 - The ______ member function moves a files write...Ch. 13 - The _______ member function returns a files...Ch. 13 - The _______ member function returns a files...Ch. 13 - The ______ mode flag causes an offset to be...Ch. 13 - The ______ mode flag causes an offset to be...Ch. 13 - The ______ mode flag causes an offset to he...Ch. 13 - A negative offset causes the files read or write...Ch. 13 - Give a pseudocode algorithm for determining the...Ch. 13 - Give a pseudocode algorithm for comparing two...Ch. 13 - Prob. 41RQECh. 13 - Suppose that you have two text files that contain...Ch. 13 - Each of the following programs or program segments...Ch. 13 - File Previewer Write a program that asks the user...Ch. 13 - File Display Program Write a program that asks the...Ch. 13 - Punch Line Write a program that reads and prints a...Ch. 13 - Tail of a File Write a program that asks the user...Ch. 13 - String Search Write a program that asks the user...Ch. 13 - Sentence Filter A program that processes an input...Ch. 13 - File Encryption Filter File encryption is the...Ch. 13 - File Decryption Filter Write a program that...Ch. 13 - Letter Frequencies The letter e is the most...Ch. 13 - Put It Back C++ input stream classes have two...Ch. 13 - Prob. 11PCCh. 13 - Insertion Sort on a File II Modify the program...Ch. 13 - Prob. 13PCCh. 13 - Prob. 14PCCh. 13 - Inventory Program Write a program that uses a...Ch. 13 - Inventory Program Write a program that uses a...Ch. 13 - Group Project 17. Customer Accounts This program...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
List the five major components of a computer system.
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Revise the loop shown in Listing 4.6 to use a break statement instead of the boolean variable areMore. Comment ...
Java: An Introduction to Problem Solving and Programming (8th Edition)
The method getValueFromFile is public and returns an int. It accepts no arguments. The method is capable of thr...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
What are some features of specific programming languages you know whose rationales are a mystery to you?
Concepts of Programming Languages (11th Edition)
Repair Bill Suppose automobile repair customers are billed at the rate of per hour for labor. Also, suppose co...
Introduction To Programming Using Visual Basic (11th Edition)
Word Separator Write a program that accepts as input a sentence in which all of the words are run together, but...
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Suppose that infile is an ifstream variable and employee.dat is a file that contains employees’ information. Write the C++ statement that opens this file using the variable infile.arrow_forwardComputer Science Create a function that can find the largest writable and non-writable file by the user in a directory without subdirectories (flat directory). This function will be part of a program named maxfile that can be invoked like this: ./maxfile <directory> You will be reading the contents of the directory passed as the only argument to your program using the function readdir(). Begin by opening the directory using opendir(), and obtain information for every file using stat(). stat() allows you to check whether a file is a regular file or a directory. (In this assignment, hard and symbolic links, special files, etc. will be ignored.) At the end, close the directory using closedir(). For Functionality 1, the input will be assumed to be a flat directory and subdirectories should not be traversed. Regular files must be separated into those for which the user has permission to write and those for which the user does not have permission to write. For each of the two types…arrow_forwardChapter 4. PC #14. Line Numbers (page 265) Write a program that asks the user for the name of a file. The program should display the contents of the file with each line preceded with a line number followed by a colon. The line numbering should start at 1. Test Case 1 Please enter the file name or type QUIT to exit:\nquitENTER Test Case 2 Please enter the file name or type QUIT to exit:\nbadfilename.txtENTERFile: badfilename.txt does not exist.\nPlease enter the file name again or type QUIT to exit:\nquitENTER Test Case 3 Please enter the file name or type QUIT to exit: \ninput1.txt ENTER1: a\n2: b\n3: c\n4: d\narrow_forward
- 1. (Practice) Enter the data for the info.txt file in Figure 9.1 or download it from this book’s Web site. Then enter and execute Program 9.5 and verify that the backup file was written. 2. (Modify) Modify Program 9.5 to use a getline() function in place of the get()method currently in the program. =============1 - 9.1========== #include <iostream>#include <fstream>#include <cstdlib> // needed for exit()#include <string>using namespace std; int main(){string fileOne = "info.txt"; // put the filename up frontstring fileTwo = "info.bak";char ch;ifstream inFile;ofstream outfile;try //this block tries to open the input file{// open a basic input streaminFile.open(fileOne.c_str());if (inFile.fail()) throw fileOne;} // end of outer try blockcatch (string in) // catch for outer try block{cout << "The input file " << in<< " was not successfully opened." << endl<< " No backup was made." << endl;exit(1);}try // this block tries to…arrow_forwardChapter 4. PC #14. Line Numbers (page 265) Write a program that asks the user for the name of a file. The program should display the contents of the file with each line preceded with a line number followed by a colon. The line numbering should start at 1.arrow_forward...ex2_main.cpp#include <stdio.h>#include <stdlib.h>#include "lab2_ex2.h" #define FILENAME "statement11.txt" int main(){ // 1. Acquire the text from file char *text = read_text_file(FILENAME); // Note: Caller should free the memory allocated printf("%s\n", text); // 2. Compute the readability and display the grade level float readability = get_readability(text); printf("Readability index = %f\n", readability); display_level(readability); // 3. Free resources, e.g. allocated memory by read_text_file() function free(text); return 0;}...lab2_ex2.cpp/* EDIT THIS FILE TO SOLVE THE LABORATORY EXERCISES*/ #include <stdio.h>#include <ctype.h>#include <string.h>#include <math.h>#include <stdlib.h>#include "lab2_ex2.h" /*Assume that a letter is any lowercase character from a to zor any uppercase character from A to Z*/int alpanumeric_count(const char *text){ int count = 0; /* YOUR CODE HERE!!! */ return…arrow_forward
- 1-) Write a code to do following operationsa-print the contents of filewrite a function to print the contents of a given file on screen. Your function prototypeshould be in given format.void PrintFileContent(FILE* fptr)b-copy contents of one file to another filewrite a function to copy contents of one file to another file. Convert all characters intouppercase while copying the content. You are allowed to use toupper() function in ctypelibrary. Your function prototype should be in given format.void copy_file(FILE* fptr1,FILE* fptr2)c- count the Number of Characters in a Filewrite a function to count the Number of Characters in a File. Your function prototypeshould be in given format.int findNumberofChar(FILE* fptr)Please design your main.c file as follow1- Open a text file to read in your directory.2- Create an empty text file for writing and reading in same directory.3- Check if both files are opened.4- Print the contents of first file by calling PrintFileContent function.5- Call…arrow_forwardQuestion 55 Write a function that takes two parameters, a file name to create and an integer. The function should write all the even numbers between 0 and the integer to the file name passed in. The numbers should be all on one line of the file For example: write_evens("even_file.txt",20) This should create a file called even_file.txt that contains 0 2 4 6 8 10 12 14 16 18 20 Full explain this question and text typing work only thanksarrow_forwardassume the file data.dat contains a sequence of binary data. write a program that does the following: displays the first 5 bytes stored in the file. each byte should be displayed on a separate line. starting with byte 0, displays every even-numbered byte in the file. (in other words, display byte 0, byte 2, byte 4, and so on.) each byte should be displayed on a separate line. starting with byte 1, displays every odd-numbered byte in the file. (in other words, display byte 1, byte 3, byte 5, and so on.) each byte should be displayed on a separate line. displays the last 5 bytes stored in the file, in reverse order. (display the last byte, then the next-to-last byte, and so on.) each byte should be displayed on a separate line. handle exceptions in the following manner: if a filenotfoundexception is thrown, the program should display the string "file error". if an eofexception is thrown, the program should display the string "eof error". if any other exception is thrown, the program…arrow_forward
- The_______________ directive inserts a file in another file.arrow_forwardexampleOne This program reads data from a physical file, create a reference to the file, perform a computation, display the result, close the file. package chario; import java.util.Scanner; import java.io.*; //public class Chario { // public static void main(String[] args) throws IOException { File file1 = new File("fileOne.txt"); //Create a reference to the physical file /* Use Notepad to create a text file named fileOne.txt which must be in the same directory that src is in To find src, open your project in NetBeans and hover its name, which is in the top left just below the Projects menu; this will display the path to your project My project path is, yours will be different I:\\Ajava\161\WPPractice\IO\charstream\chario My fileOne.txt is located in chario */ Scanner getit = new Scanner( file1 ); // connect a Scanner to the file int num, square; num = getit.nextInt(); square = num * num ; System.out.println("The square of " + num + " is " + square); getit.close(); //Close the stream…arrow_forwardAssuming default declaration types for all variables. A file has the following data: 2 4 −5 8 0 −1 Given the code below: do read (1,*, iostat=i) a if (i<0) exit if (i>0) stop if (a<0) cycle c=c+1 end do print*, c end What is the output of the program when executed? Question 12 options: none of the given choices 6 2 Syntax error message when compiled 3 Run-time error message 4arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C - File I/O; Author: Tutorials Point (India) Ltd.;https://www.youtube.com/watch?v=cEfuwpbGi1k;License: Standard YouTube License, CC-BY
file handling functions in c | fprintf, fscanf, fread, fwrite |; Author: Education 4u;https://www.youtube.com/watch?v=aqeXS1bJihA;License: Standard Youtube License