Escolar Documentos
Profissional Documentos
Cultura Documentos
Uttar Pradesh
India 201303
ASSIGNMENTS
PROGRAM: PGD IT
SEMESTER-II
Subject Name
Study COUNTRY
Roll Number (Reg.No.)
Student Name
:
:
:
:
INSTRUCTIONS
a) Students are required to submit all three assignment sets.
ASSIGNMENT
Assignment A
Assignment B
Assignment C
DETAILS
Five Subjective Questions
Three Subjective Questions + Case Study
Objective or one line Questions
MARKS
10
10
10
b)
c)
d)
e)
Signature :
Date
:
_________________________________
_________________________________
Assignment B
Q1) Explain I-O Stream file?
Input/output with fles
C++ provides the following classes to perform output and input of characters
to/from fles:
ofstream
:
Stream class to write on fles
ifstream
:
Stream class to read from fles
fstream
:
Stream class to both read and write from/to fles. These classes are derived
directly or indirectly from the classes
istream
and
ostream
. we have already used ob!ects whose types were these classes:
cin
is an ob!ect of class
istream
and
cout
is an ob!ect of class
ostream
. There ore" we have already been using classes that are related to our fle
streams. #nd in act" we can use our fle streams the same way we are already
used to use
cin
and
cout
" with theonly di$erence that we have to associate these streams with physical
fles. %et&s seean e'ample:
// basic file operations#include <iostream> #include <fstream> using
namespace
std;
int
main () { ofstream myfile; myfile.open ("example.txt"); myfile << "Writing this
to a file.\n"; myfile.close();
return
0;}
(pen a fle
The frst operation generally performed on an ob!ect of one of these classes is
toassociate it to a real fle. This procedure is )nown as to
open a fle
. #n open fle isrepresented within a program by a
stream
*i.e." an ob!ect of one these classes inthe previous e'ample" this was
myfile
, and any input or output operation performedon this stream ob!ect will be
applied to the physical fle associated to it.In order to open a fle with a stream
ob!ect we use its member unction
open
:
open(filename mode);
here
filename
is a string representing the name of the fle to be opened" and
mode
is an optional parameter with a combination of the following -ags:
ios!!in
Open for input operations.
ios!!out
Open for output operations.
ios!! inary
Open in binary mode.
ios!!ate
Set the initial position at the end of the file.If this flag is not set,
the initial position is the beginning of the file.
ios!!app
All output operations are performed at the end of the file,
appending the content tothe current content of the file.
ios!!trunc
If the file is opened for output operations and it already existed,
its previous content is deleted and replaced by the new one.
Closing a fle
then we are fnished with our input and output operations on a fle
we shall close it so that the operating system is notifed and its
resources become available again. or that" we call the stream&s
member function
close
. This member function ta)es -ushes the associated bu$ers and
closes the fle:
myfile.close();
(nce this member function is called" the stream ob!ect can be
reused to openanother fle" and the fle is available again to be
opened by other processes.In case that an ob!ect is destroyed
while still associated with an open fle" thedestructor
automatically calls the member unction
close
.
Te't fles
Te't fle streams are those where the
ios!!inary
-ag is not included in theiropening mode. These fles are designed
to store te't and thus all values that areinput or output from/to
them can su$er some or matting trans or mations" which donot
necessarily correspond to their literal binary value.riting
operations on te't fles are perormed in the same way we operated
with
cout
:
// writing on a text file#include <iostream> #include
<fstream> using
namespace
std;
int
main () { ofstream myfile ("example.txt");
if
(myfile.is#open()) { myfile << "$his is a line.\n"; myfile << "$his
is another line.\n"; myfile.close();
}
else
cout << "%nale to open file";
return
0;}
0eading rom a fle can also be perormed in the same way that we
did with
cin
:
Streams wor) with built in data types" and you can ma)e user
defned types wor) with streams by overloading the insertion
operator *33, to put ob!ects into streams" and the e'traction
operator *44, to read ob!ects from streams.
Assignment C
Q1) In Late binding the function calls gets resolved during
a) Compile Time
b) Run Time
c) Both A and B
d) None of the Above
Q2) The value of EOF is
a) 1
b) 0
c) Infinity
d) -1
Q3) Using pointers to call a function is called as
a) call by value
b) call by reference
c) call by address
d) All the Above
Q4) The variable that contains address of another variable is called as
a) Pointer
b) Arrays
c) Unions
d) None of the Above
Q5) Inheritance in C++ have default access specifier as
a) Private
b) Public
c) Protected
d) None of the Above
Q6) How many values can be returned by a C++ function?
a) 1
b) Infinity
c) 0
d) None of the Above
c) iostream.h
d) None of the Above
Q14) The other name for external variables in C++ is
a) static variables
b) register variables
c) global variables
d) None of the Above
Q15) A function in a C++ program can be called
a) Only Once
b) Cannot be called at all
c) Any number of times
d) None of the Above
Q16) Which of the following denotes feature of OOPS?
a) Inheritance
b) Encapsulation
c) Polymorphism
d) All the Above
Q17) What is used to convert C++ source code into object modules?
a) Compiler
b) Linker
c) Both A and B
d) None of the Above
Q18) Which of the looping structure in C++ check condition at the beginning of
loop?
a) do-while
b) while
c) Both A and B
d) None of the Above
Q19) A condition that must be true on exit from a member function if called as
a) Precondition
b) Post-condition
c) Both A and B
d) None of the Above
Q20) The method that is used for writing characters in C++ program is
a) put
b) get
c) write
d) None of the Above
Q21) Which of the following denote incorrect data type in C++?
a) real
b) double
c) float
d) int
Q22) The isolation of data from direct access by a C+ program is called as
a) Data Hiding
b) Data Isolation
c) Data Encapsulation
d) None of the Above
Q23) Reference to its own class can be accepted by
a) simple constructor
b) copy constructor
c) Both A and B
d) None of the Above
Q24) What is the value of variable z when the following program segment ends? int
z; for(z=0; z<50; z++) {}
a) 51
b) 49
c) 0
d) 50
Q25) The actual implementation is present in
a) declaration
b) definition
c) Both A and B
d) None of the Above
Q26) Which of the following OOPS concepts are used with cin and cout?
a) Encapsulation
b) Data Hiding
c) Operator Overloading
d) None of the Above
Q33) The member functions of a class can be defined outside the class using
a) Extraction Operator
b) Insertion Operator
c) Scope resolution operator
d) None of the Above
Q34) The output of operation 20%3 is
a) 6
b) 2
c) 1
d) 4
Q35) A template can be instantiated by
a) Explicit Instantiation
b) Implicit instantiation
c) Both A and B
d) None of the Above
Q36) A function named as exforsys has three implementations associated with it.
This means the function exforsys is
a) Overloaded
b) Overriding
c) Both A and B
d) None of the Above
Q37) Which of the following denote bitwise operators of C++?
a) ^
b) <<
c) ~
d) All the Above
Q38) Virtual functions are defined in
a) Derived class
b) Base class
c) Both A and B
d) None of the Above
Q39) The data members and member functions that are only available to derived
classes are
a) private
b) public
c) protected
d) None of the Above