Você está na página 1de 15

Amity Campus

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)

Total weightage given to these assignments is 30%. OR 30 Marks


All assignments are to be completed as typed in word/pdf.
All questions are required to be attempted.
All the three assignments are to be completed by due dates and need to be
submitted for evaluation by Amity University.
f) The students have to attached a scan signature in the form.

Signature :
Date
:

_________________________________
_________________________________

( ) Tick mark in front of the assignments submitted


Assignment
Assignment B
Assignment C
A

Object Oriented Programming s


Assignment A
Q1) Differentiate between basic data types, derived data types and user defined
data types?
Basic data types are predefined set of data in the c++, they are also called primitive data
types.
eg. are int(integer) , char(character), float, double, void , bool and wchar_t.

Derived data types are array, pointers etc.


User Defined data types are those which are defined by the user using basic data types
in them....
eg. are Classes, structures, union
Q2) Explain mechanism in Object Oriented Programming System?
Q3) Explain about passing parameters to as function in Call by Value and Call by
Reference and then distinguish between them?
Call by value essentially passes a copy of an object's value whereas call by
reference essentially passes the object itself. Pass by reference is the preferred
method whenever possible as call by value will automatically invoke the object's
copy constructor, which is often unnecessary, especially if the object is not
affected by the function call (pass by constant reference).
Q4) What is Template? Explain the concept of Template in C++?

A template is a form, mold, or pattern used as a guide to


making something. Here are some examples
Q5) Write Short notes on:a) Friend Function
b) Operator Overloading
c) Inheritance
d) Abstraction
e) Pointer
f) Constructor & Destructor

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
:

// reading a text file#include <iostream> #include


<fstream> #include <string> using
namespace
std;
int
main () { string line; ifstream myfile ("example.txt");
if
(myfile.is#open()) {
while
( getline (myfileline) ) { cout << line <<
&\n&; } myfile.close(); }
else
cout << "%nale to open file";
return
0;}
I(streams can be used or a wide variety o data manipulations
than)s to the following eatures:
# &stream& is internally nothing but a series of characters. The
characters maybe either normal characters *char, or wide
characters *wchar1t,. Streams provide you with a universal
character based interace to any type of storage medium *or
e'ample" a fle," without re2uiring you to )now the details of how
to write to the storage medium. #ny ob!ect that can be written to
one type of stream" can be written to all types of streams. In
other words" as long as an ob!ect has a stream representation"
any storage medium can accept ob!ects with that stream
representation.

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.

The stream library&s unifed approach ma)es it very riendly to


use. 5sing a consistent interface or outputting to the screen and
sending fles over a networ) ma)es lie easier. The programs below
will show you what is possible.

The IO stream class hierarchy is quite complicated, so rather than introduce


you to the fullhierarchy at this point, Ill start with explaining the
concepts of the design and show youexamples of streams in action. Once
you are familiar with elements of the design and how toapply those
concepts to design a robust I!O system for your software, an understanding
of what belongs where in the hierarchy will come naturally
Q2) Write a C++ program to create a data file with following attributes. S.No,
name, age. Accept n persons information and display the same.
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile ("Data_file2.txt");
if (myfile.is_open())
{
myfile << "S.No:.\t\t";
myfile << "Name:.\t\t";
myfile << "Age:\t\t";
myfile.close();
}
else cout << "Unable to open file";
cout<< "Enter the SNo:"
cin<<
ifstream OpenFile("Data_file2.txt");
char ch;
while(!OpenFile.eof())
{
OpenFile.get(ch);
cout << ch;
}
OpenFile.close();
system("PAUSE");
return 0;
}
Q3) Write short note on Encapsulation and Data Binding with an Example?
Q4) Write a C++ program to find factorial of a given number using functions.
Q5) What are access specifier? Explain their purpose and different type of
access specifier?

Q6) Write a C++ program to transpose a matrix using class concept.

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

Q7) The array exforsys[10] can be declared using pointers as


a) % exforsys[]
b) & exforsys[]
c) * exforsys[]
d) @ exforsys[]
Q8) The variables that can be used only within the function in which it is declared is
called as
a) Global Variables
b) Local Variables
c) Both A and B
d) None of the Above
Q9) The class that in C++ for file input is
a) Ifstream
b) Ofstream
c) Both A and B
d) The class that in C++ for file input is
Q10) Which of the following is an error statement in C++ array declaration?
a) int exforsys(10);
b) float exforsys[5][5];
c) int exforsys[5];
d) None of the Above
Q11) The members of a class are by default
a) Private
b) Public
c) Protected
d) None of the Above
Q12) The header that should be included while using manipulators in C++ is
iomanip.h
a) manip.h
b) ifstream.h
c) None of the Above
Q13) The header file that must be included while using cout function in a C++
program is
a) conio.h
b) math.h

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

Q27)The friend function of a class in C++ can access


a) Private members of the class
b) protected members of the class
c) Both A and B
d) None of the Above
Q28) A function defined within a class is called as
a) Member Function
b) Class Function
c) Object Function
d) None of the Above
Q29) The private member in derived class
a) Cannot be inherited
b) Can be inherited at all instances
c) Can be inherited only if the derived class is inheriting from base class with private
access level
d) None of the Above
Q30) Which of the following denote types of polymorphism in C++?
a) Virtual function
b) Function overloading
c) Operator Overloading
d) All the Above
Q31) An instance of a user-defined type is called
a) Class
b) Object
c) Method
d) None of the Above
Q32) Which of the following can be used to initialize a newly declared variable from
an existing variable?
a) Virtual Function
b) Namespaces
c) copy constructor
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

Q40) Which of the following remains static in a C++ program?


a) Class
b) Object
c) Both A and B
d) None of the Above

Você também pode gostar