Skip to content
VUBuddy

CS201 Short Notes Set 2 by VUBuddy

Introduction to Programming PDF 660 KBUpdated 23 Oct 2026
Quiz CS201 Short Notes Set 2 by VUBuddy PDF 660 KB
vubuddy.com
Type
Quiz
Course
CS201 Introduction to Programming
Size
PDF 660 KB
Updated
23 Oct 2026
Free download 0 of 3 used today
Download free · 660 KB

You get 3 free files a day on the website. Add the Chrome extension for 30 a day.

Unlimited downloads in the Android app Get it free on Google Play

Preview text

Text from pages 2, 3, 4 of 10. Download the file for all 10 pages.

Lecture 34

1-Array of Code: The array of objects represent storing multiple objects in a single name. In an array of objects, the data can be accessed randomly by using the index number. Reduce the time and memory by storing the data in a single variable.

New is called before the constructor, and that delete is called after the destructor. A global array called pool that can store all the Name objects expected.

2-Copying a File in the Reverse Order: Copying a File in the Reverse Order means the last byte of the input file will be the first byte of the output file, second last byte of the input file will be the second byte of the output file until the first byte of the input file becomes the last byte of the output file

The Reverse Order function outputs printed sheets in top-to-bottom order with the printed side facing up, resulting in a set of copies stacked in the opposite order to the original.

3-By overloading new and delete operators, only allocation and de-allocation part can be overridden.

4-By overloading the array operator ([]), one can implement mechanism to check for array bound.

5-With delete operator, destructor of the object is called first and then memory block is de-allocated.

6-With new operator function, a block of memory is allocated first and then constructor is called.

7-The delete operator returns nothing (void) and accepts a pointer of void to the memory block.

8-The new operator returns a void, accepts a parameter of type size_t. 9-The default constructor (parameter less constructor) is called for each element in the array allocated with new.

10 The default constructor is defined by the C++ compiler automatically for every class that has no default constructor (parameter less constructor) defined already. 11The same pointer that is returned by the new operator, is passed as an argument to the delete operator.

These rules apply to both, if operators (new and delete) are overloaded as member or non-member operators (as global operators).

Lecture 35

  • A C++ class is a collection of data and the methods necessary to control and maintain that data.
  • A class is a data type, analogous to ints, floats, and doubles. A C++ object is a specific varia- ble having a class as its data type, cin and cout are special pre-specified objects with different classes as their data types.
  • A C++ stream is a flow of data into or out of a program, such as the data written to cout or read from cin.
  • For this class we are currently interested in four different classes:

istream is a general purpose input stream. cin is an example of an istream.

⚫ ostream is a general purpose output stream. cout and cerr are both examples of ostreams.

  • ifstream is an input file stream. It is a special kind of an istream that reads in data from a data file.

⚫ ofstream is an output file stream. It is a special kind of ostream that writes data out to a data file.

  • Object Oriented Programming (e.g. C++) makes heavy use of a concept called inher- itance, in which some classes inherit the properties of previously written classes. The de- scendant classes then add on additional properties, making them specializations of their parent class.

For example, in the diagram below of (a portion of) the stream class hierarchy, we see that ifstream is a specialization of istream. What this means is that an ifstream IS an istream, and includes all the properties of the istream class, plus some additional properties of its own.

The ifstream Class

  • An ifstream is an input file stream, i.e. a stream of data used for reading input from a file.

Because an ifstream IS an istream, anything you can do to an istream you can also do the same way to an ifstream.

  • In particular, cin is an example of an istream, so anything that you can do with cin you can also do with any ifstream.
  • The use of ifstreams (and ofstreams) requires the inclusion of the fstream header:

#include <fstream>

  • Before you can use an ifstream, however, you must create a variable of type ifstream and connect it to a particular input file.
  • This can be done in a single step, such as:

ifstream fin( "inputFile.txt");

All CS201 files →
CS201 Introduction to Programming All CS201 handouts, past papers, quizzes and MCQs in one place. Open course page

Get more out of VUBuddy, for free

Android app Free on Google Play
  • Unlimited downloads
  • The explanation behind every MCQ answer
  • Study offline on slow data
Get the Android app
Chrome extension Free on the Chrome Web Store
  • 30 downloads a day instead of 3
  • Sign in and buy Pro Semester here
Add to Chrome

One Pro Semester membership works in both the extension and the app.