Starting Out with C++ from Control Structures to Objects (8th Edition)
8th Edition
ISBN: 9780133769395
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 12, Problem 71RQE
Explanation of Solution
Syntax error:
An error which is occurred on the source code of a program is referred as “syntax error”; because the computer programs strictly follows the syntax rules, if the code fails to prove its language syntax format then the compiler will throw an error.
Purpose of the given code:
The purpose of the given code is to open the file “info.dat” using “fstream” file stream object.
List of errors present in the given code:
The code that is given contains some of the syntax error and it is listed as follows:
Error 1:
- The file open statement is an error in the given code.
- In c++, files can be opened using file stream object definition. In definition, the open statement contains two arguments such as file name and file access mode.
- The format for including the file access mode in file open statement as follow as:
- ios::out
- The scope resolution operator “::” is missing in the given file open statement.
Therefore the given file open statement is modified as:
fstream dataFile(“info.dat”, ios::out);
Error 2:
- The file written statement is an error in the given code...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Static length data types vary from dynamic length data types by their intended use.
in c language
typedef _people {
int age;
char name[ 32 ] ;
} People_T ;
People_T data [ 3 ];
Using string lib function, Assign 30 and Cathy to the first cell, Assign 40 and John to the second cell and Assign 50 and Tom to the third cell
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define NAME_LEN 25
#define MAX_PARTS 100
struct part {
int number;
char name[NAME_LEN + 1];
int on_hand;
double price;
} inventory[MAX_PARTS];
int num_parts = 0;
int find_part(int number);
void insert(void);
void search(void);
void update(void);
void print(void);
int read_line(char str[], int n);
int main(void)
{
char code;
for (;;) {
printf("Enter operation code: ");
scanf(" %c", &code);
while (getchar() != '\n') /* skips to end of line */
;
switch (code) {
case 'i': insert();
break;
case 's': search();
break;
case 'u': update();
break;
case 'p': print();
break;
case 'q': return 0;
default: printf("Illegal code\n");
}
printf("\n");
}
}
int find_part(int number)
{
int i;
for (i = 0; i < num_parts; i++)
if…
Chapter 12 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
Ch. 12.1 - Which file access flag would you use if you want...Ch. 12.1 - Prob. 12.2CPCh. 12.1 - Assuming diskInfo is an fstream object, write a...Ch. 12.1 - Assuming diskInfo is an fstream object, write a...Ch. 12.1 - Assuming diskInfo is an fstream object, write a...Ch. 12.1 - Write a statement that defines an fstream object...Ch. 12.5 - Assume the file input.txt contains the following...Ch. 12.5 - Describe the difference between reading a file...Ch. 12.5 - What will be stored in the file out.txt after the...Ch. 12.10 - Describe the difference between the seekg and the...
Ch. 12.10 - Describe the difference between the tellg and the...Ch. 12.10 - Describe the meaning of the following file access...Ch. 12.10 - What is the number of the first byte in a file?Ch. 12.10 - Briefly describe what each of the following...Ch. 12.10 - Describe the mode that each of the following...Ch. 12 - What capability does the fstream data type provide...Ch. 12 - Which file access flag do you use to open a file...Ch. 12 - Assume the file data.txt already exists, and the...Ch. 12 - How do you combine multiple file access flags when...Ch. 12 - Should file stream objects be passed to functions...Ch. 12 - Under what circumstances is a file stream objects...Ch. 12 - Under what circumstances is a file stream objects...Ch. 12 - Under what circumstances is a file stream objects...Ch. 12 - How do you read the contents of a text file that...Ch. 12 - What arguments do you pass to a file stream...Ch. 12 - What arguments do you pass to a file stream...Ch. 12 - Prob. 12RQECh. 12 - Prob. 13RQECh. 12 - How do you get the byte number of a files current...Ch. 12 - If a program has read to the end of a file, what...Ch. 12 - How do you determine the number of bytes that a...Ch. 12 - How do you rewind a sequential-access file?Ch. 12 - The _____ file stream data type is for output...Ch. 12 - If a file fails to open, the file stream object...Ch. 12 - The same formatting techniques used with...Ch. 12 - The _____ function reads a line of text from a...Ch. 12 - The ____________ member function reads a single...Ch. 12 - The ________member function writes a single...Ch. 12 - Prob. 24RQECh. 12 - __________ files contain data formatted as...Ch. 12 - Prob. 26RQECh. 12 - Prob. 27RQECh. 12 - The ___________ member function writes raw binary...Ch. 12 - The __________ member function reads raw binary...Ch. 12 - Prob. 30RQECh. 12 - In ___________ file access, the contents of the...Ch. 12 - In __________ file access, the contents of a file...Ch. 12 - The _____________ member function moves a files...Ch. 12 - The ___________ member function moves a files...Ch. 12 - The __________ member function returns a files...Ch. 12 - The ___________ member function returns a files...Ch. 12 - The __________ mode flag causes an offset to be...Ch. 12 - The __________ mode flag causes an offset to be...Ch. 12 - The ________ mode flag causes an offset to be...Ch. 12 - A negative offset causes the files read or write...Ch. 12 - Write a statement that defines a file stream...Ch. 12 - Write two statements that use a file stream object...Ch. 12 - Write two statements that use a file stream object...Ch. 12 - Write two statements that use a file stream object...Ch. 12 - Write a program segment that defines a file stream...Ch. 12 - Write code that opens the file data.txt for both...Ch. 12 - Write code that determines the number of bytes...Ch. 12 - The infoFile file stream object is used to...Ch. 12 - T F Different operating systems have different...Ch. 12 - T F fstream objects are only capable of performing...Ch. 12 - T F ofstream objects, by default, delete the...Ch. 12 - T F ifstream objects, by default, create a file if...Ch. 12 - T F Several file access flags may be joined by...Ch. 12 - T F A file may be opened in the definition of the...Ch. 12 - T F If a file is opened in the definition of the...Ch. 12 - T F A file stream objects fail member function may...Ch. 12 - T F The same output formatting techniques used...Ch. 12 - T F The operator expects data to be delimited by...Ch. 12 - T F The getline member function can be used to...Ch. 12 - T F It is not possible to have more than one file...Ch. 12 - T F Binary files contain unformatted data, not...Ch. 12 - T F Binary is the default mode in which files are...Ch. 12 - T F The tellp member function tells a file stream...Ch. 12 - T F It is possible to open a file for both input...Ch. 12 - fstream file(ios::in | ios::out);...Ch. 12 - ofstream file; file.open (info.dat, ios::tin); if...Ch. 12 - fstream file("info.dat"); if (!file) { cout ...Ch. 12 - fstream dataFile("info.dat", ios:in | ios:binary);...Ch. 12 - Prob. 69RQECh. 12 - fstream dataFi1e("info.dat", ios:in); char...Ch. 12 - Prob. 71RQECh. 12 - fstream inFile("info.dat", ios:in); int x;...Ch. 12 - File Head Program Write a program that asks the...Ch. 12 - File Display Program Write a program that asks the...Ch. 12 - Punch Line Write a program that reads and prints a...Ch. 12 - Tail Program Write a program that asks the user...Ch. 12 - Line Numbers (This assignment could be done as a...Ch. 12 - String Search Write a program that asks the user...Ch. 12 - Sentence Filter Write a program that asks the user...Ch. 12 - Array/File Functions Write a function named...Ch. 12 - File Encryption Filter File encryption is the...Ch. 12 - File Decryption Filter Write a program that...Ch. 12 - Prob. 11PCCh. 12 - Prob. 12PCCh. 12 - Inventory Program Write a program that uses a...Ch. 12 - Inventory Screen Report Write a program that reads...Ch. 12 - Average Number of Words If you have downloaded...Ch. 12 - Customer Accounts This program should be designed...
Knowledge Booster
Similar questions
- using access file in visual c#arrow_forwardC++ Write a program that will allow a user to enter students into a database. The student information should include full name, student ID, GPA and status. The program should allow delete any student based on student ID. You may not use a vector.arrow_forwardJSON Response example when code = BAHRAIN as follows: { "Country": "Bahrain", "Tenps"il ("day": "SUNDAY", "temp"i {"day": "HONDAY", "temp": 35), ("day": "TUESDAYr, "teng": 39), ("day": "WEDNESDAY", "tenp": 37),. ("day"i "THURSDAY", "tenp": 35), ("day"i "FRIDAV", "temp": 34), ("day": "SATURDAY", "teng": 37) 1. Implement find Templ ) function as follows: Sample Eample This function will be called whenever the user change the value of the pull-down menu. This function should contact Ve the Web Service API, sending the selected country code, to Co display the information (country, daily temperatures in the week and average weekly temperature) inside the div tag whose id -result as shown in the example on the right. Country ahraln In addition, the country name and the average temperatures should be saved as one JS object inside an array in a local storage. Whenever new request is made, the countrylaverage will be saved and added to the array inside the local storage (duplicates is allowed).…arrow_forward
- Template Code: #include #include #define TOTAL_COURSE 3 int main(void) { printf("Hello World!\n"); // You can delete this line. return 0; }arrow_forwardASSIGNMENT: Student Data Write a program that uses two structures Name and Student to store the following information for multiple students: 1. Create a NAME structure that consists of • First Name, • Middle Initial, and • Last Name. 2. Create a STUDENT structure that contains student information (Include the NAME structure within the Student information structure) o Name o ID o email • SSN • Program (an enum type containing programs such as CSCI, DBMS, INFM, SDEV)arrow_forwardIn C#, the data type a programmer can create is known as __ type. custom user-defined enumerated structuredarrow_forward
- in c language !! typedef struct {long restaurant_id;char restaurant_name[10];char description[120];double rate;char cuisine[30]; opening_year;long capacity;char city[30];char address[60];char owner[30];} RECORD_t, *RECORD; RECORD delete (unsigned long restaurant_id, RECORD *restaurant_array, unsigned long *p_size){int rec;int index;// index <- find the index of the RECORD with given restaurant_id in restaurant_array ????? (I DIDNT)if (index is valid)rec=restaurant_array[index];elserec=NULL;return rec;}arrow_forward8arrow_forwardwhat is Procedure-level array ?arrow_forward
- When a Course object is created, what is the value of the students pointer?arrow_forwardPython No hand written and fast answer with explanationarrow_forwardGame of Hunt in C++ language Create the 'Game of Hunt'. The computer ‘hides’ the treasure at a random location in a 10x10 matrix. The user guesses the location by entering a row and column values. The game ends when the user locates the treasure or the treasure value is less than or equal to zero. Guesses in the wrong location will provide clues such as a compass direction or number of squares horizontally or vertically to the treasure. Using the random number generator, display one of the following in the board where the player made their guess: U# Treasure is up ‘#’ on the vertical axis (where # represents an integer number). D# Treasure is down ‘#’ on the vertical axis (where # represents an integer number) || Treasure is in this row, not up or down from the guess location. -> Treasure is to the right. <- Treasure is to the left. -- Treasure is in the same column, not left or right. +$ Adds $50 to treasure and no $50 turn loss. -$ Subtracts…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrNp Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
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
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning