0% found this document useful (0 votes)
158 views

Oops Assignment (TCS 307)

This document provides 30 questions as an assignment on object-oriented programming concepts in C++. The questions cover topics like operator overloading, constructors and destructors, static class members, friend functions, pointers, references, memory allocation, and copy constructors. Students are instructed to submit handwritten responses to the questions by November 8th, 2021.

Uploaded by

Devansh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
158 views

Oops Assignment (TCS 307)

This document provides 30 questions as an assignment on object-oriented programming concepts in C++. The questions cover topics like operator overloading, constructors and destructors, static class members, friend functions, pointers, references, memory allocation, and copy constructors. Students are instructed to submit handwritten responses to the questions by November 8th, 2021.

Uploaded by

Devansh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

ASSIGNMENT Based on UNIT-I AND UNIT-II

OOPs with C++ [TCS-307]

Assignment Instructions:
● You have to submit a hand written assignment only.
● Write your Name, University Roll no., Student Id, Course and Section, Subject with code
above the assignment.
● Preferred A4 sheets for writing the assignment (can use both sides)
● Submission Date is 08 NOVEMBER 2021.
● No assignment will be collected after the date.
● You have to submit your assignment to class CR.

Assignment Questions:
1. Write a C++ program to explain the concept of overloading new and delete operators for
increasing efficiency of memory management.
2. Write a C++ program for overloading subscript ([]) operator by using operator overloading.
3. A friend function can not be used to overload the assignment operator. Explain why?
4. What are the limitations of overloading unary increment/decrement operators? How are
they overcome?
5. Why is it necessary to overload an operator? List the operators which can not be overloaded
through member functions and friend functions. Also write the rules for overloading
operators.
6. What is this pointer? What is your reaction to the statement
delete this;
Write a C++ program for demonstrating the use of ‘this’ pointer.
7. What are manipulators in C++? List them and explain with examples.
8. Write a C++ program to create a class string having the parameterised constructor which
takes a parameter that tells a number of characters in a string. (allocate its memory
dynamically inside the constructor)
Member function:
enterstring(), this function takes the string from the user
show(), displays the string
concat(), this function joins the two strings and takes two objects as parameters.
9. What are Constructors and Destructors? Explain types of constructors with examples.
10. When do we declare a member of a class static? How can we access static data members?
11. What is a class? How does it accomplish data hiding?
What are the objects? How are they created?
Create a class named number and find the largest and smallest number between three
numbers, input by user.
Class name- number
Data members- a,b,c
Member Functions- Input (), largest (), smallest ()
12. What is the scope resolution operator and what is its role? Explain with a proper example.
13. In what ways does a CLASS differ from a STRUCTURE and in what way are they similar.
14. (a) Why can't we initialize data members within a class or a structure?
(b) What is the size of an object of a Class.
15. What is a friend function? What are the merits and demerits of using a friend function.
16. Describe the mechanism of accessing data members and member functions in the following
cases:
(a) Inside the main program.
(b) Inside a member function of the same class.
(c) Inside a member function of another class.

17. Write a C++ program to change every letter in a given string with the letter following it in
the alphabet (ie. a becomes b, p becomes q, z becomes a)
Example:
Sample Input: Graphic Era
Sample Output: Hsbqijd Fsb
18. Write a program in C++ to calculate the series (1) + (1+2) + (1+2+3) + (1+2+3+4) + ... +
(1+2+3+4+...+n).
Sample Output:
Input the value for nth term: 5
1=1
1+2 = 3
1+2+3 = 6
1+2+3+4 = 10
1+2+3+4+5 = 15
The sum of the above series is: 35
19. Write a program in C++ to display the multiplication table vertically from 1 to n.
Sample Output:
Input the number upto: 5
Multiplication table from 1 to 5
1x1=1 2x1=2 3x1=3 4x1=4 5x1=5
1x2=2 2x2=4 3x2=6 4x2=8 5x2=10
1x3=3 2x3=6 3x3=9 4x3=12 5x3=15
1x4=4 2x4=8 3x4=12 4x4=16 5x4=20
1x5=5 2x5=10 3x5=15 4x5=20 5x5=25
1x6=6 2x6=12 3x6=18 4x6=24 5x6=30
1x7=7 2x7=14 3x7=21 4x7=28 5x7=35
1x8=8 2x8=16 3x8=24 4x8=32 5x8=40
1x9=9 2x9=18 3x9=27 4x9=36 5x9=45
1x10=10 2x10=20 3x10=30 4x10=40 5x10=50

20. The daily maximum temperatures recorded in 5 cities during the month of January (for all
31days) have been tabulated as follows:

Cities:

Day Delhi Mumbai Kolkatta Chennai Dehradun

1 :

…..

31

Write a program to read the table elements into a two-dimensional array temperature, and
to find the city and day corresponding to (a) the highest temperature and (b) the lowest
temperature.

21. Explain inline function and function with default argument with example.
22. Explain the difference between a pointer and a reference.
23. How is call by value different from call by reference?
24. Explain the difference between call by reference and call by address with the help of a
sample code.
25. What will be the output of following code:

#include <iostream>
using namespace std;

void inc(int &a, int b){


a++;
b++;
cout << "Value of a in Function inc: "<< a <<endl;
cout << "Value of b in Function inc: "<< b <<endl;
}

int main()
{
int a = 1;
int b = 2;
inc(a, b);
cout << "Value of a in Function main: "<< a <<endl;
cout << "Value of b in Function main: "<< b <<endl;
return 0;
}
26. Write a C++ program for overloading > and < operator for two strings by using operator
overloading. Simply compare two strings by their length only. Handle 0, 1 and -1 as return
values for your overloading.
27. What is reference in C++? Write the differences between reference and address of a
variable.
28. What will be the output of a given program?

#include <iostream>
using namespace std;

int main()
{
int x=10;
int &ref=x;
cout << x << endl;
cout << ref;
return 0;
}
Explain your answer in the context of the Reference variable.

29. List out the differences between static and dynamic memory allocation in C++. How stack
and Heap would store data and references in case of pointers.
30. What is a copy constructor in C++, list out the needs of creating a copy constructor by
writing a copy constructor for a University Class in C++.

You might also like