Quiz4 and Solutions - Computer Techniques for Electronic...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Computer Techniques for Electronic Design II (ESE 224) Quiz for chapter 4 Period: 10 minutes Multiple Choice Problems 1. Which of following statements is true? a) A class is a mechanisms that allows a programmer to define new data types; b) A class is an instance of An Object. c) A class could be used to add functionality to an existing data type. d) Inheritance is an important feature for both C Language and C++ Language. e) A derived class could not call any member function of the parent class. 2. Which of following statements is correct? a) cin, cout and cerr are C++ keywords. b) A programmer must define cin and cout before using them. c) cin, cout and cerr are classes. d) cin, cout and cerr and objects. e) cerr is a unbuffered stream. 3. When an input stream fail to open a file, which is the following will happen? a) The badbit state flag would be set to true; b) The failbit state flag would be set to true; c) The eofbit state flag would be set to true; d) The program would terminate; e) The program would continue to execute but input operations applied to the stream will result in a null operation. Programming Problem 4. Several integers are stored in File a.txt. An empty File b.txt exists. Please finish following codes to copy all integers in file a.txt into file b.txt. #include <fstream> #include <iostream> using namespace std; int main() { ifstream inputdata; ofstream outputdata; } //You can write codes in backside if space is not enough Solutions 1. A, C 2. D,E 3. B,E 4. Program #include <fstream> #include <iostream> using namespace std; int main() { int x; ifstream inputdata; ofstream outputdata; inputdata.open(“a.txt”) outputdata.open(“b.txt”); if(inputdata.fail() || outputdata.fail()) { cout<<”An error occurred when opening file.”<<endl; return ‐1; } while(!inputdata.eof()) { inputdata>>x; outputdata<<x<<’ ‘; } inputdata.close(); outputdata.close(); return 0; } ...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern