Quiz4 and Solutions

Quiz4 and Solutions - Computer Techniques for Electronic...

Info iconThis 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

This note was uploaded on 10/23/2011 for the course ECE 224 taught by Professor Wangxin during the Spring '09 term at SUNY Stony Brook.

Ask a homework question - tutors are online