0% found this document useful (0 votes)
14 views3 pages

3

Awesome notes

Uploaded by

Yash Vivek Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

3

Awesome notes

Uploaded by

Yash Vivek Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 3
Hore are the solutions to the given C++ programming questions: 14. (a) Short Notes: + Object: An instance of a class. It represents a real-world entity with its own state (attributes) and behavior (methods). # Class: A blueprint or template for creating objects. It defines the data members (attributes) and member functions (methods) that objects of that class will have. '* Data Encapsulation: The practice of bundling data (attributes) and methods (functions) that operate on that data within a single unit (class). This-helps in protecting data integrity and controling access. ‘= Inheritance: The mechanism by which one class (child class or derived lass) inherits the properties and behaviors of another class (parent class of base class). This promotes cade reusability and creates hierarchical relationships between classes. '* Polymorphism: The ability of objects of different types to be treated as if they were of the ‘same type. It allows different objects to respond to the same message in different ways, based on their specific implementations. 41. (@) Storage Glasses: auto: Variable's storage class is determined by its declaration cantext. I's generally used for lacal variables. '* register: Suggests to the compiler to store the variable ina register for faster access. However, the compiler might not always honor this request. ‘© static: Variables deciared as static retain their values between function calls and have a Jonge’ lifetime than automatic variables. Thay can be used for global variables or within functions. = extern: Declares a variable that is defined elsewhere, typically in another file. I's used for sharing variables between different files. 2. (a) Dereferencing Operator: ‘The dereferencing operator * is used to access the value stored at a memory location pointed to by a pointer. I's essential for working with pointers and dynamically allocated memory. Here's an example: #include int main() { int 2 = 10; int "per = Gx; // ptr points to the address of x std::cout for loop: Repeats a block of cade a specified number of times. ‘© while loop: Repeats a biock of code as long as a condition is true. © do-while loop: Repeats a block of code at least once, and then continues as long as ‘a eondition is true. 3. (a) Unary Operator Overloading: #include class Complextumber { public: he } int real, imag; ComplexMumber (int r= 0, int i = 0) : real(r), imag(i) {} Jf Overload the unary - operator Complexvumber operator () { return ComplexNumber(-real, -imag) ; ) void display() { std::cout include class student { public: std::string name; int rollMumbers float gpa; Jf Default constructor Student () { mane = "Usknown"; rollNumber = gpa = 0.0; } J? Paraneterized constructor student (std: satring n, int r, float g) { vollNumber = ¥; gpa = 9; } J) copy constructor Student (conat student <3) vollMunber = 8.xollNunber; gpa = 5.9pa; } Jf vestructor “student () [ reoUL <2 "Student object destroyed: * << name << JJ... other member functions -.. Ve int maia() { Sh wee } ‘Note: This is just a basic implementation. You can add more member functions like display. set, get, etc. to the Student class as needed. Please let me know if you have any other questions or require further assistance.

You might also like