Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hand in HW # 1 1 40 PTS (5 EACH) ANSWER CAREFULLY Read and Study section 5-1 and

ID: 3605152 • Letter: H

Question

Hand in HW # 1 1 40 PTS (5 EACH) ANSWER CAREFULLY Read and Study section 5-1 and carefully pick the correct answer to the following quesitions. Use QUESTION NUMBER AND letter answers in the HW 1. The class name used to declare a user defined input file is A. inFile B. ifstream C. iostream D. istream 2, which include statement must you use to define and use files A. #include B.#include C. #include D#include 3. Which of the following statements correctly declares the input file object Mylnput and initializes the file object to read the file exam.txt? A. ifstream Mylnput("exam.txt"); B Mylnput ifstream("exam.txt"); C ifstream Mylnput(exam.txt); D.Mylnput ifstream (exam.txt); 4. What is the next step in using a file, after the file has been declared with the following statement? ofstream AnsFile; A. You use the file to input a variable. B. You use the file by outputting a value to it. C.You search for a file named AnsFile. D. You open the file, and associate it with a specific file name 5. Which of the following statements correctly opens the output file object AnsFile to store answers into file myanswers.txt? A. AnsFile.open("myanswers.txt"); B. open.AnsFile("myanswers.txt"); C. open.AnsFile(myanswers.txt); D. AnsFile.open(myanswers.txt); 6. Which of the following statements will properly store the number from variable value into the output file object AnsFile? A. AnsFile

Explanation / Answer

1. B) ifstream
Explanation :

ifstream is stream class to read from files


2. D) #include <fstream>
Explanation :

<fstream> is Header that provides file stream classes


3. A)ifstream MyInput("exam.txt")
Explanation :

ifstream is stream class to read from files , it is declared as -> ifstream VariableName(FileName)


4. D) You open the file, and associate it with a specific file name
Explanation :

ofstream is a Output stream class to operate on files.
How to use :
ofstream myfile; -> declare
myfile.open ("filename"); -> open file by associating


5. A) AnsFile.open("myanswers.txt")
Explanation :

As explained above file is opened in this manner : ofstreamVariable.open(fileName)


6. A) AnsFile << value
Explanation :

cout<<value -> stores the value on screen as we see it
Similarly
AnsFile << value will store the value in file as instead of cout ,ofstream is the stream used.


7. A) MyInput >> value
Explanation :

cin>>value -> reads the value from user input
Similarly
MyInput >> value will read the value from file as instead of cin ,ifstream is the stream used.


8. C) AnsFile.close()
Explanation :

We call the stream's member function close to close the stream.

**If you have any query , please feel free to comment with details.
**Happy learning :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote