0% found this document useful (0 votes)
28 views5 pages

23cs24c - Oops - Co3 QB - Rne

This document is a question bank for a course on Object Oriented Programming in C++, focusing on exception handling, file operations, and real-world application development. It includes various questions and programming tasks related to exception handling mechanisms, file input/output operations, and specific C++ functionalities. The document is structured into two parts: Part A consists of short answer questions, while Part B contains programming assignments.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views5 pages

23cs24c - Oops - Co3 QB - Rne

This document is a question bank for a course on Object Oriented Programming in C++, focusing on exception handling, file operations, and real-world application development. It includes various questions and programming tasks related to exception handling mechanisms, file input/output operations, and specific C++ functionalities. The document is structured into two parts: Part A consists of short answer questions, while Part B contains programming assignments.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

NATIONAL ENGINEERING COLLEGE, K.R.NAGAR, KOVILPATTI - 628503.

(An Autonomous Institution, Affiliated to Anna University, Chennai.)


Department of Computer Science and Engineering
23CS24C – OBJECT ORIENTED PROGRAMMING IN C++
Question Bank
CO3: develop real-world applications by using files, streams, and exceptions (CDL2)
PART –A (Two Marks)
1 #include <iostream> CDL
using namespace std; 2
void func() {
throw "An error occurred";
}
int main() {
try {
func();
}
catch (int e) {
cout << "Caught integer exception: " << e << endl;
}
return 0;
}
identify the error in the above code. How should the code be corrected to catch the thrown
exception?
2 Write the output of the following code with the explanation. CDL
#include <iostream> 2
using namespace std;

int main() {
try {
throw 10;
}
catch (int excp) {
cout << "Caught " << excp << endl;
}
catch (...) {
cout << "Default Exception\n";
}
return 0;
}
3 Identify the type of the error in the below code and highlight the line and write the definition CDL
of the error identified. 2
#include <fstream>
using namespace std;

int main() {
try {
ifstream file("nonexistent_file.txt");
if (!file) {
throw runtime_error("File could not be opened");
}
} catch (const runtime_error& e) {
cout << "Caught runtime_error: " << e.what() << endl;
} catch (...) {
cout << "Default Exception" << endl;
}
return 0;
}
4 State the purpose of a try block in C++? CDL
1
5 Enumerate the use of a catch block in C++? CDL
1
6 Distinguish throw and throws in C++? CDL
1
7 List out the purpose of the std::exception class in C++? CDL
1
8 List the components of Exception Handling and give the disadvantages of exception CDL
handling? 1
9 List the purpose of the ifstream class in C++? CDL
1
10 How do you open a file for reading using ifstream in C++? CDL
1
11 How to use seekg() and seekp() functions in file handling. CDL
1
12 Identify the type of the error in the below code and highlight the line and write the definition CDL
of the error identified. 2
#include <iostream>
#include <fstream>
using namespace std;

int main() {
ifstream file("missing.txt");
if (!file) {
cout << "Error: Could not open file" << endl;
} else {
cout << "File opened successfully" << endl;
}
return 0;
}
13 Write the process of terminating a function in C++? CDL
1
14 Write the output of the following code with the explanation. CDL
#include <iostream> 2
using namespace std;

int main() {
try {
throw 5.5;
} catch (int e) {
cout << "Caught int: " << e << endl;
} catch (double e) {
cout << "Caught double: " << e << endl;
} catch (...) {
cout << "Default Exception" << endl;
}
return 0;
}
15 Write the output of the following code with the explanation. CDL
#include <iostream> 2
#include <iomanip>
using namespace std;

int main() {
cout << oct << 64 << endl;
cout << setfill('*') << setw(8) << 123.45 << endl;
return 0;
}
16 How do you read a single character from the input stream in C++? CDL
1
17 How do you check if a file has been successfully opened in C++? CDL
1
18 Outline the role of <fstream> header in file operations? CDL
1
19 Differentiate between streambuf and fstreambase in files? CDL
1
20 Compare and contrast the usage of binary and text file streams in C++. CDL
1
PART - B
1 a) Illustrate exception handling? Explain types of exception handling and explain suitable CDL
examples. (8M) 1
b) Elaborate the Try, Catch, and Throw mechanisms? Explain with an example. (8M)
2 a) Write a program using put() to write characters to a file until user enters a dollar sign (8 CDL
M) 1
b) Write a C++ program to create a file named "log.txt" and write the current date and time
to the file. (8M)
3 Construct a C++ program that reads a file name from the user, displays information about CDL
whether the file exists, whether the file is readable, or writable, the type of file and the 2
length of the file in bytes.(16M)
4 Write a C++ program to manage employee records using file handling. The program should CDL
allow adding new employee records to a file named "employees.txt" and displaying all 1
records. Each record should include employee ID, name, and department. (16M)
5 Develop a C++ program to handle student grade management using file handling. Your CDL
program should facilitate the addition of new student records to a binary file named 2
"students.bin" and provide functionality to read and display all records. Each student record
must consist of a student ID, name, and grade. (16M)
6 a) Narrate the difference between formatted and unformatted I/O. Discuss its different CDL
functions. (8M) 1
b) Explain the role of seekg(), seekp(), tellg(), and tellp(), functions in the process of
random access in a binary file. (8 M)
7 Develop a C++ program utilizing sequential file access to manage and access a library CDL
catalog. Implement functionalities to maintain records of books, including attributes such as 2
book ID, title, author, and genre. Allow users to add new books to the catalog, search for
books by title or author, update book details, and delete books from the catalog. Utilize
sequential file operations to store and retrieve book information efficiently.
Ensure error handling and provide user-friendly interfaces for managing the library catalog.
(16M)
8 Develop a C++ program that reads a list of student names and their corresponding scores CDL
from a file named "students.txt". Sort the student data based on their scores in descending 2
order and write the sorted data to another file named "sorted_students.txt". (16M)
9 a) Explain the role of terminate() and unexpected() functions in exception handling with C+ CDL
+ program. (8M) 1
b) Develop the programs to get input two numbers and divide the first by the second and by
using exception handling to manage a divide-by-zero error. (8M)
10 Consider a scenario where a program needs to open and manipulate multiple files CDL
simultaneously. Design the exception handling mechanism to ensure proper resource 1
management and error recovery in such a scenario. (16M)
11 Develop a C++ program to implement complex number arithmetic using file handling. CDL
(16M) 1
12 Explore the implementation of exception handling mechanisms such as throw, catch, and CDL
rethrow in C++ programs, highlighting their significance in error management. (16M) 1
13 Consider a real-time application where critical sensor data is logged to a file. Design a CDL
comprehensive exception handling strategy for this application, considering potential errors 2
like disk full, file corruption, and unexpected sensor readings. Provide code snippets to
demonstrate the given approach. (16M)
14 Develop a C++ program for a simple text editor that allows users to create, edit, and save CDL
text documents. Implement file operations using file streams and include exception handling 2
for file I/O errors and memory allocation failures. (16M)
15 Write a C++ program using sequential file access to maintain and access employee payroll CDL
systems. The program should allow users to perform tasks such as 1
a. adding new Employee
b. displaying Employee information
c. updating records
d. deleting entries. (16M)

***************************************************************************

You might also like