Question

In: Computer Science

C++ 19.Which of the following headers is required for reading from and writing to disk files?...

C++

19.Which of the following headers is required for reading from and writing to disk files?

#include <ifstream>

#include <fstream>

#include <iostream>

#include <ofstream>

20.Which of the following options is the correct way to call the open function on an ifstream object named ifstr?

ifstr.open("data.txt")

ifstr.open("data", ".txt")

ifstr.open("data.txt", "read")

ifstr.open()

24. What is wrong with the following function definition?

void erase_file(ifstream infile, ofstream outfile)
{
   char ch;
   while (infile.get(ch))
   {
      outfile << ch;
   }
}

The ifstream and ofstream parameters must be reference parameters.

The function does not read an end of line character to terminate the while loop.

The output from the function does not display all of the characters in the file.

The ifstream and ofstream parameters must be pointers.

35.What is the output from the following code snippet?

int main() 
{
   for (int i = 100; i < 106; i = i + 2)
   {
      ostringstream oss;
      oss << "base-" << setw(3) << i;
      cout << oss.str() << endl;
   }
}

base-100base102base104base106

base-

base-

base-

base

base-100

base-102

base-104

base-106

base-100

base-102

base-104

37.What is the problem with the following code snippet?

double* acc_ptr;
*acc_ptr = 1000;

The acc_ptr variable is never initialized.

There is no problem.

The second statement assigns an integer to a pointer.

There is a compilation error.

51.What is the difference between a dynamically allocated array and an array variable?

The dynamically allocated array must be declared with the "dynamic" keyword.

The dynamically allocated array must have a fixed size when it is declared. The array variable can have a dynamic size, determined at run-time.

The dynamically allocated array cannot be declared with the "const" keyword.

The array variable must have a fixed size when it is declared. The dynamically allocated array can have a size determined at run-time.

Solutions

Expert Solution

19.Which of the following headers is required for reading from and writing to disk files?

#include <ifstream>

[correct]#include <fstream>

#include <iostream>

#include <ofstream>

20.Which of the following options is the correct way to call the open function on an ifstream object named ifstr?

ifstr.open("data.txt")

ifstr.open("data", ".txt")

[correct]ifstr.open("data.txt", "read")

ifstr.open()

24. What is wrong with the following function definition?

void erase_file(ifstream infile, ofstream outfile)
{
   char ch;
   while (infile.get(ch))
   {
      outfile << ch;
   }
}

The ifstream and ofstream parameters must be reference parameters.

The function does not read an end of line character to terminate the while loop.

The output from the function does not display all of the characters in the file.

The ifstream and ofstream parameters must be pointers.

35. What is the output from the following code snippet?

int main() 
{
   for (int i = 100; i < 106; i = i + 2)
   {
      ostringstream oss;
      oss << "base-" << setw(3) << i;
      cout << oss.str() << endl;
   }
}

Output-

base-100
base-102
base-104

37.What is the problem with the following code snippet?

double* acc_ptr;
*acc_ptr = 1000;

The acc_ptr variable is never initialized.

[correct]There is no problem.

The second statement assigns an integer to a pointer.

There is a compilation error.

51.What is the difference between a dynamically allocated array and an array variable?

The dynamically allocated array must be declared with the "dynamic" keyword.

The dynamically allocated array must have a fixed size when it is declared. The array variable can have a dynamic size, determined at run-time.

The dynamically allocated array cannot be declared with the "const" keyword.

[correct]The array variable must have a fixed size when it is declared. The dynamically allocated array can have a size determined at run-time.


Related Solutions

