Question

QUESTION 6 To determine whether a file was opened successfully, the program can use the fstream...

QUESTION 6

  1. To determine whether a file was opened successfully, the program can use the fstream function:

    Hint: google

    fail()

    open()

    close()

    eof()

10 points   

QUESTION 7

  1. Which of the following are correct ways to end a loop using a test for end-of-file?

    (Two correct answers)

    inStream.get(next);
    while(!inStream.eof( ))
    {
    cout << next;
    inStream.get(next);
    }

    while(inStream->next)
      {
    cout << next;
    }

    inStream.get(next)
    while(!eof(inStream))
    {
    cout << next;
    inStream.get(next);
    }

    while(inStream >> next)
      cout << next;

10 points   

QUESTION 8

  1. Which statement is incorrect?

    cin is an input stream

    An output stream flows from your program to somewhere outside the program, either to a file or to some device such as the screen

    An input stream is a stream of data flowing from your program, either to a file, or to the keyboard

    A stream is a flow of data into or out of your program

10 points   

QUESTION 9

  1. Which of the following sets of statements will set floating point output to the stream outStream to fixed point with set 3 places of decimals?

    (Two correct answers)

    outStream.setf(ios::fixed);
    outStream.setf(ios::showpoint);
    outStream.precision(2);

    outStream.setf(ios::fixed | ios::showpoint);
    outStream << setprecision(2);

    outStream << setflag(ios::fixed);
    outStream << setflag(ios::showpoint);
    outStream << setprecision(2);

    outStream.flags(ios::fixed);
    outStream.flags(ios::showpoint);
    outStream.precision(2);

10 points   

QUESTION 10

  1. Which statement is incorrect?

    A file is automatically closed when a program terminates, so there is never a need to close a file

    The flush function copies the file buffer to the file on the file medium (disk, etc)

    When you use the open member function to tie a file name to a file stream, the file name is called the external file name, the program refers to the file by the stream variable used to open the file

    When you write

    ifstream inStream;
    inStream.open("infile.dat");

    the file infile.dat must be located in the directory where the program is being run

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 6: fail()

Explanation: fail() function used to identify whether file is opened successfully. open is used for opening a file, close is used for closing a file and eof() is used for checking eof file.

Answer 7: Correct answer is a, d.

Explanation: You can iterate over file till eof() is reached. You move to next token using .get function.

Also file pointer can be used as reading next token from the file till eof.

Answer 8: C

Explanation: Incorrect answer was C. Input Stream is is always coming inside from file or keyboard.

Others were correct sentence. Cin is input stream. Output stream flows out from your program. Stream is flow of data in and out of the program.

Answer 9: a, b

Explanation: fixed and showpoint can be applied to output stream using setf separately and within the same setf using | operator. Then setprecision is sued to set the precision to 2 decimal point.

Answer 10: A

Explanation: When program terminates , file does not close automatically and file handle will remain open which corrupt the file. So you have to close the file explicitly.

Add a comment
Know the answer?
Add Answer to:
QUESTION 6 To determine whether a file was opened successfully, the program can use the fstream...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Programming question For this exercise, you will receive two string inputs, which are the names...

    C++ Programming question For this exercise, you will receive two string inputs, which are the names of the text files. You need to check if the input file exists. If input file doesn't exist, print out "Input file does not exist." You are required to create 4 functions: void removeSpace (ifstream &inStream, ofstream &outStream): removes white space from a text file and write to a new file. If write is successful, print out "Text with no white space is successfully...

  • Need to check if File is successfully opened? C++ It works when I input the right...

    Need to check if File is successfully opened? C++ It works when I input the right txt file. But, it keeps stating, File successfully open." even I put in a non-existing file. Here are the specifications: Develop a functional flowchart and then write a C++ program to solve the following problem. Create a text file named first.txt and write your first name in the file. You will be reading the name of the file from the keyboard as a string,...

  • c++ program that prints joke and its punchline

    nothing happens when I replace the skeleton code. the program runs but it does not give me the desired results. All the question marks must be removed and filled in with the appropriate code.// Function prototypesvoid displayAllLines(ifstream &infile);void displayLastLine(ifstream &infile);int main(){// Arrays for file nameschar fileName1[SIZE];char fileName2[SIZE];// File stream objectsifstream jokeFile;ifstream punchlineFile;// Explain the program to the user.cout << "This program will print a joke "<< "and its punch line.\n\n";// Get the joke file name.cout << "Enter the name of...

  • Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment...

    Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath> header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by...

  • Use the file processing example program shown at the bottom. Modify the program to enter the...

    Use the file processing example program shown at the bottom. Modify the program to enter the grades, and count number of grades. Also get total and average grade. Use the following data for grades: 79, 99, 85, 97, 88, 95, 100, 87, 94 EXAMPLE OUTPUT Total: 9 grades Total grade sum: 824 Average grade: 92 Letter grade: A / Using Break, and Continue #include "stdafx.h" #include using namespace std; int main() { int i = 0; for (int x =...

  • 4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std;...

    4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std; int main() { string playerName; cout << "Enter name"; cin >> playerName; cout << endl « playerName; return 0; } a. Tom - Sawyer b. Tom Sawyer c. Tom d. Sawyer 5) Which XXX generates "Adam is 30 years old." as the output? #include <iostream> using namespace std; int main() { string name = "Adam"; int age = 30; XXX return 0; } a....

  • I need help debugging this C++ prgram. What Am i doing wrong? //******************************************************** // This program...

    I need help debugging this C++ prgram. What Am i doing wrong? //******************************************************** // This program reads two input files whose lines are //ordered by a key data field. This program should merge //these two files, writing an output file that contains //all lines from both files ordered by the same key field. // //********************************************************* #include <iostream> #include<string> #include<fstream> //prototype void mergeTwoFiles (ifstream&,ifstream&, ofstream&); using namespace std; int main() {string inFile1,inFile2,outFile; // input and output files ifstream in1; ifstream in2;...

  • #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int...

    #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int charcnt(string filename, char ch); int main() { string filename; char ch; int chant = 0; cout << "Enter the name of the input file: "; cin >> filename; cout << endl; cout << "Enter a character: "; cin.ignore(); // ignores newline left in stream after previous input statement cin.get(ch); cout << endl; chcnt = charcnt(filename, ch); cout << "# of " «< ch« "'S:...

  • can you please split this program into .h and .cpp file #include <iostream> #include<string> #include<fstream> #define...

    can you please split this program into .h and .cpp file #include <iostream> #include<string> #include<fstream> #define SIZE 100 using namespace std; //declare struct struct word_block {    std::string word;    int count; }; int getIndex(word_block arr[], int n, string s); int main(int argc, char **argv) {    string filename="input.txt";    //declare array of struct word_block    word_block arr[SIZE];    int count = 0;    if (argc < 2)    {        cout << "Usage: " << argv[0] << "...

  • A. File I/O using C library functions File I/O in C is achieved using a file...

    A. File I/O using C library functions File I/O in C is achieved using a file pointer to access or modify files. Processing files in C is a four-step process: o Declare a file pointer. o Open the desired file using the pointer. o Read from or write to the file and finally, o Close the file. FILE is a structure defined in <stdio.h>. Files can be opened using the fopen() function. This function takes two arguments, the filename and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT