Search
Home
Saved
0
0 views
Sign In
Upload
Join
RELATED TITLES
0
Explanation_Assignment_Week 4_C++
Uploaded by Khushboo Kundnani
Books
Audiobooks
Magazines
News
Documents
Sheet Music
nptel assignment anwers c++ C++
Save
Embed
Share
Print
1
Download
of 9
a2
Les 07
Search document
Programming in C++: Explanation Assignment Week Total Marks : 20 Right hand side of each question shows its Type (MCQ/MSQ/SA/Programming)
Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology Kharagpur-721302
[email protected] September 9, 2016
Question 1 Identify the incorrect statement(s) about static data members of a class. [MSQ] class. [MSQ] a. It needs to be defined to avoid linker linker error b. Static data member member must be initialized initialized in a source source file c. It is associated with object not with class d. It can be accessed as a member of any object of the class Answer: c) Explanation: It is associat associated ed with the class not with the object. There There exist exist a single single copy copy of a member of a given class which is shared by all the objects of that class. Read Free Foron 30this Days Sign up to vote title
Master your semester with Scribd & The New York Times Question 2 Special offer for students: Only $4.99/month.
Not useful Cancel anytime.
Useful
Home
Saved
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
0 views
Sign In
Upload
Join
RELATED TITLES
0
Explanation_Assignment_Week 4_C++
Uploaded by Khushboo Kundnani
Books
Audiobooks
Magazines
News
Documents
Sheet Music
nptel assignment anwers c++ C++
Save
Embed
Share
Print
1
Download
of 9
a2
Les 07
Search document
Question 3
By using which type of function, a private static data member can be initialized even before any object has been created? [MCQ] a. non-static member function b. static member function c. constructor function d. global function Answer: b) Explanation: It is by definition
Question 4 Which of the following are true about a static member function? [MSQ] a. It can access global functions and data b. It has this pointer c. It cannot be declared as const orReading volatile a Preview You're d. There may be a non-static function in the class with the same name Unlock full access withsame a free trial.
Answer: a), c) FreeisTrial Explanation: Const-ness ofDownload a memberWith function about the const-ness of the object type of this pointer (which now becomes const * const this). Static member func not concerned with the objects – they just deal with the class as a whole. Hence, co has to semantics for static member functions.
Master your semester with Scribd & The New York Times Question 5 Special offer for students: Only $4.99/month.
Read Free Foron 30this Days Sign up to vote title
Not useful Cancel anytime.
Useful
Home
Saved
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
0 views
Sign In
Upload
Join
RELATED TITLES
0
Explanation_Assignment_Week 4_C++
Uploaded by Khushboo Kundnani
Books
Audiobooks
Magazines
News
Documents
Sheet Music
nptel assignment anwers c++ C++
Save
Embed
Share
Print
1
Download
of 9
A::a = x;
// stmt-1
A::a = 10
// stmt-2
a2
Les 07
Search document
A::init(10); // stmt-3 // ....... }
Identify the correct statement(s) inside the main() that may be used to set 10 to A::a a. stmt-1 b. stmt-1 or stmt-2 c. stmt-3 d. stmt-2 Answer: c Explanation: The static member a is private – cannot be accessed from outside.
Question 6 You're Reading a Preview A friend function violates which feature(s) of OOPs? [MSQ] a. Data hiding b. Data abstraction
Unlock full access with a free trial.
Download With Free Trial
c. Polymorphism
Master yourAnswer: semester with Scribd a), d) Explanation: & The New York Times d. Data encapsulation
Read Free Foron 30this Days Sign up to vote title
Not useful Cancel anytime.
Useful
friend is not a member of a class, it is an outsider. By using it we can access priv Special offer for students: Only $4.99/month. member of a class.
Home
Saved
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
0 views
Sign In
Upload
Join
RELATED TITLES
0
Explanation_Assignment_Week 4_C++
Uploaded by Khushboo Kundnani
Books
Audiobooks
Magazines
News
Documents
Sheet Music
nptel assignment anwers c++ C++
Save
Embed
Share
Print
1
Download
of 9
a2
Les 07
Search document
Question 8
Why is it necessary to overload some operators in a class by a global function (rat a member function)? [MCQ] a. Because member functions are slower than global functions b. Because built-in types cannot have member functions c. Because the left hand operand may not be an object of the class d. Because the right hand operand may not be an ob ject of the class
Answer: c Explanation: For example, consider the class Complex. Construct a complex number c1 as Complex If we try to perform 23 + c1 we cannot do it through member function because it r call like: 23.operator+ (Complex &c1). This operator+ must be in int type. And operator can exist in int because it is built-in type.
Question 9
class Node { You're Reading a Preview private: Unlock full access with a free trial. int key; Node *next; /* Other members of Download Node ClassWith */ Free Trial _________ int LinkedList::search();
Master your};semester with Scribd Read Free Foron 30this Days Sign up to vote title data Fill the blanks so that search() method of LinkedList class can access private & The New York Times Useful Not useful class. Special offer for students: Only $4.99/month.
a) static
Cancel anytime.
Home
Saved
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
0 views
Sign In
Upload
Join
RELATED TITLES
0
Explanation_Assignment_Week 4_C++
Uploaded by Khushboo Kundnani
Books
Audiobooks
Magazines
News
Documents
Sheet Music
nptel assignment anwers c++ C++
Save
Embed
Share
Print
1
Download
of 9
a2
Les 07
Search document
Question 10 Fill in the gaps below to complete the program: class IDGenerator { private: static int s_nextID; public: __________ int getNextID(); // Fill in the keyword }; ___________________
// Fill in the statement
int IDGenerator::getNextID() { return s_nextID++; } int main() { int add = 0, count = 0; cin >> count; for (int i = 0; i < count; ++i){ add = add + IDGenerator::getNextID(); } cout << add; return 0; You're Reading a Preview } Unlock full access with a free trial. The inputs and the desired output are given below.
Public set 1 •
Download With Free Trial
Input: 5
Output: 15 Master your semester with Scribd Public set 2 & The New York Times •
104 • Input: Special offer for students: Only $4.99/month.
Read Free Foron 30this Days Sign up to vote title
Not useful Cancel anytime.
Useful
Home
Saved
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
0 views
Upload
Sign In
Join
RELATED TITLES
0
Explanation_Assignment_Week 4_C++
Uploaded by Khushboo Kundnani
Books
Audiobooks
Magazines
News
Documents
Sheet Music
nptel assignment anwers c++ C++
Save
Embed
Share
Print
1
Download
of 9
a2
Les 07
Search document
Question 11 Fill in the gaps below to complete the program: #include
using namespace std; class Box { private: double length, breadth, height; public: Box(double a = 0, double b = 0, double c = 0) : length(a), breadth(b), height(c) {}; double getDimension(){ return length + breadth + height; } Box ___________(const Box& x){ // Fill the name of the function Box box; ___________________ // Fill the statement You're a Preview ___________________ //Reading Fill the statement ___________________ // Fill the statement Unlock full access with a free trial. return box; } };
Download With Free Trial
int main(){ double l = 0, b = 0, h = 0; cin >> l; cin >> b; cin >> h; Read Free Foron 30this Days Sign up to vote title Box Box1(5.00, 6.00, 7.00), Box2(l, b, h), Box3; Useful Not useful Cancel anytime. Box3 = Box1 + Box2; Special offer for students: Only $4.99/month. double dim = Box3.getDimension();
Master your semester with Scribd & The New York Times
Home
Saved
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
0 views
Upload
Sign In
Join
RELATED TITLES
0
Explanation_Assignment_Week 4_C++
Uploaded by Khushboo Kundnani
Books
Audiobooks
Magazines
News
Documents
Sheet Music
nptel assignment anwers c++ C++
Save
Embed
Share
Print
1
Download
of 9
a2
Les 07
Search document
Answer: operator+ box.length = this->length + x.length; box.breadth = this->breadth + x.breadth; box.height = this->height + x.height;
Explanation: It is an example of operator+ overloading for a user-defined data typ
Question 12 Fill in the gaps below to complete the program: #include using namespace std; class Date { int da; int mo; int yr; public: Date(int
// 2 digit day // 2 digit month // 4 digit year d, int m, int y):Reading da(d), amo(m), You're Previewyr(y) { }
Unlock full access with a free trial. friend ________ operator<<(ostream& os, const Date& dt); // Fill the
};
Download With Free Trial
________ operator<<(ostream& os, const Date& dt) // Fill the return typ { _______________________ // Fill the implementation Read Free Foron 30this Days Sign up to vote title return os; Not useful Useful Cancel anytime. } Special offer for students: Only $4.99/month.
Master your semester with Scribd & The New York Times int main()
Home
Saved
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
0 views
Upload
Sign In
Join
RELATED TITLES
0
Explanation_Assignment_Week 4_C++
Uploaded by Khushboo Kundnani
Books
Audiobooks
Magazines
News
Documents
Sheet Music
nptel assignment anwers c++ C++
Save
Embed
Share
Print
1
Download
of 9
a2
Les 07
Search document
Public set Input: 10, 25, 2015 Output: 10/25/2015
Private set Input: 12, 10, 1998 Output: 12/10/1098
Answer: ostream& ostream& os << dt.mo << ’/’ << dt.da << ’/’ << dt.yr;
Explanation: It is overloading of output stream. It must return an reference of ostream type. Only shall be able to stream the outputs like: int a, b, c; cout << a << b << c; Putting parentheses, we get: You're Reading a Preview (((cout << a)) << b) << c); The value of every parenthesized expression is trial. cout (of course, with the respecti Unlock full access with a free streamed already) so that the next variable can be streamed to it.
Download With Free Trial
Question 13
Master your semester with Scribd Fill in the gaps below to complete the program: Read Free Foron 30this Days Sign up to vote title & The New York Times Useful Not useful #include Special offer for students: Only $4.99/month. using namespace std;
Cancel anytime.
Home
Saved
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
0 views
Sign In
Upload
Join
RELATED TITLES
0
Explanation_Assignment_Week 4_C++
Uploaded by Khushboo Kundnani
Books
Audiobooks
Magazines
News
Documents
Sheet Music
nptel assignment anwers c++ C++
Save
Embed
Share
Print
1
Download
of 9
a2
Les 07
Search document
cin >> x; cin >> y; cout << x << ’\n’; cout << y << ’\n’; cout << first::y << ’\n’; cout << second::x << ’\n’; return 0; }
The inputs and the desired output are given below. Public set •
Input: 5 2.7183
•
Output: 5 2.7183 10 3.1416
Private set •
Input: 66 4.21
•
Output: 66 4.21 10 3.1416
Answer: using first // using second You're Reading a Preview Explanation: The statement using first::x,Unlock qualify the ’x’ which to namespace ’first’ in the full access with a free belong trial. the main(). Similar the statement using second::y makes y available in main. So c refers the first::x and cin >> y refers second::y; Download With Free Trial
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Read Free Foron 30this Days Sign up to vote title
Not useful Cancel anytime.
Useful
Home
Saved
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join