IN C++ PLEASE. Use ONLY: exception handling, read and write files, arrays, vectors, functions, headers and...
IN C++ PLEASE. Use ONLY: exception handling, read and write files, arrays, vectors, functions, headers and other files, loops, conditionals, data types, assignment.   Calculating fuel economy. This program will use exceptions and stream errors to make a robust application that gets the number of miles and gallons each time the user fuels their car. It will put those values into vectors. Once the user wants to quit enter values, it will calculate the fuel economy. Create GetMiles() function that returns...
which tips about reading and writing from the readings have you used specifically in your writing...
which tips about reading and writing from the readings have you used specifically in your writing process?
Code the following in C++ and make sure to include all three files required at the...
Code the following in C++ and make sure to include all three files required at the end. Hotdogs – The World’s Greatest Cost Effective Wholesome Nutritious Food Due to world food supply scarcity and the burgeoning populations of the world’s countries, your hot stand business is globalizing to satisfy the world’s desire for a cost effective wholesome nutritious food source. Market studies have shown that tens of billions of people are craving for the eponymous hotdog which will result in...
Develop a report that includes the following sections: (Use the required sections as headers in your...
Develop a report that includes the following sections: (Use the required sections as headers in your report.) Section I: Overview Provide a general overview of QuickBooks. Make sure the overview provides the reader with a general understanding of the application, including costs, functionality and minimum system requirements. Section II: Transactional Processing and Data Management Describe how QuickBooks handles processing the accounting transactions and recording business activities for the revenue, expenditure and financing cycles. You should provide at least one detailed...
I am Writing a C-Program to read and write files. but none of my code is...
I am Writing a C-Program to read and write files. but none of my code is working like it should be. Please fix all code and supply output response. Please try to use existing code and code in comments. But if needed change any code that needs to be changed. Thank you in advance //agelink.c //maintains list of agents //uses linked list #include <stdio.h> #include <stdlib.h> #define TRUE 1 void listall(void); void newname(void); void rfile(void); void wfile(void); struct personnel {...
In this task, you will create a Python script in which you will practice reading files...
In this task, you will create a Python script in which you will practice reading files in Python and writing them to a new output file. Construct a text file called Py4_Task3_input.txt that has the following lines: 4 Sandwiches 04 July 2020 Pasta 31 October 2014 Hot Dogs 15 November 2005 Tacos 25 December 1986 The first line of the file represents the number of lines in the data file. Write a loop that reads in each additional line (one...
In C++, develop a menu program which reads in data from 4 different input files -...
In C++, develop a menu program which reads in data from 4 different input files - appetizers, entrees, desserts, and drinks. Then, record the item information ordered by the customer for each item selected. When finished, display all items ordered to the screen with the subtotal, tax (10% for easy math), and the total. Be sure to get tip as well. Then, ensure enough payment was received before generating an output file receipt which can be printed off. Use functions...
Write a Python program that uses function(s) for writing to and reading from a file: a....
Write a Python program that uses function(s) for writing to and reading from a file: a. Random Number File Writer Function Write a function that writes a series of random numbers to a file called "random.txt". Each random number should be in the range of 1 through 500. The function should take an argument that tells it how many random numbers to write to the file. b. Random Number File Reader Function Write another function that reads the random numbers...
PLEASE DO IN C# Warehouse Inventories Objective: Work with multiple objects and review reading data files....
PLEASE DO IN C# Warehouse Inventories Objective: Work with multiple objects and review reading data files. Description: A wholesale distributor has six warehouses (Atlanta, Baltimore, Chicago, Denver, Ely and Fargo) and sells five different items (identified by part number: 102, 215, 410, 525 and 711). Each warehouse may stock any or all of the five items. The company buys and sells these items constantly. Company transaction records contain a transaction code (‘P’ for a purchase or ‘S’ for a sale)...
Python - files: find a solution for each following: -Open the file hostdata.txt for reading. -Store...
Python - files: find a solution for each following: -Open the file hostdata.txt for reading. -Store four file objects corresponding to the files winter2003.txt , spring2003.txt, summer2003.txt, and fall2003.txt in the variables winter, spring, summer, and fall (respectively), and open them all for reading. -Write a statement to open the file yearsummary.txt in a way that erases any existing data in the file. -Use the file object output to write the string "3.14159" to a file called pi. -A file...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT